Class DataWithUid<DataType>

java.lang.Object
org.jtrim2.concurrent.query.DataWithUid<DataType>
Type Parameters:
DataType - the type of the data held by the DataWithUid instance

public final class DataWithUid<DataType> extends Object
Defines an object and its ID which uniquely identifies the object within the JVM. That is, two objects with the same ID (according to equals are considered to be equivalent objects).

This class overrides equals and hashCode, so that two DataWithUid instances are considered equivalent, if and only if, their ID equal (according to their equals method).

Thread safety

The methods of this class are safe to be accessed by multiple threads concurrently. Instances of this class cannot be directly modified, only its properties if they are mutable. In case both the ID and the data is immutable, then the DataWithUid is completely immutable.

Synchronization transparency

The methods of this class are synchronization transparent.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates and initializes the DataWithUid instance with the argument as the data and the ID.
    Creates and initializes the DataWithUid instance with the given data and ID.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks whether the passed object is a DataWithUid and has an equivalent ID or not.
    Returns the data specified at construction time.
    Returns the ID which is used to determine if two data is to be considered equivalent.
    int
    Returns a hash code which can be used in has tables and is compatible with the equals method.
    Returns the string representation of this DataWithUid in no particular format.

    Methods inherited from class java.lang.Object

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

    • DataWithUid

      public DataWithUid(DataType data)
      Creates and initializes the DataWithUid instance with the argument as the data and the ID.
      Parameters:
      data - the data held by the DataWithUid instance and also the ID. That is, both the getData and the getID methods will return this object. This argument is allowed to be null.
    • DataWithUid

      public DataWithUid(DataType data, Object id)
      Creates and initializes the DataWithUid instance with the given data and ID.
      Parameters:
      data - the data held by the DataWithUid instance. This argument is allowed to be null.
      id - the ID identifying the given data. That is, only this ID needs to be compared to determine if two data is equivalent. This argument can be null but note that null ID can only be equivalent to another null ID.
  • Method Details

    • getData

      public DataType getData()
      Returns the data specified at construction time. If two data is considered to be equivalent should be determined by their ID.
      Returns:
      the data specified at construction time. This method may return null if null was specified at construction time.
    • getID

      public Object getID()
      Returns the ID which is used to determine if two data is to be considered equivalent. That is, if the IDs are equivalent according to their equals method, the data they identify should be considered equal as well. Note that it is allowed for the data objects to have an equals method inconsistent with the IDs.
      Returns:
      the ID which is used to determine if two data is to be considered equivalent. This method may return null and null values can be equivalent only to other null values.
    • equals

      public boolean equals(Object obj)
      Checks whether the passed object is a DataWithUid and has an equivalent ID or not. That is, this method returns true, if and only if, the passed object is an instance of DataWithUid and its ID is also equals to the ID of this DataWithUid.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to which this DataWithUid is to be compared to. This argument can be null, in which case this method returns false.
      Returns:
      true, the passed object is an instance of DataWithUid and its ID is also equals to the ID of this DataWithUid, false otherwise
    • hashCode

      public int hashCode()
      Returns a hash code which can be used in has tables and is compatible with the equals method.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code which can be used in has tables and is compatible with the equals method
      See Also:
    • toString

      public String toString()
      Returns the string representation of this DataWithUid in no particular format. The string representation contains the string representation of both the ID and the data.

      This method is intended to be used for debugging only.

      Overrides:
      toString in class Object
      Returns:
      the string representation of this object in no particular format. This method never returns null.