agentland.device.intelliCD
Class SongContainer

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--agentland.device.intelliCD.SongContainer
All Implemented Interfaces:
Cloneable, Collection, List, Serializable, SongContainerElement
Direct Known Subclasses:
SCollection, SongList

public class SongContainer
extends Vector
implements SongContainerElement

A song container can hold songs or it can hold nested SongContainers. This is subclassed from Vector so that it can handle the List and Collection methods natively, but still have all the methods synchronized. Additional methods are defined to make accessing elements slightly easier. Try to use the List methods whenever possible.

To make things more straightforward, SongContainers maintain the parents of their children. When an element is added to the container, the parent of the item should be set.

See Also:
Serializable, SongContainerElement, Serialized Form

Field Summary
protected  String author
           
protected  long id
           
protected  SongContainer parent
           
protected  String title
           
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SongContainer()
           
SongContainer(SongContainer sc)
          Creates a new song container by copying the contents of an existing container.
SongContainer(String t, String a, long id)
          Creates a new empty song container with the given parameters.
 
Method Summary
 void add(int i, SongContainerElement el)
          Inserts an element at the given index.
 void add(SongContainerElement el)
           
 void addFromContainer(SongContainer sc)
          Load all the stuff in the song container into the object.
protected  SongContainer copyParent(SongContainer parent, SongContainerElement childCopy)
           
 SongContainerElement copyParentTree()
          Creates a cheap-and-dirty copy of the song container and its parents.
 SongContainerElement copySubtree()
          Make a copy of the element and all elements below it.
 boolean equals(Object obj)
           
 String getAuthor()
           
 SongContainerElement getElement(SongContainerElement elt)
          Returns the object specified by the given element (possibly a placeholder).
 long getID()
           
 String getName()
           
 SongContainer getParent()
           
 SongContainerElement getSCE(int i)
          Gets the element at the given index.
 List getSongsRecursive()
          Returns all songs in the container (even from nested SongContainers)
 String getTitle()
           
 int hashCode()
           
 String iconName()
           
protected  void init()
           
 SongContainerElement lightweightCopy()
          Creates a very lightweight copy of this object.
 SongContainerElement lookup(SongContainerElement sce)
           
 SongContainer lookupContainer(long l)
          Lookup a container given an ID.
 SongContainer lookupContainer(SongContainer sc)
          Look up a song container given an ID.
 Song lookupSong(Song s)
          Look up a song given an ID.
 void printWithPrefix(String prefix)
           
 Object remove(int i)
          Returns a copy of the element at index i, then removes the element from the container.
 void set(int i, SongContainerElement el)
          Adds an element at the given index.
 void setAuthor(String a)
           
protected  void setID(long l)
           
 void setParent(SongContainer elt)
           
 void setTitle(String t)
           
protected  SongContainerElement shallowCopy(boolean copyKids)
          Creates a cheap-and-dirty copy of the song container and its parents.
 String toString()
           
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, firstElement, get, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

title

protected String title

author

protected String author

id

protected long id

parent

protected SongContainer parent
Constructor Detail

SongContainer

public SongContainer()

SongContainer

public SongContainer(String t,
                     String a,
                     long id)
Creates a new empty song container with the given parameters.
Parameters:
t - the title for the new container.
a - the author name for the new container.
id - the new identification value.

SongContainer

public SongContainer(SongContainer sc)
Creates a new song container by copying the contents of an existing container.
Parameters:
sc - the container to be copied.
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class Vector

init

protected void init()

setParent

public void setParent(SongContainer elt)
Specified by:
setParent in interface SongContainerElement

getParent

public SongContainer getParent()
Specified by:
getParent in interface SongContainerElement

getTitle

public String getTitle()

setTitle

public void setTitle(String t)

getAuthor

public String getAuthor()

setAuthor

public void setAuthor(String a)

getID

public long getID()
Specified by:
getID in interface SongContainerElement

setID

protected void setID(long l)

equals

public boolean equals(Object obj)
Overrides:
equals in class Vector

toString

public String toString()
Overrides:
toString in class Vector

getName

public String getName()
Specified by:
getName in interface SongContainerElement

set

public void set(int i,
                SongContainerElement el)
Adds an element at the given index. Unlike the superclass, this will pad the container with nulls if the index is greater than the current container size.
See Also:
Vector.set(int, java.lang.Object)

add

public void add(int i,
                SongContainerElement el)
Inserts an element at the given index. Unlike the superclass, this will pad the container with nulls if the index is greater than the current container size.
See Also:
Vector.add(int,Object)

add

public void add(SongContainerElement el)

remove

public Object remove(int i)
Returns a copy of the element at index i, then removes the element from the container.
Overrides:
remove in class Vector
Parameters:
i - the index of the element to be removed.
Returns:
the object removed.

getSCE

public SongContainerElement getSCE(int i)
Gets the element at the given index. Unlike the get method, this will return null if the index is out of bounds. This will also return a SongContainerElement for the convenience of the caller.
See Also:
Vector.get(int)

lookupSong

public Song lookupSong(Song s)
Look up a song given an ID. This method exists so that a song `placeholder' consisting only of an ID can get the full details from the container. This is slow, but can be overridden to make it faster.

lookupContainer

public SongContainer lookupContainer(SongContainer sc)
Look up a song container given an ID. This method exists so that a container `placeholder' consisting only of an ID can get the full details from the container.

lookupContainer

public SongContainer lookupContainer(long l)
Lookup a container given an ID. This is slow, but can be overridden by subclasses to make this lookup faster.

lookup

public SongContainerElement lookup(SongContainerElement sce)

getSongsRecursive

public List getSongsRecursive()
Returns all songs in the container (even from nested SongContainers)

getElement

public SongContainerElement getElement(SongContainerElement elt)
Returns the object specified by the given element (possibly a placeholder). Also searches nested subcollections. If no such element exists, this will return null.

printWithPrefix

public void printWithPrefix(String prefix)

addFromContainer

public void addFromContainer(SongContainer sc)
Load all the stuff in the song container into the object. This is different from add in that it adds the contents of the container, not the container itself.
Parameters:
sc - the container whose elements will be added. # @see #addElement

lightweightCopy

public SongContainerElement lightweightCopy()
Creates a very lightweight copy of this object. Suitable for matching with equals(), but not for much else.
Specified by:
lightweightCopy in interface SongContainerElement

copyParentTree

public SongContainerElement copyParentTree()
Creates a cheap-and-dirty copy of the song container and its parents. This is suitable for network transfer of changes. For merging changes to subtrees, children of this song container are also copied, but not the children of the parent containers.
Specified by:
copyParentTree in interface SongContainerElement

shallowCopy

protected SongContainerElement shallowCopy(boolean copyKids)
Creates a cheap-and-dirty copy of the song container and its parents. This is suitable for network transfer of changes. The copyKids flag is used to copy children if appropriate.

copyParent

protected SongContainer copyParent(SongContainer parent,
                                   SongContainerElement childCopy)

copySubtree

public SongContainerElement copySubtree()
Make a copy of the element and all elements below it. The subtree copy should have all parent references in place.
Specified by:
copySubtree in interface SongContainerElement
Returns:
a SongContainerElement value

iconName

public String iconName()
Specified by:
iconName in interface SongContainerElement