Class TwoFacedObject

java.lang.Object
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 Details

    • debug

      public static boolean debug
      debug flag
  • Constructor Details

    • 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 Details

    • 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.
    • getIdObject

      public static Object getIdObject(Object o)
      Get the id object of this possible TwoFacedObject.
      Parameters:
      o - object in question.
      Returns:
      the id if this is a TwoFacedObject, otherwise 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)
      Find the label for the object in the list
      Parameters:
      id - object to search for
      l - list of TwoFacedObjects objects
      Returns:
      the label
    • contains

      public static boolean contains(List objects, Object value)
    • 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.
    • sort

      public static void sort(List list)