viper.descriptors
Class DescVector

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byjava.util.Vector
              extended byviper.descriptors.DescVector
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, DescriptorList, java.util.List, java.util.RandomAccess, java.io.Serializable
Direct Known Subclasses:
DescriptorConfigs

public class DescVector
extends java.util.Vector
implements DescriptorList

A collection of Descriptor Objects that supports various operations on them, such as comparison between to DescVector, collection of statistics, reading and printing from files, and various others. It extends Vector now, but could be made to extend some sorted list object without too much hassle.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
DescVector(DescriptorData parent)
          Constructs an empty list of descriptors with the given parent data holder.
DescVector(int initialCapacity, DescriptorData parent)
          Constructs an empty list of descriptors with the given parent data holder.
 
Method Summary
 void addDescriptor(Descriptor desc)
          Adds a new descriptor to this set.
 java.util.Iterator cropNodesToSpan(FrameSpan span)
          Like getNodesByFrame, but instead, the Iterator returns copies of the Descriptor objects contained here, each cropped to contain no frames beyond the specified FrameSpan.
 java.util.Collection getAllDescriptors()
          Get a collection of all of the descriptors declared for this source file.
 CanonicalFileDescriptor getFileInformation()
          Gets file information.
 int getHighestFrame()
          Returns the greatest frame index of all Descriptor objects.
 java.util.List getIds()
          Gets a flattened list of all ids.
 java.lang.String getInformation()
          Gets the source media file information.
 int getLowestFrame()
          Returns the least frame index of all Descriptor objects.
 Equivalencies getMap()
          Gets the map of the parent DescriptorData that holds the information for this sourcefile.
 Descriptor getNodeByID(java.lang.String type, java.lang.String name, int idNumber)
          Returns the Descriptor with the given id number and type.
 java.util.Iterator getNodesByFrame(FrameSpan span)
          Returns descriptors that contain the subspan, or some of the subspan, with their framespan set to the subspan intersected with the span.
 java.util.Iterator getNodesByID(int idNumber)
          Returns all Descriptors with the given id number.
 java.util.Iterator getNodesByType(java.lang.String type, java.lang.String name)
          Returns the first Descriptor in the list with the specified category and title.
 java.util.Iterator getNodesByType(java.lang.String type, java.lang.String name, Equivalencies map)
          Returns the first Descriptor in the list with the specified category and title.
 DescriptorData getParent()
          Gets the parent set of descriptor lists.
 java.lang.String getSourcefileName()
          Gets the name of the file this metadata describes.
 org.w3c.dom.Element getXMLFormat(org.w3c.dom.Document root)
          Returns a sourcefile tag with lots of children.
 boolean hasDescriptor(java.lang.String type, java.lang.String name)
          Checks to see if a Descriptor with this category and title is in the list.
 void parseData(org.w3c.dom.Element source, RuleHolder limits)
          Reads in the given data in xml format.
 void parseData(java.util.List allFiles, RuleHolder limits)
          Reads in Descriptor data from the specified list of files with the specified config info.
 void parseData(java.util.List allFiles, RuleHolder limits, boolean all, boolean err, boolean warn, boolean bad, boolean totals)
          Reads in Descriptor data from the specified list of files with the specified config info.
protected  void parseData(VReader reader, RuleHolder limits)
           
 void printOut(java.io.PrintWriter output)
          Prints the data out to a file in the specified format.
 void setFileInformation(CanonicalFileDescriptor cfd)
          Will try to set the canonical file descriptor.
 void setMap(Equivalencies map)
          Sets the map of the parent DescriptorData that holds the information for this sourcefile.
 void setSourcefileName(java.lang.String S)
          Sets the source file name.
 java.lang.String toString()
          Prints the data in .gtf format, header and footer included.
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, 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 viper.descriptors.DescriptorList
clone, get, size
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Constructor Detail

DescVector

public DescVector(DescriptorData parent)
Constructs an empty list of descriptors with the given parent data holder.

Parameters:
parent - the data holder that will contain this. You will have to add this to the holder manually.

DescVector

public DescVector(int initialCapacity,
                  DescriptorData parent)
