All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.analyst.SurfaceCache Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
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