de.sciss.io
Class Marker

java.lang.Object
  extended by de.sciss.io.Marker
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

public class Marker
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

A struct class: marker in an audio file. (copied from FScape).

Version:
0.23, 25-Feb-08
Author:
Hanns Holger Rutz
See Also:
AudioFileDescr.KEY_MARKERS, Serialized Form

Field Summary
 java.lang.String name
          A marker's name
static java.util.Comparator nameComparator
          A Comparator which can be used to sort a list of markers according to the markers' names.
 long pos
          A marker's position in sample frames
 
Constructor Summary
Marker(long pos, java.lang.String name)
          Constructs a new immutable marker
Marker(Marker orig)
          Constructs a new immutable marker identical to a given marker.
 
Method Summary
static int add(java.util.List markers, Marker marker)
          Adds marker chronologically to a pre-sorted list.
 java.lang.Object clone()
          Returns a new marker which is equal to this one.
 int compareTo(java.lang.Object o)
          Implementation of the Comparable interface.
 boolean equals(java.lang.Object o)
           
static int find(java.util.List markers, java.lang.String name, int startIndex)
          Gets the index for specific marker in a list.
 int hashCode()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nameComparator

public static final java.util.Comparator nameComparator
A Comparator which can be used to sort a list of markers according to the markers' names. Note that to sort markers according to their position, you can use the natural ordering of the markers as defined by the Comparable interface.

See Also:
Collections.sort( List ), Collections.sort( List, Comparator )

pos

public final long pos
A marker's position in sample frames


name

public final java.lang.String name
A marker's name

Constructor Detail

Marker

public Marker(long pos,
              java.lang.String name)
Constructs a new immutable marker

Parameters:
pos - position in sample frames
name - marker's name

Marker

public Marker(Marker orig)
Constructs a new immutable marker identical to a given marker.

Parameters:
orig - the marker to copy
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a new marker which is equal to this one. CloneNotSupportedException is never thrown.

Overrides:
clone in class java.lang.Object
Returns:
a new marker with the same name and position as this marker
Throws:
java.lang.CloneNotSupportedException

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Implementation of the Comparable interface. The passed object can be either another Marker or a Region. In the latter case, the region's start position is compared to this marker's position.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the object to compare to this marker
Returns:
negative or positive value, if the object is greater or smaller compared to this marker, zero if they are equal
Throws:
java.lang.ClassCastException - if o is neither a Markers nor a Region

add

public static int add(java.util.List markers,
                      Marker marker)
Adds marker chronologically to a pre-sorted list.

Parameters:
markers - a chronological marker list
marker - the marker to insert such that its predecessor has a position less or equal this marker's position and the marker's successor has a position greater than this marker's position.
Returns:
marker index in vector at which it was inserted

find

public static int find(java.util.List markers,
                       java.lang.String name,
                       int startIndex)
Gets the index for specific marker in a list. Note that if the markers have distinct names (no duplicates), it may be more convenient to create a list copy, sort it using the nameComparator, and looking it up using Collections.binarySearch().

Parameters:
markers - a List whose elements are instanceof Marker.
name - marker name to find
startIndex - where to begin
Returns:
The list index of the first occurance (beginning at startIndex) of a marker whose name equals the given name.
See Also:
nameComparator, Collections.binarySearch( List, Object, Comparator )