Class CustomSet<T>

  • Type Parameters:
    T - The type of the entries in the set

    public class CustomSet<T>
    extends java.lang.Object
    A mutable set implementation using a custom equality matcher, to avoid having to wrap each entry in a wrapper object to achieve customised equality testing.

    Note: this doesn't implement java.util.Set<T>. This is to save the effort of implementing methods like size() and iterator() that aren't required for our use cases. These methods could easily be added without changing the basic design.

    • Constructor Summary

      Constructors 
      Constructor Description
      CustomSet​(EqualityMatcher<T> matcher)
      Create an empty set using the supplied equality matcher
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T value)
      Add a value to the set
      boolean contains​(T value)
      Ask if a value exists in the set
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CustomSet

        public CustomSet​(EqualityMatcher<T> matcher)
        Create an empty set using the supplied equality matcher
        Parameters:
        matcher - the function used to compare items for equality
    • Method Detail

      • add

        public boolean add​(T value)
        Add a value to the set
        Parameters:
        value - the value to be added.
        Returns:
        true if the value is newly added, that is, if it was not already present
      • contains

        public boolean contains​(T value)
        Ask if a value exists in the set
        Parameters:
        value - the requested value
        Returns:
        true if it exists