kodkod.util.ints
Class AbstractIntCollection

java.lang.Object
  extended by kodkod.util.ints.AbstractIntCollection
All Implemented Interfaces:
IntCollection
Direct Known Subclasses:
AbstractIntSet, AbstractIntVector

public abstract class AbstractIntCollection
extends java.lang.Object
implements IntCollection

A skeletal implementation of the IntCollection interface.

Author:
Emina Torlak

Method Summary
 boolean add(int i)
          Throws an UnsupportedOperationException.
 boolean addAll(IntCollection c)
          Adds all of the elements in the specified collection to this collection.
 void clear()
          This implementation iterates over this set, removing each element using the Iterator.remove operation.
 boolean contains(int i)
          Iterates through this.ints and returns true if it finds i, otherwise returns false.
 boolean containsAll(IntCollection c)
          Returns true if this collection contains all of the elements in the specified collection.
 boolean isEmpty()
          Returns true if this collection has no elements; otherwise returns false.
 boolean remove(int i)
          Iterates through the elements of this, removes i if it finds it and returns true.
 boolean removeAll(IntCollection c)
          Removes all of this collection's elements that are also contained in the specified collection.
 boolean retainAll(IntCollection c)
          Retains only the elements in this collection that are contained in the specified collection.
 int[] toArray()
          Returns the result of calling toArray(int[]) with a freshly constructed array of length this.size().
 int[] toArray(int[] array)
          Copies the elements of this collection into the specified array, provided that it is large enough, and returns it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface kodkod.util.ints.IntCollection
iterator, size
 

Method Detail

isEmpty

public boolean isEmpty()
Returns true if this collection has no elements; otherwise returns false.

Specified by:
isEmpty in interface IntCollection
Returns:
true if this collection has no elements, false otherwise.
See Also:
IntSet.isEmpty()

contains

public boolean contains(int i)
Iterates through this.ints and returns true if it finds i, otherwise returns false.

Specified by:
contains in interface IntCollection
Returns:
true if i is in this collection, otherwise returns false.

add

public boolean add(int i)
Throws an UnsupportedOperationException.

Specified by:
add in interface IntCollection
Returns:
true if this collection has changed as a result of the call
Throws:
java.lang.UnsupportedOperationException

remove

public boolean remove(int i)
Iterates through the elements of this, removes i if it finds it and returns true. Otherwise returns false. Throws an UnsupportedOperationException if this.iterator() does not support removal.

Specified by:
remove in interface IntCollection
Returns:
true if this collection has changed as a result of the call
Throws:
java.lang.UnsupportedOperationException - - this.iterator() does not support removal
effects:
iterates through the elements of this and removes i if it finds it

containsAll

public boolean containsAll(IntCollection c)
Returns true if this collection contains all of the elements in the specified collection.

Specified by:
containsAll in interface IntCollection
Returns:
true if this collection contains all of the elements in the specified collection.
See Also:
IntCollection.containsAll(kodkod.util.ints.IntCollection)

addAll

public boolean addAll(IntCollection c)
Adds all of the elements in the specified collection to this collection. Returns true if this collection has changed as a result of the call.

Specified by:
addAll in interface IntCollection
Returns:
true if this collection has changed as a result of the call
See Also:
IntCollection.addAll(kodkod.util.ints.IntCollection)

retainAll

public boolean retainAll(IntCollection c)
Retains only the elements in this collection that are contained in the specified collection. In other words, removes from this collection all of its elements that are not contained in the specified collection. Returns true if this collection has changed as a result of the call.

Specified by:
retainAll in interface IntCollection
Returns:
rue if this collection has changed as a result of the call
See Also:
IntCollection.retainAll(kodkod.util.ints.IntCollection)

removeAll

public boolean removeAll(IntCollection c)
Removes all of this collection's elements that are also contained in the specified collection. After this call returns, this collection will contain no elements in common with the specified collection. Returns true if this collection has changed as a result of the call.

Specified by:
removeAll in interface IntCollection
Returns:
true if this collection has changed as a result of the call
See Also:
IntCollection.removeAll(kodkod.util.ints.IntCollection)

clear

public void clear()
This implementation iterates over this set, removing each element using the Iterator.remove operation. Most implementations will probably choose to override this method for efficiency.

Note that this implementation will throw an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection is non-empty.

Specified by:
clear in interface IntCollection
Throws:
java.lang.UnsupportedOperationException - if the clear method is not supported by this collection.

toArray

public int[] toArray()
Returns the result of calling toArray(int[]) with a freshly constructed array of length this.size().

Specified by:
toArray in interface IntCollection
Returns:
this.toArray(new int[size()])
See Also:
IntCollection.toArray()

toArray

public int[] toArray(int[] array)
Copies the elements of this collection into the specified array, provided that it is large enough, and returns it. If the array is not large enough, the effect of this method is the same as calling IntCollection.toArray().

Specified by:
toArray in interface IntCollection
Returns:
the given array, filled with the elements from this collection, if the it is large enough; otherwise a new array containing all of the elements in this collection.
See Also:
IntCollection.toArray(int[])