For Java, there are many available. JGraphT is simple and nice. Jung, JTS etc.
If you are implementing on your own, then I would rather use a LinkedHashSet, ex:
public abstract class Graphs<T, E>
{
final LinkedHashSet<Vertex<? extends T>> allVertex;
...
and Vertex would be:
/**
* E is of the type: the kind of vertex I want to make. For example String
*/
public interface Vertice<E>
{
public void setAttribute(E ob);
public E getAttribute();
// public Set<Edge<?>> getConnectedVertices();
public Set<Edge<?>> getConnectedEdges();
public Edge<?> getPassageToVertice(Vertice<?> vertice);
}
With Edge being:
package Graph;
public interface Edge<E>
{
/**
* Returns the attribute Associated with the Edge
* @return The Attribute associated with the Edge
*/
public E getAttribute();
public void setSource(Vertex<?> source);
public void setDestination(Vertex<?> dest);
/**
* Sets the attribute of the edge
* @param attr Sets the attribute of the Edge
*/
void setAttribute(E attr);
/**
* Get the permission to access the destination from the source.
* <p> For example:
* <li>A-------edge---------B </li>
* here A is a vertex
* B is a vertex
* edge is the edge.
* If the argument of the method is vertex A then it returns Vertex B, if it is
* legal to return (for ex will return B if the edge is intended to be Undirected)
* This method can be used to create different types of Edge's.</p>
* <p> In case of a directed edge
* <li>A----->----edge------>B</li>
* on calling getPassage(B) it will return null.
* </p>
* @param source One end of the edge
* @return The other end of the edge if the edge has access to. Or else return null;
*/
public Vertex<?> getPassage(Vertex<?> source);
public Vertex<?> getSource();
public Vertex<?> getDestination();
}