/// <summary> /// Compares the specified object with this <code>UID</code> for /// equality. /// /// This method returns <code>true</code> if and only if the /// specified object is a <code>UID</code> instance with the same /// <code>unique</code>, <code>time</code>, and <code>count</code> /// values as this one. /// </summary> /// <param name="obj"> the object to compare this <code>UID</code> to /// </param> /// <returns> <code>true</code> if the given object is equivalent to /// this one, and <code>false</code> otherwise </returns> public override bool Equals(Object obj) { if (obj is UID) { UID uid = (UID)obj; return(Unique == uid.Unique && Count == uid.Count && Time == uid.Time); } else { return(false); } }
/// <summary> /// Generates a unique object identifier. /// /// <para>If the system property <code>java.rmi.server.randomIDs</code> /// is defined to equal the string <code>"true"</code> (case insensitive), /// then this constructor will use a cryptographically /// strong random number generator to choose the object number of the /// returned <code>ObjID</code>. /// </para> /// </summary> public ObjID() { /* * If generating random object numbers, create a new UID to * ensure uniqueness; otherwise, use a shared UID because * sequential object numbers already ensure uniqueness. */ if (UseRandomIDs()) { Space = new UID(); ObjNum = SecureRandom.NextLong(); } else { Space = MySpace; ObjNum = NextObjNum.AndIncrement; } }
/// <summary> /// Constructs an object identifier given data read from a stream. /// </summary> private ObjID(long objNum, UID space) { this.ObjNum = objNum; this.Space = space; }
/// <summary> /// Creates a "well-known" object identifier. /// /// <para>An <code>ObjID</code> created via this constructor will not /// clash with any <code>ObjID</code>s generated via the no-arg /// constructor. /// /// </para> /// </summary> /// <param name="objNum"> object number for well-known object identifier </param> public ObjID(int objNum) { Space = new UID((short)0); this.ObjNum = objNum; }