org.semanticweb.elk.util.collections
Class LazySetUnion<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by org.semanticweb.elk.util.collections.LazySetUnion<E>
Type Parameters:
E - the type of the elements in this set
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>

public class LazySetUnion<E>
extends AbstractSet<E>

Represents a Set view for the union of elements of two sets. The resulted set is backed by the input sets, so changes to any of the sets are reflected in the union. The main purpose of the class is to facilitate iteration and checking the membership over union of sets without computing the set explicitly (and thus potentially saving memory). When iterating over the union, the common elements of the two sets are iterated only once. An element is contained in the union as reported by contains if it is contained in one of the input sets. The size of the union reported by size is the sum of the sizes for the sets. This way it is possible to use the result to build other LazySetIntersection and LazySetUnion objects. If any of the sets is modified while an iteration over the union is in progress, the results of the iteration are undefined. The set union does not support additions or removal of elements; if attempted, an UnsupportedOperationException will be thrown.

Author:
Yevgeny Kazakov
See Also:
LazySetIntersection

Constructor Summary
LazySetUnion(Set<? extends E> firstSet, Set<? extends E> secondSet)
          Returns a new Set view for union of two input sets.
 
Method Summary
 boolean contains(Object o)
           
 boolean isEmpty()
           
 Iterator<E> iterator()
           
 boolean remove(Object o)
           
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, containsAll, retainAll, toArray, toArray
 

Constructor Detail

LazySetUnion

public LazySetUnion(Set<? extends E> firstSet,
                    Set<? extends E> secondSet)
Returns a new Set view for union of two input sets.

Parameters:
firstSet - the first set of the union
secondSet - the second set of the union
Method Detail

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Set<E>
Specified by:
iterator in class AbstractCollection<E>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface Set<E>
Overrides:
contains in class AbstractCollection<E>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface Set<E>
Overrides:
remove in class AbstractCollection<E>

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface Set<E>
Specified by:
size in class AbstractCollection<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface Set<E>
Overrides:
isEmpty in class AbstractCollection<E>


Copyright © 2011-2013 Department of Computer Science, University of Oxford. All Rights Reserved.