Even if there was a way to modify the class to get a proper hash code, the question would be, which hash code should it be. Normally, hash codes and equality are using all properties of an object, so such a standard implementation would not help here as you want to have unique objects regarding a single property of the instances.
There is no standard hash map allowing you to provide a custom hash and equality function but you can do this for sorted maps. This will not give you O(1) like hashing, but it can give you O(log(n)) for a lookup which is still better than O(n).
Here is how it works like:
List<foo> list = // however you get it
Set<foo> set=new TreeSet<>(FooComparator.INSTANCE);
// now the set has no duplicates regarding foo.name
…
final class FooComparator implements Comparator<foo>
{
static final FooComparator INSTANCE = new FooComparator();
public int compare(foo o1, foo o2)
{
return o1.name.compareTo(o2.name);
}
}
class foo {
String name;
String time;
}