An easy way to think about graphs is to break them down into their Node and Edge components. (Note: what you call a vertex I call a node. Close enough.)
Let us consider the following options:
// Option 1
class Node<V> {
V data;
Set<Node<V>> edges;
// if it were a directed graph, you'd need:
// Set<Node<V>> edgesAway;
}
// Option 2
class Node<V> {
V data;
Set<Edge<V>> edges;
// if it were a directed graph, you'd need:
// Set<Edge<V>> edgesAway;
}
class Edge<V> {
Node<V> source;
Node<V> destination;
}
Now a graph is nothing more than:
// option 1
class Graph<V> {
Set<Node<V>> nodes;
}
// option 2
class Graph<V> {
Set<Node<V>> nodes;
Set<Edge<V>> edges;
}
Option 1 is the simplest and easiest to implement. Option 2 gives you some more flexibility, such as adding weights to the edge values.
Now, you have some data at these nodes, correct? For now, let's just have the data be the string representation of the coordinates.
class SomeObject {
String data;
int x;
int y;
public boolean equals(Object o) {
if(o instanceof SomeObject) {
SomeObject so = (SomeObject)o;
return so.x == x && so.y == y;
}
return false;
}
public int hashCode() {
return x * 100 + y; // it works... close enough :)
}
}
// somewhere later:
Graph<SomeObject> graph = ...
Now as for what functionality you'll want you'd need a more complete list. But this should get you well on your way to understanding how to implement a graph.