Skip to content

Commit

Permalink
Added a few more utility functions to the nodes and iterators.
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierMarrero committed Nov 13, 2022
1 parent a5b9d4a commit 3d08923
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 310 deletions.
8 changes: 8 additions & 0 deletions src/cu/edu/cujae/graphy/core/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package cu.edu.cujae.graphy.core;

import java.util.Collection;
import java.util.Set;

/**
Expand Down Expand Up @@ -78,6 +79,13 @@ public interface Node<T> extends Cloneable
*/
public Edge getAdjacentEdge(Node<T> v);

/**
* Returns a {@link Collection} containing all the adjacent vertices to this node.
*
* @return
*/
public Collection<Integer> getAllAdjacentVertices();

/**
* Returns the set of edges connected to this node. If the node is isolated, it should return the empty set. This
* set is an unmodifiable view of the {@link Node}'s internal container.
Expand Down
22 changes: 17 additions & 5 deletions src/cu/edu/cujae/graphy/core/defaults/DefaultNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@

import cu.edu.cujae.graphy.core.Edge;
import cu.edu.cujae.graphy.core.Node;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;

/**
Expand Down Expand Up @@ -110,6 +106,22 @@ public Edge getAdjacentEdge(Node<T> v)
return getConnectionsFromVertex().get(v);
}

@Override
public Collection<Integer> getAllAdjacentVertices()
{
Collection<Integer> nodes = new LinkedHashSet<>(getConnectionsFromVertex().size() + getConnectionsToVertex().size());
for (Edge e : getEdgesArrivingSelf())
{
nodes.add(e.getStartNode().getLabel());
}
for (Edge e : getEdgesDepartingSelf())
{
nodes.add(e.getFinalNode().getLabel());
}

return Collections.unmodifiableCollection(nodes);
}

/**
* {@inheritDoc}
*/
Expand Down
Loading

0 comments on commit 3d08923

Please sign in to comment.