com.foxinmy.weixin4j.util
Class ObjectId

java.lang.Object
  extended by com.foxinmy.weixin4j.util.ObjectId
All Implemented Interfaces:
Serializable, Comparable<ObjectId>

public class ObjectId
extends Object
implements Comparable<ObjectId>, Serializable

A globally unique identifier for objects.

Consists of 12 bytes, divided as follows:

ObjectID layout
0 1 2 3 4 5 6 7 8 9 10 11
time machine pid inc

Instances of this class are immutable.

See Also:
Serialized Form

Constructor Summary
ObjectId()
          Create a new object id.
ObjectId(byte[] b)
          Constructs an ObjectId given its 12-byte binary representation.
 
Method Summary
 int compareTo(ObjectId id)
           
 boolean equals(Object o)
           
static ObjectId get()
          Gets a new object id.
static int getCurrentCounter()
          Gets the current value of the auto-incrementing counter.
 Date getDate()
          Gets the timestamp as a Date instance.
 int getTimestamp()
          Gets the timestamp (number of seconds since the Unix epoch).
 int hashCode()
           
static boolean isValid(String s)
          Checks if a string could be an ObjectId.
 byte[] toByteArray()
          Convert to a byte array.
 String toHexString()
          Converts this instance into a 24-byte hexadecimal string representation.
 String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectId

public ObjectId(byte[] b)
Constructs an ObjectId given its 12-byte binary representation.

Parameters:
b - a byte array of length 12

ObjectId

public ObjectId()
Create a new object id.

Method Detail

get

public static ObjectId get()
Gets a new object id.

Returns:
the new id

isValid

public static boolean isValid(String s)
Checks if a string could be an ObjectId.

Parameters:
s - a potential ObjectId as a String.
Returns:
whether the string could be an object id
Throws:
IllegalArgumentException - if hexString is null

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

toHexString

public String toHexString()
Converts this instance into a 24-byte hexadecimal string representation.

Returns:
a string representation of the ObjectId in hexadecimal format

toByteArray

public byte[] toByteArray()
Convert to a byte array. Note that the numbers are stored in big-endian order.

Returns:
the byte array

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(ObjectId id)
Specified by:
compareTo in interface Comparable<ObjectId>

getTimestamp

public int getTimestamp()
Gets the timestamp (number of seconds since the Unix epoch).

Returns:
the timestamp

getDate

public Date getDate()
Gets the timestamp as a Date instance.

Returns:
the Date

getCurrentCounter

public static int getCurrentCounter()
Gets the current value of the auto-incrementing counter.

Returns:
the current counter value.


Copyright © 2014–2017. All rights reserved.