Package com.tibco.patterns.learn.recpair

## Class RecPairId

- java.lang.Object
- - com.tibco.patterns.learn.recpair.RecPairId

- All Implemented Interfaces:
    `java.lang.Comparable<RecPairId>`

      public final class RecPairId
      extends java.lang.Object
      implements java.lang.Comparable<RecPairId>

  Stores a pair of keys. Ensures that keys are different and not null. The order of the two keys does not matter, it is still the same record pair. Can be used as a key in HashMap. Immutable class.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `RecPairId​(com.tibco.patterns.learn.jaxb.model.RecPairType xmlRecPair)` | Creates object that stores keys taken from the given XML record pair.
    `RecPairId​(java.lang.String key0, java.lang.String key1)` | Creates object that stores the two given keys for a record pair.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `compareTo​(RecPairId other)` | Compares the two keys.
    `boolean` | `equals​(java.lang.Object obj)` | If the two keys are swapped, the record pairs are still equal.
    `java.lang.String` | `getKey​(int index)` |
    `int` | `hashCode()` |
    `static void` | `selfTest()` | Called from ProjectTest, RecPairTest.
    `java.lang.String` | `toString()` |

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### RecPairId

          public RecPairId​(java.lang.String key0,
                           java.lang.String key1)

      Creates object that stores the two given keys for a record pair.
      Parameters:
        `key0` - - the key value for the first record.
        `key1` - - the key value for the second record.
      Throws:
        `java.lang.NullPointerException` - if a parameter is null.
        `java.lang.IllegalArgumentException` - if both keys are equal.

    - #### RecPairId

          public RecPairId​(com.tibco.patterns.learn.jaxb.model.RecPairType xmlRecPair)

      Creates object that stores keys taken from the given XML record pair. To be used from Learn UI.
      Parameters:
        `xmlRecPair` - - an XML object that contains two keys. Not null.
      Throws:
        `java.lang.NullPointerException` - one of the keys in the given xmlRecPair is null.
        `java.lang.IllegalArgumentException` - if both keys in xmlRecPair are equal.

  - ### Method Detail

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### getKey

          public java.lang.String getKey​(int index)

      Parameters:
        `index` - - the index of the record (0 or 1).
      Returns:
        the key of one of the records in the pair.
      Throws:
        `java.lang.IllegalArgumentException` - if the index is not 0 or 1.

    - #### equals

          public boolean equals​(java.lang.Object obj)

      If the two keys are swapped, the record pairs are still equal.
      Overrides:
        `equals` in class `java.lang.Object`
      Parameters:
        `obj` - - the reference object with which to compare
      Returns:
        true if two RecPairId objects are compared and both refer to the same two records.

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`
      Returns:
        a hash code for this pair of keys. The order of any two given keys does not matter.

    - #### compareTo

          public int compareTo​(RecPairId other)

      Compares the two keys. Comparison is consistent with equals. Since IDs with swapped keys are still equal, the two lexicographically smaller key strings from both IDs are compared first, followed by the two larger strings.
      Specified by:
        `compareTo` in interface `java.lang.Comparable<RecPairId>`
      Parameters:
        `other` - - the ID to compare with. Not null.
      Returns:
        a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

    - #### selfTest

          public static void selfTest()

      Called from ProjectTest, RecPairTest. Tests equals and hashCode operations.