Graph class implemented in Java