예제 #1
0
  /** @see Graph#addEdge(Object, Object, Object) */
  public boolean addEdge(V sourceVertex, V targetVertex, E e) {
    if (e == null) {
      throw new NullPointerException();
    } else if (containsEdge(e)) {
      return false;
    }

    assertVertexExist(sourceVertex);
    assertVertexExist(targetVertex);

    if (!allowingMultipleEdges && containsEdge(sourceVertex, targetVertex)) {
      return false;
    }

    if (!allowingLoops && sourceVertex.equals(targetVertex)) {
      throw new IllegalArgumentException(LOOPS_NOT_ALLOWED);
    }

    IntrusiveEdge intrusiveEdge = createIntrusiveEdge(e, sourceVertex, targetVertex);

    edgeMap.put(e, intrusiveEdge);
    specifics.addEdgeToTouchingVertices(e);

    return true;
  }
예제 #2
0
  /** @see Graph#addEdge(Object, Object) */
  public E addEdge(V sourceVertex, V targetVertex) {
    assertVertexExist(sourceVertex);
    assertVertexExist(targetVertex);

    if (!allowingMultipleEdges && containsEdge(sourceVertex, targetVertex)) {
      return null;
    }

    if (!allowingLoops && sourceVertex.equals(targetVertex)) {
      throw new IllegalArgumentException(LOOPS_NOT_ALLOWED);
    }

    E e = edgeFactory.createEdge(sourceVertex, targetVertex);

    if (containsEdge(e)) { // this restriction should stay!

      return null;
    } else {
      IntrusiveEdge intrusiveEdge = createIntrusiveEdge(e, sourceVertex, targetVertex);

      edgeMap.put(e, intrusiveEdge);
      specifics.addEdgeToTouchingVertices(e);

      return e;
    }
  }
예제 #3
0
  /** @see Graph#vertexSet() */
  public Set<V> vertexSet() {
    if (unmodifiableVertexSet == null) {
      unmodifiableVertexSet = Collections.unmodifiableSet(specifics.getVertexSet());
    }

    return unmodifiableVertexSet;
  }
예제 #4
0
  public void union(AbstractBaseGraph<V, E> g2) {
    if (!(this instanceof DirectedGraph<?, ?> && g2 instanceof DirectedGraph<?, ?>)) {
      return;
    }
    Set<V> vertexSet = g2.vertexSet();
    for (V vertex : vertexSet) {
      if (!containsVertex(vertex)) addVertex(vertex);
    }

    for (V vertex : vertexSet) {
      Set<E> edgeSet = g2.specifics.outgoingEdgesOf(vertex);
      for (E edge : edgeSet) {
        V sourceVertex = getEdgeSource(edge);
        V targetVertex = getEdgeTarget(edge);
        if (!allowingMultipleEdges && containsEdge(sourceVertex, targetVertex)) {
          continue;
        }

        if (!allowingLoops && sourceVertex.equals(targetVertex)) {
          continue;
        }

        if (containsEdge(edge)) {
          continue;
        } else {
          IntrusiveEdge intrusiveEdge = createIntrusiveEdge(edge, sourceVertex, targetVertex);

          edgeMap.put(edge, intrusiveEdge);
          specifics.addEdgeToTouchingVertices(edge);
        }
      }
    }
  }
예제 #5
0
  /** @see Graph#removeEdge(Object) */
  public boolean removeEdge(E e) {
    if (containsEdge(e)) {
      specifics.removeEdgeFromTouchingVertices(e);
      edgeMap.remove(e);

      return true;
    } else {
      return false;
    }
  }
예제 #6
0
  /** @see Graph#removeEdge(Object, Object) */
  public E removeEdge(V sourceVertex, V targetVertex) {
    E e = getEdge(sourceVertex, targetVertex);

    if (e != null) {
      specifics.removeEdgeFromTouchingVertices(e);
      edgeMap.remove(e);
    }

    return e;
  }
예제 #7
0
  /** @see Graph#addVertex(Object) */
  public boolean addVertex(V v) {
    if (v == null) {
      throw new NullPointerException();
    } else if (containsVertex(v)) {
      return false;
    } else {
      specifics.addVertex(v);

      return true;
    }
  }
예제 #8
0
  private void addUnseenChildrenOf(V vertex) {
    for (E edge : specifics.edgesOf(vertex)) {
      if (nListeners != 0) {
        fireEdgeTraversed(createEdgeTraversalEvent(edge));
      }

      V oppositeV = Graphs.getOppositeVertex(graph, edge, vertex);

      if (isSeenVertex(oppositeV)) {
        encounterVertexAgain(oppositeV, edge);
      } else {
        encounterVertex(oppositeV, edge);
      }
    }
  }
예제 #9
0
  /** @see Graph#removeVertex(Object) */
  public boolean removeVertex(V v) {
    if (containsVertex(v)) {
      Set<E> touchingEdgesList = edgesOf(v);

      // cannot iterate over list - will cause
      // ConcurrentModificationException
      removeAllEdges(new ArrayList<E>(touchingEdgesList));

      specifics.getVertexSet().remove(v); // remove the vertex itself

      return true;
    } else {
      return false;
    }
  }
예제 #10
0
 /** @see DirectedGraph#inDegreeOf(Object) */
 public int inDegreeOf(V vertex) {
   return specifics.inDegreeOf(vertex);
 }
예제 #11
0
 /** @see Graph#getEdge(Object, Object) */
 public E getEdge(V sourceVertex, V targetVertex) {
   return specifics.getEdge(sourceVertex, targetVertex);
 }
예제 #12
0
 /** @see UndirectedGraph#degreeOf(Object) */
 public int degreeOf(V vertex) {
   return specifics.degreeOf(vertex);
 }
예제 #13
0
 /** @see Graph#containsVertex(Object) */
 public boolean containsVertex(V v) {
   return specifics.getVertexSet().contains(v);
 }
예제 #14
0
 /** @see DirectedGraph#outgoingEdgesOf(Object) */
 public Set<E> outgoingEdgesOf(V vertex) {
   return specifics.outgoingEdgesOf(vertex);
 }
예제 #15
0
 /** @see DirectedGraph#outDegreeOf(Object) */
 public int outDegreeOf(V vertex) {
   return specifics.outDegreeOf(vertex);
 }
예제 #16
0
 /** @see DirectedGraph#incomingEdgesOf(Object) */
 public Set<E> incomingEdgesOf(V vertex) {
   return specifics.incomingEdgesOf(vertex);
 }
예제 #17
0
 /** @see Graph#getAllEdges(Object, Object) */
 public Set<E> getAllEdges(V sourceVertex, V targetVertex) {
   return specifics.getAllEdges(sourceVertex, targetVertex);
 }
예제 #18
0
 /** @see Graph#edgesOf(Object) */
 public Set<E> edgesOf(V vertex) {
   return specifics.edgesOf(vertex);
 }