Constructs an empty list of descriptors with the given parent data holder.

Parameters:
parent - the data holder that will contain this. You will have to add this to the holder manually.
initialCapacity - the initial vector capacity
Method Detail

getSourcefileName

public java.lang.String getSourcefileName()
Gets the name of the file this metadata describes.

Returns:
the source file name

setSourcefileName

public void setSourcefileName(java.lang.String S)
Sets the source file name.

Parameters:
S - the name of the file this set of metadata describes

getAllDescriptors

public java.util.Collection getAllDescriptors()
Description copied from interface: DescriptorList
Get a collection of all of the descriptors declared for this source file.

Specified by:
getAllDescriptors in interface DescriptorList
Returns:
Collectionof Descriptors

getMap

public Equivalencies getMap()
Gets the map of the parent DescriptorData that holds the information for this sourcefile.

Specified by:
getMap in interface DescriptorList
Returns:
the equivalency map of the list.
See Also:
DescriptorList.getMap()

setMap

public void setMap(Equivalencies map)
Sets the map of the parent DescriptorData that holds the information for this sourcefile.

Specified by:
setMap in interface DescriptorList
Parameters:
map - the new equivalency map of the list.
See Also:
DescriptorList.setMap(Equivalencies)

parseData

public void parseData(java.util.List allFiles,
                      RuleHolder limits)
Reads in Descriptor data from the specified list of files with the specified config info.

Parameters:
allFiles - a Vector of Strings containing the names of the files to search for config information
limits - a set of rules that are checked. Descriptors that don't pass the limits are not parsed.

parseData

public void parseData(java.util.List allFiles,
                      RuleHolder limits,
                      boolean all,
                      boolean err,
                      boolean warn,
                      boolean bad,
                      boolean totals)
Reads in Descriptor data from the specified list of files with the specified config info.

Parameters:
allFiles - a Vector of Strings containing the names of the files to search for config information
limits - a set of rules that are checked. Descriptors that don't pass the limits are not parsed.
all - print out all data-containing lines of the parsed file
err - print out all error messages
warn - print out all warning messages
bad - print out the bad line in addition to the message and line number
totals - print out total number of errors/warnings/etc.

parseData

protected void parseData(VReader reader,
                         RuleHolder limits)
Parameters:
reader - uses the VReader at its current place. Note that this method closes the reader at the end.
limits - only parse in descriptors that meet these rules. If null, then no rules are applied.

parseData

public void parseData(org.w3c.dom.Element source,
                      RuleHolder limits)
Reads in the given data in xml format.

Parameters:
source - the source DOM node
limits - information about what not to read

hasDescriptor

public boolean hasDescriptor(java.lang.String type,
                             java.lang.String name)
Checks to see if a Descriptor with this category and title is in the list.

Specified by:
hasDescriptor in interface DescriptorList
Parameters:
type - the category of the Descriptor
name - the name of the Descriptor
Returns:
true if one or more are found

getNodesByType

public java.util.Iterator getNodesByType(java.lang.String type,
                                         java.lang.String name)
Returns the first Descriptor in the list with the specified category and title. Returns null if none is found.

Specified by:
getNodesByType in interface DescriptorList
Parameters:
type - the category of the Descriptor
name - the name of the Descriptor
Returns:
a Descriptor with the specified type and title
See Also:
DescriptorList.getNodesByType(String, String)

getNodesByType

public java.util.Iterator getNodesByType(java.lang.String type,
                                         java.lang.String name,
                                         Equivalencies map)
Returns the first Descriptor in the list with the specified category and title. Returns null if none is found.

Parameters:
type - the category of the Descriptor
name - the name of the Descriptor
map - Equivalencies to use while searching
Returns:
a Descriptor with the specified type and title

getNodeByID

public Descriptor getNodeByID(java.lang.String type,
                              java.lang.String name,
                              int idNumber)
Description copied from interface: DescriptorList
Returns the Descriptor with the given id number and type.

Specified by:
getNodeByID in interface DescriptorList
Parameters:
type - the type of the descriptor
name - the name of the descriptor
idNumber - the id number of the descriptor
Returns:
the descriptor, if it exists. Otherwise, null.

