E - the type of elements maintained by the created set or keys by the created map.public class EqualityTransformingCollectionBuilder<E> extends Object
EqualityTransformingSets and EqualityTransformingMaps.
(For simplification the comments only talk about sets but unless otherwise noted the same applies to maps.)
The implementations of equals and hashCode are provided as functions to the builder. They must of
course fulfill the general contract between those two methods (see here). The functions can
be provided on two ways:
with[Equals|Hash]-methods. In this case, the functions will never be called with null instances,
which are handled by this map as follows:
hashCode(null) == 0
equals(null, null) == true;
equals(not-null, null) == false
equals(null, not-null) == false
with[Equals|Hash]HandlingNull-methods.
The same builder instance can be reused to create multiple instances. The builder is not thread-safe and should not be used concurrently.
public static <E> EqualityTransformingCollectionBuilder<E> forType(Class<? super E> keyTypeToken)
If a type token for the elements can not be provided, call forTypeUnknown() instead.
E - the type of elements contained in the created setkeyTypeToken - a type token for the elements contained in the created setpublic static <E> EqualityTransformingCollectionBuilder<E> forTypeUnknown()
This is equivalent to calling forKeyType(Object.class). To obtain a builder for
<E> you will have to call EqualityTransformingCollectionBuilder.<E> forTypeUnknown().
E - the type of elements contained in the set created by the builderpublic EqualityTransformingCollectionBuilder<E> withEqualsHandlingNull(BiPredicate<? super E,? super E> equals)
equals - a function determining equality of elements; might be called with null elementspublic EqualityTransformingCollectionBuilder<E> withEquals(BiPredicate<? super E,? super E> equals)
equals - a function determining equality of elements; will not be called with null elementspublic EqualityTransformingCollectionBuilder<E> withHashHandlingNull(ToIntFunction<? super E> hash)
hash - a function computing the hash code of an element; might be called with null elementspublic EqualityTransformingCollectionBuilder<E> withHash(ToIntFunction<? super E> hash)
hash - a function computing the hash code of an element; will not be called with null elementspublic EqualityTransformingSet<E> buildSet()
EqualityTransformingSet by decorating a HashSet.EqualityTransformingSetpublic EqualityTransformingSet<E> buildSet(Set<Object> emptySet)
EqualityTransformingSet by decorating the specified set.emptySet - an empty set which is not otherwise referencedEqualityTransformingSetpublic <V> EqualityTransformingMap<E,V> buildMap()
EqualityTransformingMap by decorating a HashMap.V - the type of values mapped by the new mapEqualityTransformingMappublic <V> EqualityTransformingMap<E,V> buildMap(Map<Object,Object> emptyMap)
EqualityTransformingMap by decorating the specified map.V - the type of values mapped by the new mapemptyMap - an empty map which is not otherwise referencedEqualityTransformingMapThis documentation is licensed under CC-BY 4.0, attributed to Nicolai Parlog from CodeFX.