MATSIM
MediumCompressedNetworkRoute.java
Go to the documentation of this file.
1 package org.matsim.core.population.routes.mediumcompressed;
2 
3 import org.matsim.api.core.v01.Id;
8 
9 import java.util.ArrayList;
10 import java.util.Collections;
11 import java.util.List;
12 
29 
30  private final static byte[] EMPTY_ROUTE = new byte[0];
31  private byte[] route = EMPTY_ROUTE;
32 
33  public MediumCompressedNetworkRoute(Id<Link> startLinkId, Id<Link> endLinkId) {
34  this.setStartLinkId(startLinkId);
35  this.setEndLinkId(endLinkId);
36  }
37 
38  @Override
39  public void setLinkIds(Id<Link> startLinkId, List<Id<Link>> linkIds, Id<Link> endLinkId) {
40  this.setStartLinkId(startLinkId);
41  this.setEndLinkId(endLinkId);
42  int linkCount = linkIds == null ? 0 : linkIds.size();
43  int[] route = new int[linkCount];
44  int i = 0;
45  if (linkIds != null) {
46  for (Id<Link> linkId : linkIds) {
47  route[i] = linkId.index();
48  i++;
49  }
50  }
51  this.route = VarIntUtils.encode(route, 0, route.length);
52  }
53 
54  @Override
55  public List<Id<Link>> getLinkIds() {
56  if (this.route == null || this.route == EMPTY_ROUTE) {
57  return Collections.emptyList();
58  }
59  int[] idxRoute = VarIntUtils.decode(this.route);
60  List<Id<Link>> linkIds = new ArrayList<>(idxRoute.length);
61  for (int linkIndex : idxRoute) {
62  linkIds.add(Id.get(linkIndex, Link.class));
63  }
64  return linkIds;
65  }
66 
67  @Override
69  return (MediumCompressedNetworkRoute) super.clone();
70  }
71 
72 }
static< T > Id< T > get(int index, final Class< T > type)
Definition: Id.java:112
void setLinkIds(Id< Link > startLinkId, List< Id< Link >> linkIds, Id< Link > endLinkId)