maspack.render
Class SortedRenderableList

java.lang.Object
  extended by maspack.render.SortedRenderableList
All Implemented Interfaces:
java.lang.Iterable<GLRenderable>, java.util.Collection<GLRenderable>

public class SortedRenderableList
extends java.lang.Object
implements java.util.Collection<GLRenderable>

Set of renderables sorted by zOrder. This is very similar to what would be a SortedSet, except I do no checks to ensure elements are distinct according to compareTo(...) with respect to zOrder. In fact, most elements will have the same zOrder=0, in which case they are sorted according to the original order they were added to the list (stable sort). Unlike List, order is not guaranteed.

The zOrder is read from render properties if the GLRenderable is an instance of HasRenderProps. Otherwise, a zOrder can be specified in add(GLRenderable,int), or is assumed to be 0.

Author:
Antonio

Field Summary
static int defaultCapacity
           
static int defaultIncrement
           
 
Constructor Summary
SortedRenderableList()
          Constructs an empty list with an initial capacity of ten.
SortedRenderableList(java.util.Collection<? extends GLRenderable> c)
          Constructs a set containing the elements of the specified collection.
SortedRenderableList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
 
Method Summary
 boolean add(GLRenderable e)
          Adds an element to this set, sorted ascending by the zOrder parameter if exists (otherwise assumed zOrder = 0).
 boolean add(GLRenderable e, int zOrder)
          Adds an element to this set, sorted ascending by the zOrder parameter if exists.
 boolean addAll(java.util.Collection<? extends GLRenderable> c)
          Adds all elements in c to this set.
 void clear()
          Clears all elements from this set
 boolean contains(java.lang.Object o)
          Determines whether the set contains a specified object
 boolean containsAll(java.util.Collection<?> c)
          Returns true if this set contains all elements in the supplied collection
 GLRenderable first()
          Gets the first element in the set
 GLRenderable get(int index)
           
 boolean isEmpty()
          Returns true if set is empty
 java.util.Iterator<GLRenderable> iterator()
          Returns an iterator for looping through elements
 GLRenderable last()
          Gets the last element in the set
 int numSelectionQueriesNeeded()
          Returns the maximum number of selection queries required for all renderables in this list.
 GLRenderable remove(int idx)
           
 boolean remove(java.lang.Object o)
          Removes an element from this set
 boolean removeAll(java.util.Collection<?> c)
          Removes all elements in this set that are found in c.
 boolean retainAll(java.util.Collection<?> c)
          Retains only the elements that are also found in the collection c, essentially performing an intersection.
 void setIncrement(int inc)
          Sets the size to grow the array when we read capacity
 int size()
          Returns the number of elements in the set
 GLRenderable[] toArray()
          Returns a copy of the GLRenderable array
<T> T[]
toArray(T[] a)
          Fills an array with the current sorted GLRenderables.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Field Detail

defaultCapacity

public static int defaultCapacity

defaultIncrement

public static int defaultIncrement
Constructor Detail

SortedRenderableList

public SortedRenderableList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list

SortedRenderableList

public SortedRenderableList()
Constructs an empty list with an initial capacity of ten.


SortedRenderableList

public SortedRenderableList(java.util.Collection<? extends GLRenderable> c)
Constructs a set containing the elements of the specified collection.

Parameters:
c - the collection whose elements are to be placed into this list
Throws:
java.lang.NullPointerException - if the specified collection is null
Method Detail

numSelectionQueriesNeeded

public int numSelectionQueriesNeeded()
Returns the maximum number of selection queries required for all renderables in this list. This number is needed by viewer-based selection software.


setIncrement

public void setIncrement(int inc)
Sets the size to grow the array when we read capacity

Parameters:
inc -

size

public int size()
Returns the number of elements in the set

Specified by:
size in interface java.util.Collection<GLRenderable>

isEmpty

public boolean isEmpty()
Returns true if set is empty

Specified by:
isEmpty in interface java.util.Collection<GLRenderable>

contains

public boolean contains(java.lang.Object o)
Determines whether the set contains a specified object

Specified by:
contains in interface java.util.Collection<GLRenderable>

iterator

public java.util.Iterator<GLRenderable> iterator()
Returns an iterator for looping through elements

Specified by:
iterator in interface java.lang.Iterable<GLRenderable>
Specified by:
iterator in interface java.util.Collection<GLRenderable>

toArray

public GLRenderable[] toArray()
Returns a copy of the GLRenderable array

Specified by:
toArray in interface java.util.Collection<GLRenderable>

toArray

public <T> T[] toArray(T[] a)
Fills an array with the current sorted GLRenderables. A new array is created if 'a' is too small.

Specified by:
toArray in interface java.util.Collection<GLRenderable>
Parameters:
a -

add

public boolean add(GLRenderable e)
Adds an element to this set, sorted ascending by the zOrder parameter if exists (otherwise assumed zOrder = 0). For equal zOrders, the original order is maintained (stable sort).

Specified by:
add in interface java.util.Collection<GLRenderable>

add

public boolean add(GLRenderable e,
                   int zOrder)
Adds an element to this set, sorted ascending by the zOrder parameter if exists. For equal zOrders, the original order is maintained (stable sort).


remove

public boolean remove(java.lang.Object o)
Removes an element from this set

Specified by:
remove in interface java.util.Collection<GLRenderable>

remove

public GLRenderable remove(int idx)

containsAll

public boolean containsAll(java.util.Collection<?> c)
Returns true if this set contains all elements in the supplied collection

Specified by:
containsAll in interface java.util.Collection<GLRenderable>

addAll

public boolean addAll(java.util.Collection<? extends GLRenderable> c)
Adds all elements in c to this set. Always returns true;

Specified by:
addAll in interface java.util.Collection<GLRenderable>

retainAll

public boolean retainAll(java.util.Collection<?> c)
Retains only the elements that are also found in the collection c, essentially performing an intersection. Returns true if the collection is modified

Specified by:
retainAll in interface java.util.Collection<GLRenderable>

removeAll

public boolean removeAll(java.util.Collection<?> c)
Removes all elements in this set that are found in c. Returns true if the set is modified.

Specified by:
removeAll in interface java.util.Collection<GLRenderable>

clear

public void clear()
Clears all elements from this set

Specified by:
clear in interface java.util.Collection<GLRenderable>

first

public GLRenderable first()
Gets the first element in the set


last

public GLRenderable last()
Gets the last element in the set


get

public GLRenderable get(int index)