GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.3 -r1.4
--- IIdentifier.java 2 May 2007 01:58:19 -0000 1.3
+++ IIdentifier.java 2 May 2007 23:43:33 -0000 1.4
@@ -8,9 +8,10 @@
* @see DetectorElement
*
* @author jeremym
- * @version $Id: IIdentifier.java,v 1.3 2007/05/02 01:58:19 jeremy Exp $
+ * @version $Id: IIdentifier.java,v 1.4 2007/05/02 23:43:33 jeremy Exp $
*/
public interface IIdentifier
+extends Comparable
{
/**
* Get the value of this identifier as a long.
@@ -23,52 +24,20 @@
* @param id
*/
void setValue(long id);
-
- /**
- * True if the identifiers are equivalent.
- *
- * @param id
- * @return
- */
- public boolean equals(IIdentifier id);
-
- /**
- * True if the identifiers are not equivalent.
- *
- * @param id
- * @return
- */
- public boolean nequals(IIdentifier id);
-
- /**
- * True if this identifier is greater.
- *
- * @param id
- * @return
- */
- public boolean greater(IIdentifier id);
-
- /**
- * True if this identifier is less.
- *
- * @param id
- * @return
- */
- public boolean less(IIdentifier id);
-
+
/**
* Get a raw hex string representation.
*
* @return
*/
- public String getHexString();
+ public String toHexString();
/**
* Set the value from a raw hex string.
*
* @param hexRep
*/
- public void setHexString(String hexRep);
+ public void fromHexString(String hexRep);
/**
* Clear the state of this identifier.
GeomConverter/src/org/lcsim/detector/identifier
diff -u -r1.1 -r1.2
--- Identifier.java 2 May 2007 01:58:19 -0000 1.1
+++ Identifier.java 2 May 2007 23:43:33 -0000 1.2
@@ -5,7 +5,7 @@
* Implementation of {@link IIdentifier}.
*
* @author Jeremy McCormick
- * @version $Id: Identifier.java,v 1.1 2007/05/02 01:58:19 jeremy Exp $
+ * @version $Id: Identifier.java,v 1.2 2007/05/02 23:43:33 jeremy Exp $
*/
package org.lcsim.detector.identifier;
@@ -48,23 +48,18 @@
{
value = unsetValue;
}
-
- public boolean equals( IIdentifier id)
- {
- return id.getValue() == value;
- }
- public String getHexString()
+ public String toHexString()
{
return Long.toHexString(value);
}
public String toString()
{
- return getHexString();
+ return toHexString();
}
- public void setHexString( String hexRep )
+ public void fromHexString( String hexRep )
{
value = Long.parseLong(hexRep, 16);
}
@@ -74,18 +69,28 @@
return value != unsetValue;
}
- public boolean less( IIdentifier id)
- {
- return value < id.getValue();
- }
-
- public boolean greater( IIdentifier id)
- {
- return value > id.getValue();
- }
+ public int compareTo( Object object )
+ {
+ if ( object instanceof IIdentifier )
+ {
+ return Long.valueOf(((IIdentifier)object).getValue()).compareTo(getValue());
+ }
+ else if ( object instanceof Long)
+ {
+ return ((Long)object).compareTo(getValue());
+ }
+ else if ( object instanceof Integer )
+ {
+ return ((Long)object).compareTo(getValue());
+ }
+ else
+ {
+ throw new ClassCastException("Identifier is not comparable to an object of class " + object.getClass().getCanonicalName() + ".");
+ }
+ }
- public boolean nequals( IIdentifier id)
+ public boolean equals( Object object )
{
- return value != id.getValue();
+ return compareTo( object ) == 0;
}
-}
+}
\ No newline at end of file