diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/certsrv/request/RequestId.java')
-rw-r--r-- | pki/base/common/src/com/netscape/certsrv/request/RequestId.java | 89 |
1 files changed, 67 insertions, 22 deletions
diff --git a/pki/base/common/src/com/netscape/certsrv/request/RequestId.java b/pki/base/common/src/com/netscape/certsrv/request/RequestId.java index 31681675b..da61f2bc0 100644 --- a/pki/base/common/src/com/netscape/certsrv/request/RequestId.java +++ b/pki/base/common/src/com/netscape/certsrv/request/RequestId.java @@ -17,6 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.certsrv.request; +import java.math.BigInteger; + /** * The RequestId class represents the identifier for a particular * request within a request queue. This identifier may be used to @@ -25,52 +27,95 @@ package com.netscape.certsrv.request; * * @version $Revision$ $Date$ */ -public final class RequestId { +public class RequestId { + + protected BigInteger value; /** * Creates a new RequestId from its string representation. * <p> * * @param id - * a string containing the decimal (base 10) value for the identifier. + * a string containing the decimal or hex value for the identifier. */ public RequestId(String id) { - mString = id; + if (id != null) { + id = id.trim(); + if (id.startsWith("0x")) { // hex + value = new BigInteger(id.substring(2), 16); + } else { // decimal + value = new BigInteger(id); + } + } } /** - * Converts the RequestId into its string representation. The string - * form can be stored in a database (such as the LDAP directory) + * Creates a new RequestId from its BigInteger representation. * <p> - * - * @return - * a string containing the decimal (base 10) value for the identifier. + * + * @param id + * a BigInteger containing the identifier. */ - public String toString() { - return mString; + public RequestId(BigInteger id) { + value = id; } /** - * Implements Object.hashCode. + * Creates a new RequestId from its integer representation. * <p> - * - * @return hash code of the object + * + * @param id + * an integer containing the identifier. */ - public int hashCode() { - return mString.hashCode(); + public RequestId(int id) { + value = BigInteger.valueOf(id); } /** - * Implements Object.equals. + * Converts the RequestId into its BigInteger representation. + * <p> + * + * @return + * a BigInteger containing the identifier. + */ + public BigInteger toBigInteger() { + return value; + } + + /** + * Converts the RequestId into its string representation. The string + * form can be stored in a database (such as the LDAP directory) * <p> * - * @param obj object to compare - * @return true if objects are equal + * @return + * a string containing the decimal (base 10) value for the identifier. */ - public boolean equals(Object obj) { - return mString.equals(obj); + public String toString() { + return value.toString(); } - // instance variables - private final String mString; + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RequestId other = (RequestId) obj; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } } |