public class

ShapeSet

extends Object
implements Set<E>
java.lang.Object
   ↳ sofia.graphics.ShapeSet<ShapeType extends sofia.graphics.Shape>
Known Direct Subclasses

Class Overview

Represents a collection of Shape objects held in drawing order, based on z-index.

This class merely represents a generic, ordered collection of shapes; it provides no physical simulation or collision detection. Refer to the ShapeField class, which provides this added behavior.

Summary

Public Constructors
ShapeSet()
Constructs a new, empty shape set, sorted by their drawing order.
Public Methods
boolean add(ShapeType shape)
Adds the specified shape to this set if it is not already present.
boolean addAll(Collection<? extends ShapeType> collection)
Adds all of the shapes in the specified collection to this set if they're not already present.
ShapeType back()
Gets the backmost shape in the shape set.
void clear()
Removes all of the shapes from this set.
boolean contains(Object object)
Returns true if this set contains the specified shape.
boolean containsAll(Collection<?> collection)
Returns true if this set contains all of the shapes of the specified collection.
boolean equals(Object other)
Compares the specified object with this set for equality.
ShapeType front()
Gets the frontmost shape in the shape set.
Iterator<ShapeType> frontToBackIterator()
Access an iterator that traverses the collection from "front" (top) to "back" (bottom) in terms of drawing order.
ZIndexComparator getDrawingOrder()
Get the shape order for this shape set.
int hashCode()
Returns the hash code value for this set.
boolean isEmpty()
Returns true if this set contains no shapes.
boolean isInFrontOf(Shape left, Shape right)
Returns true if the left shape is drawn in front of (later than) the shape on the right.
Iterator<ShapeType> iterator()
Returns an iterator over the shapes in this set.
boolean remove(Object object)
Removes the specified shape from this set if it is present.
boolean removeAll(Collection<?> collection)
Removes from this set all of its shapes that are contained in the specified collection.
boolean retainAll(Collection<?> collection)
Retains only the shapes in this set that are contained in the specified collection.
void setDrawingOrder(ZIndexComparator order)
Change the shape order for this shape set.
int size()
Returns the number of shapes in this set (its cardinality).
<T> T[] toArray(T[] array)

Returns an array containing all of the shapes in this set; the runtime type of the returned array is that of the specified array.

Shape[] toArray()
Returns an array containing all of the shapes in this set.
Protected Methods
TreeSet<ShapeType> rawSet()
Gets the TreeSet underlying this shape set.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Iterable
From interface java.util.Collection
From interface java.util.Set

Public Constructors

public ShapeSet ()

Constructs a new, empty shape set, sorted by their drawing order.

Public Methods

public boolean add (ShapeType shape)

Adds the specified shape to this set if it is not already present.

Parameters
shape the shape to be added to this set
Returns
  • true if this set did not already contain the specified shape

public boolean addAll (Collection<? extends ShapeType> collection)

Adds all of the shapes in the specified collection to this set if they're not already present.

Parameters
collection the collection containing shapes to be added to this set
Returns
  • true if the set changed as a result of this operation

public ShapeType back ()

Gets the backmost shape in the shape set. This is the shape that has the lowest z-index, or if multiple shapes have the same z-index, the one that was added least recently to its field.

Returns
  • the backmost shape in the set, or null if the set is empty

public void clear ()

Removes all of the shapes from this set. The set will be empty after this call returns.

public boolean contains (Object object)

Returns true if this set contains the specified shape.

Parameters
object the shape whose presence in this set is to be tested
Returns
  • true if this set contains the specified shape

public boolean containsAll (Collection<?> collection)

Returns true if this set contains all of the shapes of the specified collection.

Parameters
collection the collection to be checked for containment in this set
Returns
  • true if this set contains all of the shapes of the specified collection

public boolean equals (Object other)

Compares the specified object with this set for equality.

Parameters
other the object to be compared for equality with this set
Returns
  • true if the specified object is equal to this set

public ShapeType front ()

Gets the frontmost shape in the shape set. This is the shape that has the highest z-index, or if multiple shapes have the same z-index, the one that was added most recently to its field.

Returns
  • the frontmost shape in the set, or null if the set is empty

public Iterator<ShapeType> frontToBackIterator ()

Access an iterator that traverses the collection from "front" (top) to "back" (bottom) in terms of drawing order.

Returns
  • An iterator representing this traversal order.

public ZIndexComparator getDrawingOrder ()

Get the shape order for this shape set.

Returns
  • The current shape ordering, in the form of a comparator

public int hashCode ()

Returns the hash code value for this set.

Returns
  • the hash code value for this set

public boolean isEmpty ()

Returns true if this set contains no shapes.

Returns
  • true if this set contains no shapes

public boolean isInFrontOf (Shape left, Shape right)

Returns true if the left shape is drawn in front of (later than) the shape on the right.

Parameters
left the shape to check
right the shape to check against
Returns
  • true if left is drawn above (later than) right

public Iterator<ShapeType> iterator ()

Returns an iterator over the shapes in this set. The shapes are returned in order from farthest back (lowest z-index) to farthest forward (highest z-index).

Returns
  • an iterator over the shapes in this set

public boolean remove (Object object)

Removes the specified shape from this set if it is present.

Parameters
object the shape to be removed from this set, if present
Returns
  • true if this set contained the specified shape

public boolean removeAll (Collection<?> collection)

Removes from this set all of its shapes that are contained in the specified collection.

Parameters
collection the collection containing shapes to be removed from this set
Returns
  • true if this set changed as a result of the call

public boolean retainAll (Collection<?> collection)

Retains only the shapes in this set that are contained in the specified collection. In other words, removes from this set all of its shapes that are not contained in the specified collection.

Parameters
collection the collection containing shapes to be retained in this set
Returns
  • true if this set changed as a result of the call

public void setDrawingOrder (ZIndexComparator order)

Change the shape order for this shape set.

Parameters
order the new ordering to use

public int size ()

Returns the number of shapes in this set (its cardinality).

Returns
  • the number of shapes in this set (its cardinality)

public T[] toArray (T[] array)

Returns an array containing all of the shapes in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set.

If this set fits in the specified array with room to spare (i.e., the array has more elements than this set), the element in the array immediately following the end of the set is set to null. (This is useful in determining the length of this set only if the caller knows that this set does not contain any null elements.)

The shapes are returned in order from farthest back (lowest z-index) to farthest forward (highest z-index).

Parameters
array the array into which the shapes of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.

public Shape[] toArray ()

Returns an array containing all of the shapes in this set. The shapes are returned in order from farthest back (lowest z-index) to farthest forward (highest z-index).

Protected Methods

protected TreeSet<ShapeType> rawSet ()

Gets the TreeSet underlying this shape set.

Returns
  • the TreeSet underlying this shape set