ucar.unidata.util
Class TwoFacedObject

java.lang.Object
  extended by ucar.unidata.util.TwoFacedObject
All Implemented Interfaces:
Comparable

public class TwoFacedObject
extends Object
implements Comparable

A generic Object wrapper that holds two objects. The first is used as the label and for comparisons in lists.

Version:
$Revision: 1.20 $ $Date: 2006/06/23 20:17:32 $
Author:
Metapps development team

Field Summary
static boolean debug
          debug flag
 
Constructor Summary
TwoFacedObject()
          Default constructor with null id and label
TwoFacedObject(Object label)
          Create a TwoFacedObject where both id and label are identical.
TwoFacedObject(Object label, int id)
          Create a TwoFacedObject with label and integer id
TwoFacedObject(Object label, Object id)
          Create a TwoFacedObject.
 
Method Summary
 int compareTo(Object o)
          Compare this object to another.
static List createList(int[] ids, String[] names)
          Create a list of tfos from the given int ids and names
static List createList(String[] ids, String[] names)
          Create a list of tfos from the given int ids and names
 boolean equals(Object other)
          See if this TwoFacedObject is equal to another object.
static TwoFacedObject findId(Object id, List l)
          Finf the tfo with the given id in the list
static String findLabel(Object id, List l)
           
 Object getId()
          Get the Id object.
static List getIdList(List objects)
          Create a list of ids from the given list of objects.
static String getIdString(Object o)
          Get a String representation for the id of this TwoFacedObject.
static List getIdStrings(List objects)
          Get a String representation for the objects in te lsit
 Object getLabel()
          Get the Label object.
 int hashCode()
          Get the hashcode for this TwoFacedObject
 void setId(Object newId)
          Sets the value of the Id object.
 void setLabel(Object newLabel)
          Sets the value of the Label object.
 String toString()
          String representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

debug

public static boolean debug
debug flag

Constructor Detail

TwoFacedObject

public TwoFacedObject()
Default constructor with null id and label


TwoFacedObject

public TwoFacedObject(Object label)
Create a TwoFacedObject where both id and label are identical.

Parameters:
label - label and object

TwoFacedObject

public TwoFacedObject(Object label,
                      int id)
Create a TwoFacedObject with label and integer id

Parameters:
label - label
id - id

TwoFacedObject

public TwoFacedObject(Object label,
                      Object id)
Create a TwoFacedObject.

Parameters:
label - object to use for labeling.
id - other face of this object
Method Detail

toString

public String toString()
String representation of this object.

Overrides:
toString in class Object
Returns:
toString() method of label.

equals

public boolean equals(Object other)
See if this TwoFacedObject is equal to another object.

Overrides:
equals in class Object
Parameters:
other -
Returns:
true if both are TwoFacedObjects and their id-s are equal

hashCode

public int hashCode()
Get the hashcode for this TwoFacedObject

Overrides:
hashCode in class Object
Returns:
the hashcode

getId

public Object getId()
Get the Id object.

Returns:
the id for this TwoFacedObject.

setId

public void setId(Object newId)
Sets the value of the Id object.

Parameters:
newId -

getLabel

public Object getLabel()
Get the Label object.

Returns:
the label for this TwoFacedObject.

setLabel

public void setLabel(Object newLabel)
Sets the value of the Label object.

Parameters:
newLabel -

getIdString

public static String getIdString(Object o)
Get a String representation for the id of this TwoFacedObject.

Parameters:
o - object in question.
Returns:
the toString() of the id if this is a TwoFacedObject, otherwise the toString() method of o.

createList

public static List createList(int[] ids,
                              String[] names)
Create a list of tfos from the given int ids and names

Parameters:
ids - ids
names - names
Returns:
list of tfos

createList

public static List createList(String[] ids,
                              String[] names)
Create a list of tfos from the given int ids and names

Parameters:
ids - ids
names - names
Returns:
list of tfos

getIdList

public static List getIdList(List objects)
Create a list of ids from the given list of objects. For any TwoFaceObject in objects, the id is added to the resulting list, otherwise the object is added

Parameters:
objects - list of objects
Returns:
list of tfos

findId

public static TwoFacedObject findId(Object id,
                                    List l)
Finf the tfo with the given id in the list

Parameters:
id - id to look for
l - list of tfos
Returns:
the tfo or null if none found

findLabel

public static String findLabel(Object id,
                               List l)

getIdStrings

public static List getIdStrings(List objects)
Get a String representation for the objects in te lsit

Parameters:
objects - objects in question.
Returns:
List of fbhe toString() of the id if these are TwoFacedObjects, otherwise the toString() method of o.

compareTo

public int compareTo(Object o)
Compare this object to another.

Specified by:
compareTo in interface Comparable
Parameters:
o - object in question.
Returns:
spec from Comparable interface.