Package mondrian.util

Class ArraySortedSet<E extends java.lang.Comparable<E>>

  • Type Parameters:
    E -
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, java.util.SortedSet<E>

    public class ArraySortedSet<E extends java.lang.Comparable<E>>
    extends java.util.AbstractSet<E>
    implements java.util.SortedSet<E>, java.io.Serializable
    Implementation of SortedSet based on an array. The array must already be sorted in natural order.
    Author:
    Julian Hyde
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ArraySortedSet​(E[] values)
      Creates a set backed by an array.
      ArraySortedSet​(E[] values, int start, int end)
      Creates a set backed by a region of an array.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Comparator<? super E> comparator()  
      boolean contains​(java.lang.Object o)  
      E first()  
      java.util.SortedSet<E> headSet​(E toElement)  
      java.util.Iterator<E> iterator()  
      E last()  
      ArraySortedSet<E> merge​(ArraySortedSet<E> arrayToMerge)
      Performs a merge between two ArraySortedSet instances in O(n) time, returning a third instance that doesn't include duplicates.
      int size()  
      java.util.SortedSet<E> subSet​(E fromElement, E toElement)  
      java.util.SortedSet<E> tailSet​(E fromElement)  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] a)  
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        add, addAll, clear, containsAll, isEmpty, remove, retainAll, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        add, addAll, clear, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll
      • Methods inherited from interface java.util.SortedSet

        spliterator
    • Constructor Detail

      • ArraySortedSet

        public ArraySortedSet​(E[] values)
        Creates a set backed by an array. The array must be sorted, and is not copied.
        Parameters:
        values - Array of values
      • ArraySortedSet

        public ArraySortedSet​(E[] values,
                              int start,
                              int end)
        Creates a set backed by a region of an array. The array must be sorted, and is not copied.
        Parameters:
        values - Array of values
        start - Index of start of region
        end - Index of first element after end of region
    • Method Detail

      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E extends java.lang.Comparable<E>>
        Specified by:
        iterator in interface java.lang.Iterable<E extends java.lang.Comparable<E>>
        Specified by:
        iterator in interface java.util.Set<E extends java.lang.Comparable<E>>
        Specified by:
        iterator in class java.util.AbstractCollection<E extends java.lang.Comparable<E>>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E extends java.lang.Comparable<E>>
        Specified by:
        size in interface java.util.Set<E extends java.lang.Comparable<E>>
        Specified by:
        size in class java.util.AbstractCollection<E extends java.lang.Comparable<E>>
      • comparator

        public java.util.Comparator<? super E> comparator()
        Specified by:
        comparator in interface java.util.SortedSet<E extends java.lang.Comparable<E>>
      • subSet

        public java.util.SortedSet<E> subSet​(E fromElement,
                                             E toElement)
        Specified by:
        subSet in interface java.util.SortedSet<E extends java.lang.Comparable<E>>
      • headSet

        public java.util.SortedSet<E> headSet​(E toElement)
        Specified by:
        headSet in interface java.util.SortedSet<E extends java.lang.Comparable<E>>
      • tailSet

        public java.util.SortedSet<E> tailSet​(E fromElement)
        Specified by:
        tailSet in interface java.util.SortedSet<E extends java.lang.Comparable<E>>
      • first

        public E first()
        Specified by:
        first in interface java.util.SortedSet<E extends java.lang.Comparable<E>>
      • last

        public E last()
        Specified by:
        last in interface java.util.SortedSet<E extends java.lang.Comparable<E>>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<E extends java.lang.Comparable<E>>
        Specified by:
        toArray in interface java.util.Set<E extends java.lang.Comparable<E>>
        Overrides:
        toArray in class java.util.AbstractCollection<E extends java.lang.Comparable<E>>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface java.util.Collection<E extends java.lang.Comparable<E>>
        Specified by:
        toArray in interface java.util.Set<E extends java.lang.Comparable<E>>
        Overrides:
        toArray in class java.util.AbstractCollection<E extends java.lang.Comparable<E>>
      • merge

        public ArraySortedSet<E> merge​(ArraySortedSet<E> arrayToMerge)
        Performs a merge between two ArraySortedSet instances in O(n) time, returning a third instance that doesn't include duplicates.

        For example, ArraySortedSet("a", "b", "c").merge(ArraySortedSet("a", "c", "e")) returns ArraySortedSet("a", "b", "c", "e")}.

        Parameters:
        arrayToMerge - Other set to combine with this
        Returns:
        Set containing union of the elements of inputs
        See Also:
        Util.intersect(java.util.SortedSet, java.util.SortedSet)
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<E extends java.lang.Comparable<E>>
        Specified by:
        contains in interface java.util.Set<E extends java.lang.Comparable<E>>
        Overrides:
        contains in class java.util.AbstractCollection<E extends java.lang.Comparable<E>>