Class SetUniqueList

  • All Implemented Interfaces:
    Serializable, Iterable, Collection, List

    public class SetUniqueList
    extends AbstractSerializableListDecorator
    Decorates a List to ensure that no duplicates are present much like a Set.

    The List interface makes certain assumptions/requirements. This implementation breaks these in certain ways, but this is merely the result of rejecting duplicates. Each violation is explained in the method, but it should not affect you. Bear in mind that Sets require immutable objects to function correctly.

    The ListOrderedSet class provides an alternative approach, by wrapping an existing Set and retaining insertion order in the iterator.

    This class is Serializable from Commons Collections 3.1.

    Since:
    Commons Collections 3.0
    Version:
    $Revision: 1713299 $ $Date: 2015-11-08 22:35:53 +0100 (Sun, 08 Nov 2015) $
    Author:
    Matthew Hawthorne, Stephen Colebourne, Tom Dunham
    See Also:
    Serialized Form
    • Field Detail

      • set

        protected final Set set
        Internal Set to maintain uniqueness.
    • Constructor Detail

      • SetUniqueList

        protected SetUniqueList​(List list,
                                Set set)
        Constructor that wraps (not copies) the List and specifies the set to use.

        The set and list must both be correctly initialised to the same elements.

        Parameters:
        set - the set to decorate, must not be null
        list - the list to decorate, must not be null
        Throws:
        IllegalArgumentException - if set or list is null