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

org.opentripplanner.routing.services.notes.DynamicStreetNotesSource Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
/* This program is free software: you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public License
 as published by the Free Software Foundation, either version 3 of
 the License, or (props, at your option) any later version.

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

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see . */

package org.opentripplanner.routing.services.notes;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import org.opentripplanner.routing.edgetype.PartialStreetEdge;
import org.opentripplanner.routing.graph.Edge;

import java.util.Set;

/**
 * A notes source of dynamic notes, Usually created and modified by a single GraphUpdater.
 *
 * @author hannesj
 */
public class DynamicStreetNotesSource implements StreetNotesSource {

    private static final long serialVersionUID = 1L;

    /**
     * Notes for street edges. Volatile in order to guarantee that the access to notesForEdge is safe.
     */
    private volatile SetMultimap notesForEdge = HashMultimap.create();

    public DynamicStreetNotesSource() {
    }

    /**
     * Return the set of notes applicable for this state / backedge pair.
     *
     * @param edge The edge for which the notes will be returned.
     * @return The set of notes or null if empty.
     */
    @Override
    public Set getNotes(Edge edge) {
        /* If the edge is temporary, we look for notes in it's parent edge. */
        if (edge instanceof PartialStreetEdge) {
            edge = ((PartialStreetEdge) edge).getParentEdge();
        }
        Set maas = notesForEdge.get(edge);
        if (maas == null || maas.isEmpty()) {
            return null;
        }
        return maas;
    }

    /*
     * Update the NotesSource with a new set of notes.
     */
    public void setNotes(SetMultimap notes){
        this.notesForEdge = notes;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy