Class IdentifierEquivClass

java.lang.Object
xal.tools.text.IdentifierEquivClass
All Implemented Interfaces:
Comparable<IdentifierEquivClass>

public class IdentifierEquivClass extends Object implements Comparable<IdentifierEquivClass>

Represents an equivalence class of element identifiers. An element ID is a member of the equivalence class if it is a proper substring of the current class representative or the current class representative is a proper substring of the given element ID. The class representative identifier is continually truncated whenever a member element ID is encounter that is shorter, that is, the encountered ID becomes the representative ID.

The class of identifiers is intended to be associated with one hardware element.

Due to a peculiarity of the XAL lattice generator, modeling elements are created with identifiers that are suffixed versions of their hardware counterpart. Thus, we equate two ElementIdClass objects if they have the same prefix (ergo, they must belong to the same hardware object).

Since:
Jun 4, 2013
Author:
Christopher K. Allen
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of ElementIdClass.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(String strElemId)
    This is essentially a utility method for the other methods of the class, as such I have removed the visibility.
    int
    Implements a comparison of equivalences classes for the element IDs.
    boolean
    Checks whether or not the given object is equivalent to this object and also sets the base ID string if necessary.
    boolean
    Tests whether or not the given equivalence class object is the same as this, w.r.t. equivalence of the element ID class.
    int
    Returns the hash code of the base ID.
    boolean
    isMember(String strElemId)
    Checks whether or not the given ID is an member of this equivalence class of element IDs.
    Returns the representative identifier string.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • IdentifierEquivClass

      public IdentifierEquivClass(String strElemId)
      Creates a new instance of ElementIdClass.
      Parameters:
      strElemId -
      Since:
      Jun 5, 2013
  • Method Details

    • isMember

      public boolean isMember(String strElemId)
      Checks whether or not the given ID is an member of this equivalence class of element IDs.
      Parameters:
      strElemId - element identifier under comparison
      Returns:
      true if argument is equivalent to the representative element of this equivalence class, false otherwise
      Since:
      Jun 10, 2013
    • equivalentTo

      public boolean equivalentTo(IdentifierEquivClass idCmp)
      Tests whether or not the given equivalence class object is the same as this, w.r.t. equivalence of the element ID class. Returns the result

          ElementIdClass.isMember(idCmp.strClassId)
      Parameters:
      idCmp - element ID class object to compare
      Returns:
      returns true if the argument and this object represent the same equivalence class, or false otherwise
      Since:
      Jun 10, 2013
    • compareTo

      public int compareTo(IdentifierEquivClass idcCmp)
      Implements a comparison of equivalences classes for the element IDs. We first check whether or not the argument is equivalent to this object, if so a value of 0 is returned. If not, then the representative strings of the equivalence class are compared lexicographically, the result of that comparison is returned. Note that is value will not be 0 since the objects under comparison are not in the same equivalence class of element IDs.
      Specified by:
      compareTo in interface Comparable<IdentifierEquivClass>
      Parameters:
      idcCmp - equivalence class object to compare w.r.t. the element ID class
      Returns:
      a value 0 if the argument is the same equivalence class, or the lexicographical comparison result otherwise
      Since:
      Jun 6, 2013
      See Also:
    • equals

      public boolean equals(Object obj)
      Checks whether or not the given object is equivalent to this object and also sets the base ID string if necessary. Two ElementIdentifiers are equivalent if one is a substring of the other. The base ID string then becomes the smallest common string between them.
      Overrides:
      equals in class Object
      Parameters:
      obj - obj to be compared (must be of type ElementIdentifier
      Returns:
      returns true if the given element identifier object is equivalent to this (see above), false otherwise.
      Since:
      Jun 4, 2013
      See Also:
    • hashCode

      public int hashCode()
      Returns the hash code of the base ID. This is the prefix of the identifier, which has intersected all others compared to so far.
      Overrides:
      hashCode in class Object
      Returns:
      hash code of the ID prefix (makes the hash class larger)
      Since:
      Jun 4, 2013
      See Also:
    • toString

      public String toString()
      Returns the representative identifier string.
      Overrides:
      toString in class Object
      Returns:
      returns the value of the class ID
      Since:
      Jun 4, 2013
      See Also:
    • compareTo

      public int compareTo(String strElemId) throws NoSuchElementException

      This is essentially a utility method for the other methods of the class, as such I have removed the visibility.

      Makes a comparison of the equivalence class representative string ID with the given string ID. If the two strings are not equivalent, then a NoSuchElementException is thrown. If the two strings are equivalent (w.r.t. to the equivalence class rules), then an integer value is returned (described below). The empty identifier "" is handled as a special case: no string of finite length is equivalent to the empty string, both strings must be empty to be equivalent. Otherwise we have the trivial case where all IDs would be equivalent to the empty ID since all IDs contain the empty string.

      Now consider when the given string is found to be an element of this equivalence class. Denote by s the given argument string and by r the representative string of this equivalence class (so that the equivalence class is represented as [r]). Then the follow results are returned:

          -1 ⇒ sr ,
            0 ⇒ s = r ,
          +1 ⇒ sr ,

      where all strings are compared starting from the head, i.e., s[0] == r[0] must hold in every case since neither is the empty string.

      Parameters:
      strElemId - string to be compared to the representative string of this equivalence class
      Returns:
      if the two strings are equivalent, then the result of the comparison as described above, otherwise an exception is thrown.
      Throws:
      NoSuchElementException - the given string ID is not equivalent to this object
      Since:
      Jun 10, 2013