/** @see Graph#getAllEdges(Object, Object) */
    public Set<E> getAllEdges(V sourceVertex, V targetVertex) {
      Set<E> edges = null;

      if (containsVertex(sourceVertex) && containsVertex(targetVertex)) {
        edges = new ArrayUnenforcedSet<E>();

        Iterator<E> iter = getEdgeContainer(sourceVertex).vertexEdges.iterator();

        while (iter.hasNext()) {
          E e = iter.next();

          boolean equalStraight =
              sourceVertex.equals(getEdgeSource(e)) && targetVertex.equals(getEdgeTarget(e));

          boolean equalInverted =
              sourceVertex.equals(getEdgeTarget(e)) && targetVertex.equals(getEdgeSource(e));

          if (equalStraight || equalInverted) {
            edges.add(e);
          }
        }
      }

      return edges;
    }
  /**
   * Compares the specified Object with this Map for equality, as per the definition in the Map
   * interface.
   *
   * @param o object to be compared for equality with this hashtable
   * @return true if the specified Object is equal to this Map
   * @see Map#equals(Object)
   * @since 1.2
   */
  public synchronized boolean equals(Object o) {
    if (o == this) return true;

    if (!(o instanceof Map)) return false;
    Map<?, ?> t = (Map<?, ?>) o;
    if (t.size() != size()) return false;

    try {
      for (Map.Entry<K, V> e : entrySet()) {
        K key = e.getKey();
        V value = e.getValue();
        if (value == null) {
          if (!(t.get(key) == null && t.containsKey(key))) return false;
        } else {
          if (!value.equals(t.get(key))) return false;
        }
      }
    } catch (ClassCastException unused) {
      return false;
    } catch (NullPointerException unused) {
      return false;
    }

    return true;
  }
  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);
        }
      }
    }
  }
Exemple #4
0
  /**
   * Compares the specified Object with this Map for equality, as per the definition in the Map
   * interface.
   *
   * @param o object to be compared for equality with this hashtable
   * @return true if the specified Object is equal to this Map
   * @see Map#equals(Object)
   * @since 1.2
   */
  public synchronized boolean equals(Object o) {
    if (o == this) return true;

    if (!(o instanceof Map)) return false;
    Map<K, V> t = (Map<K, V>) o;
    if (t.size() != size()) return false;

    try {
      Iterator<Map.Entry<K, V>> i = entrySet().iterator();
      while (i.hasNext()) {
        Map.Entry<K, V> e = i.next();
        K key = e.getKey();
        V value = e.getValue();
        if (value == null) {
          if (!(t.get(key) == null && t.containsKey(key))) return false;
        } else {
          if (!value.equals(t.get(key))) return false;
        }
      }
    } catch (ClassCastException unused) {
      return false;
    } catch (NullPointerException unused) {
      return false;
    }

    return true;
  }
    /** @see AbstractBaseGraph#removeEdgeFromTouchingVertices(Edge) */
    public void removeEdgeFromTouchingVertices(E e) {
      V source = getEdgeSource(e);
      V target = getEdgeTarget(e);

      getEdgeContainer(source).removeEdge(e);

      if (!source.equals(target)) {
        getEdgeContainer(target).removeEdge(e);
      }
    }
  /** @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;
  }
  /** @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;
    }
  }
    public boolean equals(Object o) {
      if (!(o instanceof Map.Entry)) return false;
      Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;

      return (key == null ? e.getKey() == null : key.equals(e.getKey()))
          && (value == null ? e.getValue() == null : value.equals(e.getValue()));
    }
  /**
   * Returns a string representation of this {@code Hashtable} object in the form of a set of
   * entries, enclosed in braces and separated by the ASCII characters "<code> ,&nbsp;</code>"
   * (comma and space). Each entry is rendered as the key, an equals sign {@code =}, and the
   * associated element, where the {@code toString} method is used to convert the key and element to
   * strings.
   *
   * @return a string representation of this hashtable
   */
  public synchronized String toString() {
    int max = size() - 1;
    if (max == -1) return "{}";

    StringBuilder sb = new StringBuilder();
    Iterator<Map.Entry<K, V>> it = entrySet().iterator();

    sb.append('{');
    for (int i = 0; ; i++) {
      Map.Entry<K, V> e = it.next();
      K key = e.getKey();
      V value = e.getValue();
      sb.append(key == this ? "(this Map)" : key.toString());
      sb.append('=');
      sb.append(value == this ? "(this Map)" : value.toString());

      if (i == max) return sb.append('}').toString();
      sb.append(", ");
    }
  }
    /** @see Graph#getEdge(Object, Object) */
    public E getEdge(V sourceVertex, V targetVertex) {
      if (containsVertex(sourceVertex) && containsVertex(targetVertex)) {
        Iterator<E> iter = getEdgeContainer(sourceVertex).vertexEdges.iterator();

        while (iter.hasNext()) {
          E e = iter.next();

          boolean equalStraight =
              sourceVertex.equals(getEdgeSource(e)) && targetVertex.equals(getEdgeTarget(e));

          boolean equalInverted =
              sourceVertex.equals(getEdgeTarget(e)) && targetVertex.equals(getEdgeSource(e));

          if (equalStraight || equalInverted) {
            return e;
          }
        }
      }

      return null;
    }
 public boolean containsValue(final V val) {
   final byte[] states = this._states;
   final V[] vals = (V[]) this._values;
   if (null == val) {
     int i = vals.length;
     while (i-- > 0) {
       if (states[i] == 1 && val == vals[i]) {
         return true;
       }
     }
   } else {
     int i = vals.length;
     while (i-- > 0) {
       if (states[i] == 1 && (val == vals[i] || val.equals(vals[i]))) {
         return true;
       }
     }
   }
   return false;
 }
 public String toString() {
   return key.toString() + "=" + value.toString();
 }
Exemple #13
0
 public int hashCode() {
   return hash ^ (value == null ? 0 : value.hashCode());
 }
Exemple #14
0
 public final int hashCode() {
   return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
 }