Ejemplo n.º 1
0
 @Nullable
 public IDirectedGraphRelation getIncomingRelationFrom(
     @Nullable final IDirectedGraphNode aFromNode) {
   if (m_aIncoming != null && aFromNode != null)
     for (final IDirectedGraphRelation aRelation : m_aIncoming.values())
       if (aRelation.getFrom().equals(aFromNode)) return aRelation;
   return null;
 }
Ejemplo n.º 2
0
 @Nonnull
 @ReturnsMutableCopy
 public Set<IDirectedGraphNode> getAllFromNodes() {
   final Set<IDirectedGraphNode> ret = new HashSet<IDirectedGraphNode>();
   if (m_aIncoming != null)
     for (final IDirectedGraphRelation aRelation : m_aIncoming.values())
       ret.add(aRelation.getFrom());
   return ret;
 }
Ejemplo n.º 3
0
  public void addIncomingRelation(@Nonnull final IDirectedGraphRelation aNewRelation) {
    if (aNewRelation == null) throw new NullPointerException("relation");
    if (aNewRelation.getTo() != this)
      throw new IllegalArgumentException("Passed incoming relation is not based on this node");
    if (m_aIncoming != null) {
      if (m_aIncoming.containsKey(aNewRelation.getID()))
        throw new IllegalArgumentException(
            "The passed relation ("
                + aNewRelation
                + ") is already contained as an incoming relation");

      // check if the relation from-node is already contained
      for (final IDirectedGraphRelation aRelation : m_aIncoming.values())
        if (aRelation.getFrom() == aNewRelation.getFrom())
          throw new IllegalArgumentException(
              "The from-node of the passed relation (" + aNewRelation + ") is already contained");
    } else {
      m_aIncoming = new LinkedHashMap<String, IDirectedGraphRelation>();
    }

    // Add!
    m_aIncoming.put(aNewRelation.getID(), aNewRelation);
  }