Graph utility class in java