Class ExtendedSet<E>

  • All Implemented Interfaces:
    Iterable<E>, Collection<E>, Set<E>

    public class ExtendedSet<E>
    extends Object
    implements Set<E>
    A Set providing additional get, insertOrReplace and conditionalRemove methods.
    • Constructor Detail

      • ExtendedSet

        public ExtendedSet​(Map<E,​E> map)
        Constructs a new instance by backing it with the supplied Map.

        Constructed ExtendedSet will have the same concurrency properties as that of the supplied Map.

        Parameters:
        map - input map.
    • Method Detail

      • get

        public E get​(Object o)
        Returns set element that is equal to the specified object.
        Parameters:
        o - object
        Returns:
        set element that is equal to the input argument or null if no such set element exists
      • insertOrReplace

        public boolean insertOrReplace​(E entry,
                                       Predicate<E> entryTest)
        Inserts the entry if it is not already in the set otherwise replaces the existing entry if the supplied predicate evaluates to true.
        Parameters:
        entry - entry to add
        entryTest - predicate that is used to evaluate if the existing entry should be replaced
        Returns:
        true if the set is updated; false otherwise
      • conditionalRemove

        public boolean conditionalRemove​(E entry,
                                         Predicate<E> entryTest)
        Removes the entry if the supplied predicate evaluates to true.
        Parameters:
        entry - entry to remove
        entryTest - predicate that is used to evaluated aginst the existing entry. Return value of true implies value should be removed.
        Returns:
        true if the set is updated; false otherwise
      • size

        public int size()
        Specified by:
        size in interface Collection<E>
        Specified by:
        size in interface Set<E>
      • add

        public boolean add​(E e)
        Specified by:
        add in interface Collection<E>
        Specified by:
        add in interface Set<E>