/** * For the given trip ID, fetch all the stop times in order of increasing stop_sequence. * This is an efficient iteration over a tree map. */ public Iterable<StopTime> getOrderedStopTimesForTrip (String trip_id) { Map<Fun.Tuple2, StopTime> tripStopTimes = stop_times.subMap( Fun.t2(trip_id, null), Fun.t2(trip_id, Fun.HI) ); return tripStopTimes.values(); }
@Override public void remove( String nodeKey, String propertyName, T value ) { // Find all of the T values (entry keys) for the given node key (entry values) and remove those which have value 'value' for (UniqueKey<T> key : Fun.filter(valuesByKey, nodeKey)) { if (key.actualKey.equals(value)) { logger.trace("Removing node '{0}' from '{1}' index with value '{2}'", nodeKey, name, key.actualKey); keysByValue.remove(key); } } }
@Override public boolean equals( Object o ) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LocalTuple2KeySerializer<A, B> t = (LocalTuple2KeySerializer<A, B>)o; return Fun.eq(aComparator, t.aComparator) && Fun.eq(aSerializer, t.aSerializer) && Fun.eq(bSerializer, t.bSerializer); }
@Override public void remove( String nodeKey, String propertyName, T value ) { // Find all of the T values (entry keys) for the given node key (entry values) ... for (T key : Fun.filter(valuesByKey, nodeKey)) { if (comparator.compare(value, key) == 0) { logger.trace("Removing node '{0}' from '{1}' index with value '{2}'", nodeKey, name, value); keysByValue.remove(key); } } }
@Override public boolean equals( Object o ) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LocalTuple2KeySerializer<A, B> t = (LocalTuple2KeySerializer<A, B>)o; return Fun.eq(aComparator, t.aComparator) && Fun.eq(aSerializer, t.aSerializer) && Fun.eq(bSerializer, t.bSerializer); }
@Override public void loadOneRow() throws IOException { Frequency f = new Frequency(); Trip trip = getRefField("trip_id", true, feed.trips); f.sourceFileLine = row + 1; // offset line number by 1 to account for 0-based row index f.trip_id = trip.trip_id; f.start_time = getTimeField("start_time", true); f.end_time = getTimeField("end_time", true); f.headway_secs = getIntField("headway_secs", true, 1, 24 * 60 * 60); f.exact_times = getIntField("exact_times", false, 0, 1); f.feed = feed; feed.frequencies.add(Fun.t2(f.trip_id, f)); } }
@Override public void remove( String nodeKey, String propertyName, T value ) { // Find all of the T values (entry keys) for the given node key (entry values) and remove those which have value 'value' for (UniqueKey<T> key : Fun.filter(valuesByKey, nodeKey)) { if (key.actualKey.equals(value)) { logger.trace("Removing node '{0}' from '{1}' index with value '{2}'", nodeKey, name, key.actualKey); keysByValue.remove(key); } } }
public void add(K key,V value){ entries.add(Fun.t2(key, value)); } public Iterator<Tuple2<K,V>> batchInsertIterator(){
@Override public void remove( String nodeKey, String propertyName, T value ) { // Find all of the T values (entry keys) for the given node key (entry values) ... for (T key : Fun.filter(valuesByKey, nodeKey)) { if (comparator.compare(value, key) == 0) { logger.trace("Removing node '{0}' from '{1}' index with value '{2}'", nodeKey, name, value); keysByValue.remove(key); } } }
public void add(K key,V value){ entries.add(Fun.t2(key, value)); } public Iterator<Tuple2<K,V>> batchInsertIterator(){
@Override public void remove( String nodeKey ) { // Find all of the T values (entry keys) for the given node key (entry values) ... for (UniqueKey<T> key : Fun.filter(valuesByKey, nodeKey)) { logger.trace("Removing node '{0}' from '{1}' index with value '{2}'", nodeKey, name, key.actualKey); keysByValue.remove(key); } } }
public void add(K key,V value){ entries.add(Fun.t2(key, value)); } public Iterator<Tuple2<K,V>> batchInsertIterator(){
@Override public void remove( String nodeKey ) { // Find all of the T values (entry keys) for the given node key (entry values) ... for (T key : Fun.filter(valuesByKey, nodeKey)) { logger.trace("Removing node '{0}' from '{1}' index with value '{2}'", nodeKey, name, key); keysByValue.remove(key); } }
/** * For the given trip ID, fetch all the stop times in order of increasing stop_sequence. * This is an efficient iteration over a tree map. */ public Iterable<StopTime> getOrderedStopTimesForTrip (String trip_id) { Map<Fun.Tuple2, StopTime> tripStopTimes = stop_times.subMap( Fun.t2(trip_id, null), Fun.t2(trip_id, Fun.HI) ); return tripStopTimes.values(); }
@Override public void remove( String nodeKey ) { // Find all of the T values (entry keys) for the given node key (entry values) ... for (T key : Fun.filter(valuesByKey, nodeKey)) { logger.trace("Removing node '{0}' from '{1}' index with value '{2}'", nodeKey, name, key); keysByValue.remove(key); } }
@Override public void add(long entityId, Map<String, Object> properties) { for (Map.Entry<String, Object> entry : properties.entrySet()) { getSet(entry.getKey()).add(Fun.t2(entry.getValue(), entityId)); } index.add(entityId,properties); }
@Override public void remove( String nodeKey ) { // Find all of the T values (entry keys) for the given node key (entry values) ... for (UniqueKey<T> key : Fun.filter(valuesByKey, nodeKey)) { logger.trace("Removing node '{0}' from '{1}' index with value '{2}'", nodeKey, name, key.actualKey); keysByValue.remove(key); } } }
/** Get trip speed in meters per second. */ public double getTripSpeed (String trip_id, boolean straightLine) { StopTime firstStopTime = this.stop_times.ceilingEntry(Fun.t2(trip_id, null)).getValue(); StopTime lastStopTime = this.stop_times.floorEntry(Fun.t2(trip_id, Fun.HI)).getValue(); // ensure that stopTime returned matches trip id (i.e., that the trip has stoptimes) if (!firstStopTime.trip_id.equals(trip_id) || !lastStopTime.trip_id.equals(trip_id)) { return Double.NaN; } double distance = getTripDistance(trip_id, straightLine); // trip time (in seconds) int time = lastStopTime.arrival_time - firstStopTime.departure_time; return distance / time; // meters per second }
@Override public Object[] deserialize( DataInput in, int start, int end, int size ) throws IOException { Object[] ret = new Object[size]; A a = null; int acount = 0; for (int i = start; i < end; i++) { if (acount == 0) { // read new A a = aSerializer.deserialize(in, -1); acount = DataInput2.unpackInt(in); } B b = bSerializer.deserialize(in, -1); ret[i] = Fun.t2(a, b); acount--; } assert (acount == 0); return ret; }
@Override public Object[] deserialize( DataInput in, int start, int end, int size ) throws IOException { Object[] ret = new Object[size]; A a = null; int acount = 0; for (int i = start; i < end; i++) { if (acount == 0) { // read new A a = aSerializer.deserialize(in, -1); acount = DataInput2.unpackInt(in); } B b = bSerializer.deserialize(in, -1); ret[i] = Fun.t2(a, b); acount--; } assert (acount == 0); return ret; }