at.tuwien.ifs.somtoolbox.layers
Class Label

java.lang.Object
  extended by at.tuwien.ifs.somtoolbox.layers.Label
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ClusterLabel

public class Label
extends Object
implements Serializable

A simple class representing a unit label. This class holds the name, the value and the quantization error of a label. It also provides static methods for sorting an array of labels according to on of the three properties mentioned before.

Version:
$Id: Label.java 3587 2010-05-21 10:35:33Z mayer $
Author:
Michael Dittenbach
See Also:
Serialized Form

Field Summary
private  String bestContext
           
private  String name
           
private  double qe
           
private static long serialVersionUID
           
static int SORT_ASC
           
private static int SORT_BYMEAN
           
private static int SORT_BYNAME
           
private static int SORT_BYQE
           
static int SORT_DESC
           
private  double value
           
 
Constructor Summary
Label(String name)
           
Label(String name, double value)
           
Label(String name, double value, double qe)
          Constructs a label object with the given arguments.
Label(String name, String BestContext)
           
 
Method Summary
 String getBestContext()
           
 String getName()
          Returns the name of the label.
 String getNameAndScaledValue(int scale)
           
 double getQe()
          Returns the quantization error of this label.
 double getValue()
          Returns the value of this label.
private static void qsort(Label[] a, int type, int order)
          Internal method for the quick sort algorithm.
private static void qsort(Label[] a, int lo0, int hi0, int type)
          Internal method for the quick sort algorithm.
private static void reverse(Label[] a)
          Convenience method for the reversal of an array of labels.
private static void reverse(Label[] a, int start, int end)
          Internal method for reversal of a part of an array of labels.
static void sortByName(Label[] labels, int order)
          Convenience method for sorting an array of labels by their names.
static void sortByQe(Label[] labels, int order)
          Convenience method for sorting an array of labels by their quantization errors.
static void sortByQeValue(Label[] labels, int order1, int order2)
          Convenience method for sorting an array of labels by their quantization errors and values (in case of equal quantization errors).
static void sortByValue(Label[] labels, int order)
          Convenience method for sorting an array of labels by their values.
static void sortByValueQe(Label[] labels, int order1, int order2)
          Convenience method for sorting an array of labels by their values and quantization errors (in case of equal value).
private static void swap(Label[] a, int i, int j)
          Internal method for the quick sort algorithm for swapping two elements (labels) of an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

SORT_ASC

public static final int SORT_ASC
See Also:
Constant Field Values

SORT_BYMEAN

private static final int SORT_BYMEAN
See Also:
Constant Field Values

SORT_BYNAME

private static final int SORT_BYNAME
See Also:
Constant Field Values

SORT_BYQE

private static final int SORT_BYQE
See Also:
Constant Field Values

SORT_DESC

public static final int SORT_DESC
See Also:
Constant Field Values

name

private String name

qe

private double qe

value

private double value

bestContext

private String bestContext
Constructor Detail

Label

public Label(String name,
             double value,
             double qe)
Constructs a label object with the given arguments.

Parameters:
name - the name of the label.
value - the label value.
qe - the quantization error of the label.

Label

public Label(String name,
             double value)

Label

public Label(String name)

Label

public Label(String name,
             String BestContext)
Method Detail

qsort

private static void qsort(Label[] a,
                          int type,
                          int order)
Internal method for the quick sort algorithm.

Parameters:
a - an array of labels to be sorted.
type - the sorting criterion (SORT_BYMEAN, SORT_BYNAME or SORT_BYQE).
order - the order of sorting, either ascending (SORT_ASC) or descending (SORT_DESC).

qsort

private static void qsort(Label[] a,
                          int lo0,
                          int hi0,
                          int type)
Internal method for the quick sort algorithm.

Parameters:
a - an array of labels to be sorted.
lo0 - the lower boundary.
hi0 - the upper boundary.
type - the sorting criterion (SORT_BYMEAN, SORT_BYNAME or SORT_BYQE).

reverse

private static void reverse(Label[] a)
Convenience method for the reversal of an array of labels.

Parameters:
a - the array of labels to be reversed.

reverse

private static void reverse(Label[] a,
                            int start,
                            int end)
Internal method for reversal of a part of an array of labels.

Parameters:
a - the array of labels to be reversed.
start - the lower boundary.
end - the upper boundary.

sortByValue

public static void sortByValue(Label[] labels,
                               int order)
Convenience method for sorting an array of labels by their values.

Parameters:
labels - an array of labels to be sorted.
order - the sorting order, either ascending (SORT_ASC) or descending (SORT_DESC).

sortByValueQe

public static void sortByValueQe(Label[] labels,
                                 int order1,
                                 int order2)
Convenience method for sorting an array of labels by their values and quantization errors (in case of equal value). The sorting order is specified separately for both criteria by arguments order1 and order2.

Parameters:
labels - an array of labels to be sorted.
order1 - the sorting order for the primary criterion, either ascending (SORT_ASC) or descending ( SORT_DESC).
order2 - the sorting order for the secondary criterion, either ascending (SORT_ASC) or descending ( SORT_DESC).

sortByName

public static void sortByName(Label[] labels,
                              int order)
Convenience method for sorting an array of labels by their names.

Parameters:
labels - an array of labels to be sorted.
order - the sorting order, either ascending (SORT_ASC) or descending (SORT_DESC).

sortByQe

public static void sortByQe(Label[] labels,
                            int order)
Convenience method for sorting an array of labels by their quantization errors.

Parameters:
labels - an array of labels to be sorted.
order - the sorting order, either ascending (SORT_ASC) or descending (SORT_DESC).

sortByQeValue

public static void sortByQeValue(Label[] labels,
                                 int order1,
                                 int order2)
Convenience method for sorting an array of labels by their quantization errors and values (in case of equal quantization errors). The sorting order is determined separately for both criteria by arguments order1 and order2.

Parameters:
labels - an array of labels to be sorted.
order1 - the sorting order for the primary criterion, either ascending (SORT_ASC) or descending ( SORT_DESC).
order2 - the sorting order for the secondary criterion, either ascending (SORT_ASC) or descending ( SORT_DESC).

swap

private static void swap(Label[] a,
                         int i,
                         int j)
Internal method for the quick sort algorithm for swapping two elements (labels) of an array.

Parameters:
a - an array of labels.
i - index of first element to be swapped with second.
j - index of second element to be swapped with first.

getName

public String getName()
Returns the name of the label.

Returns:
the name of the label.

getQe

public double getQe()
Returns the quantization error of this label.

Returns:
the quantization error of this label.

getBestContext

public String getBestContext()

getValue

public double getValue()
Returns the value of this label.

Returns:
the value of this label.

getNameAndScaledValue

public String getNameAndScaledValue(int scale)