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

org.opentripplanner.common.geometry.Subgraph Maven / Gradle / Ivy

package org.opentripplanner.common.geometry;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.opentripplanner.routing.graph.Vertex;
import org.opentripplanner.routing.vertextype.TransitStopVertex;

public class Subgraph {

  private final Set streetVertexSet;
  private final Set stopsVertexSet;

  public Subgraph() {
    streetVertexSet = new HashSet<>();
    stopsVertexSet = new HashSet<>();
  }

  public void addVertex(Vertex vertex) {
    if (vertex instanceof TransitStopVertex) {
      stopsVertexSet.add(vertex);
    } else {
      streetVertexSet.add(vertex);
    }
  }

  public boolean contains(Vertex vertex) {
    return (streetVertexSet.contains(vertex) || stopsVertexSet.contains(vertex));
  }

  public int streetSize() {
    return streetVertexSet.size();
  }

  public int stopSize() {
    return stopsVertexSet.size();
  }

  public Vertex getRepresentativeVertex() {
    //TODO this is not very smart but good enough at the moment
    return streetVertexSet.iterator().next();
  }

  public Iterator streetIterator() {
    return streetVertexSet.iterator();
  }

  public Iterator stopIterator() {
    return stopsVertexSet.iterator();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy