Graph implementation in java