public class ObjectId extends Object implements Comparable<ObjectId>, Serializable
| 构造器和说明 |
|---|
ObjectId()
Create a new object id.
|
ObjectId(byte[] bytes)
Constructs a new instance from the given byte array
|
ObjectId(ByteBuffer buffer)
Constructs a new instance from the given ByteBuffer
|
ObjectId(Date date)
Constructs a new instance using the given date.
|
ObjectId(Date date,
int counter)
Constructs a new instances using the given date and counter.
|
ObjectId(Date date,
int machineIdentifier,
short processIdentifier,
int counter)
已过时。
Use
ObjectId(Date, int) instead |
ObjectId(int timestamp,
int counter)
Creates an ObjectId using the given time, machine identifier, process identifier, and counter.
|
ObjectId(int timestamp,
int machineIdentifier,
short processIdentifier,
int counter)
已过时。
Use
ObjectId(int, int) instead |
ObjectId(String hexString)
Constructs a new instance from a 24-byte hexadecimal string representation.
|
| 限定符和类型 | 方法和说明 |
|---|---|
int |
compareTo(ObjectId other) |
static ObjectId |
createFromLegacyFormat(int time,
int machine,
int inc)
已过时。
Use
ObjectId(int, int) instead |
boolean |
equals(Object o) |
static ObjectId |
get()
Gets a new object id.
|
int |
getCounter()
已过时。
|
static int |
getCurrentCounter()
已过时。
|
Date |
getDate()
Gets the timestamp as a
Date instance. |
static int |
getGeneratedMachineIdentifier()
已过时。
|
static int |
getGeneratedProcessIdentifier()
已过时。
|
int |
getMachineIdentifier()
已过时。
|
short |
getProcessIdentifier()
已过时。
|
long |
getTime()
已过时。
Use #getDate instead
|
int |
getTimeSecond()
已过时。
Use #getTimestamp instead
|
int |
getTimestamp()
Gets the timestamp (number of seconds since the Unix epoch).
|
int |
hashCode() |
static boolean |
isValid(String hexString)
Checks if a string could be an
ObjectId. |
void |
putToByteBuffer(ByteBuffer buffer)
Convert to bytes and put those bytes to the provided ByteBuffer.
|
byte[] |
toByteArray()
Convert to a byte array.
|
String |
toHexString()
Converts this instance into a 24-byte hexadecimal string representation.
|
String |
toString() |
String |
toStringMongod()
已过时。
use
toHexString() |
public ObjectId()
public ObjectId(Date date)
date - the datepublic ObjectId(Date date, int counter)
date - the datecounter - the counterIllegalArgumentException - if the high order byte of counter is not zero@Deprecated public ObjectId(Date date, int machineIdentifier, short processIdentifier, int counter)
ObjectId(Date, int) insteaddate - the datemachineIdentifier - the machine identifierprocessIdentifier - the process identifiercounter - the counterIllegalArgumentException - if the high order byte of machineIdentifier or counter is not zero@Deprecated public ObjectId(int timestamp, int machineIdentifier, short processIdentifier, int counter)
ObjectId(int, int) insteadtimestamp - the time in secondsmachineIdentifier - the machine identifierprocessIdentifier - the process identifiercounter - the counterIllegalArgumentException - if the high order byte of machineIdentifier or counter is not zeropublic ObjectId(int timestamp,
int counter)
timestamp - the time in secondscounter - the counterIllegalArgumentException - if the high order byte of counter is not zeropublic ObjectId(String hexString)
hexString - the string to convertIllegalArgumentException - if the string is not a valid hex string representation of an ObjectIdpublic ObjectId(byte[] bytes)
bytes - the byte arrayIllegalArgumentException - if array is null or not of length 12public ObjectId(ByteBuffer buffer)
buffer - the ByteBufferIllegalArgumentException - if the buffer is null or does not have at least 12 bytes remainingpublic static ObjectId get()
public static boolean isValid(String hexString)
ObjectId.hexString - a potential ObjectId as a String.IllegalArgumentException - if hexString is nullpublic byte[] toByteArray()
public void putToByteBuffer(ByteBuffer buffer)
buffer - the ByteBufferIllegalArgumentException - if the buffer is null or does not have at least 12 bytes remainingpublic int getTimestamp()
public Date getDate()
Date instance.public String toHexString()
public int compareTo(ObjectId other)
compareTo 在接口中 Comparable<ObjectId>@Deprecated public static ObjectId createFromLegacyFormat(int time, int machine, int inc)
ObjectId(int, int) insteadCreates an ObjectId using time, machine and inc values. The Java driver used to create all ObjectIds this way, but it does not match the ObjectId specification, which requires four values, not three. This major release of the Java driver conforms to the specification, but still supports clients that are relying on the behavior of the previous major release by providing this explicit factory method that takes three parameters instead of four.
Ordinary users of the driver will not need this method. It's only for those that have written there own BSON decoders.
NOTE: This will not break any application that use ObjectIds. The 12-byte representation will be round-trippable from old to new driver releases.
time - time in secondsmachine - machine IDinc - incremental valueObjectId created from the given values@Deprecated public static int getCurrentCounter()
@Deprecated public static int getGeneratedMachineIdentifier()
@Deprecated public static int getGeneratedProcessIdentifier()
@Deprecated public int getMachineIdentifier()
@Deprecated public short getProcessIdentifier()
@Deprecated public int getCounter()
@Deprecated public int getTimeSecond()
@Deprecated public long getTime()
@Deprecated public String toStringMongod()
toHexString()toHexString()Copyright © 2024. All rights reserved.