AppendableRouteExtraInfoBuilder.java

  1. /*  This file is part of Openrouteservice.
  2.  *
  3.  *  Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
  4.  *  GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
  5.  *  of the License, or (at your option) any later version.

  6.  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  7.  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8.  *  See the GNU Lesser General Public License for more details.

  9.  *  You should have received a copy of the GNU Lesser General Public License along with this library;
  10.  *  if not, see <https://www.gnu.org/licenses/>.
  11.  */
  12. package org.heigit.ors.routing.util.extrainfobuilders;

  13. import com.graphhopper.util.PointList;
  14. import org.heigit.ors.routing.RouteExtraInfo;

  15. import java.util.ArrayList;
  16. import java.util.Iterator;
  17. import java.util.List;

  18. public class AppendableRouteExtraInfoBuilder extends SimpleRouteExtraInfoBuilder {
  19.     private final ArrayList<SegmentParams> segmentParamsList;

  20.     public AppendableRouteExtraInfoBuilder(RouteExtraInfo extraInfo) {
  21.         super(extraInfo);
  22.         segmentParamsList = new ArrayList<>();
  23.     }

  24.     @Override
  25.     public void addSegment(double value, long valueIndex, PointList geom, double dist) {
  26.         segmentParamsList.add(new SegmentParams(value, valueIndex, geom, dist));
  27.     }

  28.     public List<SegmentParams> getSegmentParamsList() {
  29.         return segmentParamsList;
  30.     }

  31.     public void append(AppendableRouteExtraInfoBuilder more) {
  32.         this.segmentParamsList.addAll(more.getSegmentParamsList());
  33.     }

  34.     @Override
  35.     public void finish() {
  36.         for (Iterator<SegmentParams> it = segmentParamsList.iterator(); it.hasNext(); ) {
  37.             SegmentParams s = it.next();
  38.             super.addSegment(s.value, s.valueIndex, s.geom, s.dist, !it.hasNext());
  39.         }
  40.     }

  41.     private static class SegmentParams {
  42.         double value;
  43.         long valueIndex;
  44.         PointList geom;
  45.         double dist;

  46.         SegmentParams(double value, long valueIndex, PointList geom, double dist) {
  47.             this.value = value;
  48.             this.valueIndex = valueIndex;
  49.             this.geom = geom;
  50.             this.dist = dist;
  51.         }
  52.     }
  53. }