getIds

public java.util.List getIds()
Gets a flattened list of all ids. Flattened because DescAggregates have lists of IDs. May contain duplicates if this contains prototypes (all ids are 0) or if it was put together improperly.

Specified by:
getIds in interface DescriptorList
Returns:
a flattened list of all ids.

cropNodesToSpan

public java.util.Iterator cropNodesToSpan(FrameSpan span)
Description copied from interface: DescriptorList
Like getNodesByFrame, but instead, the Iterator returns copies of the Descriptor objects contained here, each cropped to contain no frames beyond the specified FrameSpan.

Specified by:
cropNodesToSpan in interface DescriptorList
Parameters:
span - the span to get values cropped to
Returns:
cropped copies of the descriptors in the span

getNodesByFrame

public java.util.Iterator getNodesByFrame(FrameSpan span)
Description copied from interface: DescriptorList
Returns descriptors that contain the subspan, or some of the subspan, with their framespan set to the subspan intersected with the span.

Specified by:
getNodesByFrame in interface DescriptorList
Parameters:
span - the span to check
Returns:
all descriptors that intersect with the span

getNodesByID

public java.util.Iterator getNodesByID(int idNumber)
Description copied from interface: DescriptorList
Returns all Descriptors with the given id number.

Specified by:
getNodesByID in interface DescriptorList
Parameters:
idNumber - the number to look for
Returns:
the descriptors with the given id. Note that there can only be one of each declared descriptor type

getHighestFrame

public int getHighestFrame()
Returns the greatest frame index of all Descriptor objects.

Specified by:
getHighestFrame in interface DescriptorList
Returns:
the last frame index of all Descriptor objects. Will return -1 if there are no frames.

getLowestFrame

public int getLowestFrame()
Returns the least frame index of all Descriptor objects.

Specified by:
getLowestFrame in interface DescriptorList
Returns:
the first frame index of all Descriptor objects Will return -1 if there are no frames.

printOut

public void printOut(java.io.PrintWriter output)
Prints the data out to a file in the specified format.

Parameters:
output - - the PrintWriter to hand the data

toString

public java.lang.String toString()
Prints the data in .gtf format, header and footer included.

Returns:

getInformation

public java.lang.String getInformation()
Gets the source media file information.

Returns:
the source media file information

getXMLFormat

public org.w3c.dom.Element getXMLFormat(org.w3c.dom.Document root)
Returns a sourcefile tag with lots of children. Note that there is no filename in the sourcefile tag, as the vector doesn't know about it. FIXME: Perhaps it should...

Specified by:
getXMLFormat in interface DescriptorList
Parameters:
root - The DOM root
Returns:
<sourcefile> element, with descriptor children

addDescriptor

public void addDescriptor(Descriptor desc)
                   throws java.lang.UnsupportedOperationException
Description copied from interface: DescriptorList
Adds a new descriptor to this set. Unlike a simple call to add, this will reset the object ID to be unique to this list.

Specified by:
addDescriptor in interface DescriptorList
Parameters:
desc - the descriptor to add
Throws:
java.lang.UnsupportedOperationException

getFileInformation

public CanonicalFileDescriptor getFileInformation()
Gets file information. See all of the caveats therein -- it may be null, or it may not have any useful values.

Specified by:
getFileInformation in interface DescriptorList
Returns:
the canonical file descriptor associated with this metadata
See Also:
DescriptorList.getFileInformation()

setFileInformation

public void setFileInformation(CanonicalFileDescriptor cfd)
Will try to set the canonical file descriptor. Note that any attributes that are not in the prototype that was parsed from file (or added later) should not be set. The policy on how to treat the SOURCEFILES attribute may be implementation dependent (use it for ordering, although it may also be used to remove files if you wish).

Specified by:
setFileInformation in interface DescriptorList
Parameters:
cfd - the new canonical file descriptor
See Also:
DescriptorList.setFileInformation(CanonicalFileDescriptor)

getParent

public DescriptorData getParent()
Description copied from interface: DescriptorList
Gets the parent set of descriptor lists.

Specified by:
getParent in interface DescriptorList
Returns:
the parent holder