
org.opentripplanner.analyst.SurfaceCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.analyst;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import org.opentripplanner.routing.spt.ShortestPathTree;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Queue;
/**
* Caches travel time surfaces, which are derived from shortest path trees.
* TODO add LRU behavior upon get
* TODO extend to store any type by moving the IDs into the cache
* TODO use a disk-backed MapDB to avoid eating memory
*/
public class SurfaceCache {
public static final int NONE = -1;
public final Cache cache;
public SurfaceCache (int capacity) {
this.cache = CacheBuilder.newBuilder()
.maximumSize(100)
.build();
}
public int add(TimeSurface surface) {
this.cache.put(surface.id, surface);
return surface.id;
}
public TimeSurface get(int id) {
return this.cache.getIfPresent(id);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy