@Nullable public IDirectedGraphRelation getOutgoingRelationTo(@Nullable final IDirectedGraphNode aToNode) { if (m_aOutgoing != null && aToNode != null) for (final IDirectedGraphRelation aRelation : m_aOutgoing.values()) if (aRelation.getTo().equals(aToNode)) return aRelation; return null; }
@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; }
@Nonnull @ReturnsMutableCopy public Set<IDirectedGraphNode> getAllToNodes() { final Set<IDirectedGraphNode> ret = new HashSet<IDirectedGraphNode>(); if (m_aOutgoing != null) for (final IDirectedGraphRelation aRelation : m_aOutgoing.values()) ret.add(aRelation.getTo()); return ret; }
@Nonnull @ReturnsMutableCopy public Set<String> getAllRelatedNodeIDs() { final Set<String> ret = new LinkedHashSet<String>(); if (m_aIncoming != null) for (final IDirectedGraphRelation aRelation : m_aIncoming.values()) ret.add(aRelation.getFromID()); if (m_aOutgoing != null) for (final IDirectedGraphRelation aRelation : m_aOutgoing.values()) ret.add(aRelation.getToID()); return ret; }
public void addOutgoingRelation(@Nonnull final IDirectedGraphRelation aNewRelation) { if (aNewRelation == null) throw new NullPointerException("relation"); if (aNewRelation.getFrom() != this) throw new IllegalArgumentException("Passed outgoing relation is not based on this node"); if (m_aOutgoing != null) { if (m_aOutgoing.containsKey(aNewRelation.getID())) throw new IllegalArgumentException( "The passed relation " + aNewRelation + " is already contained as an outgoing relation"); // check if the relation to-node is already contained for (final IDirectedGraphRelation aRelation : m_aOutgoing.values()) if (aRelation.getTo() == aNewRelation.getTo()) throw new IllegalArgumentException( "The to-node of the passed relation " + aNewRelation + " is already contained"); } else { m_aOutgoing = new LinkedHashMap<String, IDirectedGraphRelation>(); } // Add! m_aOutgoing.put(aNewRelation.getID(), aNewRelation); }
public boolean isIncomingRelation(@Nullable final IDirectedGraphRelation aRelation) { return m_aIncoming != null && aRelation != null && aRelation.equals(m_aIncoming.get(aRelation.getID())); }
@Nonnull public EChange removeOutgoingRelation(@Nonnull final IDirectedGraphRelation aRelation) { return aRelation == null || m_aOutgoing == null ? EChange.UNCHANGED : EChange.valueOf(m_aOutgoing.remove(aRelation.getID()) != null); }