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

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

public class LazySetIntersection<E>
extends AbstractSet<E>

Represents a Set view for common elements of two sets. The intersection is backed by the input sets, so changes to any of the sets are reflected in the intersection. The main purpose of the class is to facilitate iteration over intersection of sets without computing the intersection explicitly. Iteration over the intersection is organized by iterating over the elements in the smallest set and checking if the elements are present in the other set. An element is contained in the intersection as reported by contains if it is contained in all input sets. The size of the intersection reported by size is the minimum 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 intersection is in progress, the results of the iteration are undefined. The set intersection does not support additions or removal of elements; if attempted, an UnsupportedOperationException will be thrown.

Author:
Yevgeny Kazakov
See Also:
LazySetUnion

Constructor Summary
LazySetIntersection(Set<E> firstSet, Set<E> secondSet)
          Returns a new Set view for intersection 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

LazySetIntersection

public LazySetIntersection(Set<E> firstSet,
                           Set<E> secondSet)
Returns a new Set view for intersection of two input sets.

Parameters:
firstSet - the first set of the intersection
secondSet - the second set of the intersection
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.