/*
* Copyright (c) 2008-2014 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.exam.sdk.base;
import java.io.Serializable;
import java.net.NetworkInterface;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
import java.util.Date;
import java.util.Enumeration;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* <p>A globally unique identifier for objects.</p>
* <p>
* <p>Consists of 12 bytes, divided as follows:</p>
* <table border="1">
* <caption>ObjectID layout</caption>
* <tr>
* <td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td>
* </tr>
* <tr>
* <td colspan="4">time</td><td colspan="3">machine</td> <td colspan="2">pid</td><td colspan="3">inc</td>
* </tr>
* </table>
* <p>
* <p>Instances of this class are immutable.</p>
*
* @mongodb.driver.manual core/object-id ObjectId
*/
public final class ObjectId implements Comparable<ObjectId>, Serializable {
private static final long serialVersionUID = 3670079982654483072L;
static final Logger LOGGER = Logger.getLogger("ObjectId");
private static final int LOW_ORDER_THREE_BYTES = 0x00ffffff;
private static final int MACHINE_IDENTIFIER;
private static final short PROCESS_IDENTIFIER;
private static final AtomicInteger NEXT_COUNTER = new AtomicInteger(new SecureRandom().nextInt());
private static final char[] HEX_CHARS = new char[]{
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private final int timestamp;
private final int machineIdentifier;
private final short processIdentifier;
private final int counter;
/**
* Gets a new object id.
*
* @return the new id
*/
public static ObjectId get() {
return new ObjectId();
}
/**
* Checks if a string could be an {@code ObjectId}.
*
* @param hexString a potential ObjectId as a String.
* @return whether the string could be an object id
* @throws IllegalArgumentException if hexString is null
*/
public static boolean isValid(final String hexString) {
if (hexString == null) {
throw new IllegalArgumentException();
}
int len = hexString.length();
if (len != 24) {
return false;
}
for (int i = 0; i < len; i++) {
char c = hexString.charAt(i);
if (c >= '0' && c <= '9') {
continue;
}
if (c >= 'a' && c <= 'f') {
continue;
}
if (c >= 'A' && c <= 'F') {
continue;
}
return false;
}
return true;
}
/**
* Gets the generated machine identifier.
*
* @return an int representing the machine identifier
*/
public static int getGeneratedMachineIdentifier() {
return MACHINE_IDENTIFIER;
}
/**
* Gets the generated process identifier.
*
* @return the process id
*/
public static int getGeneratedProcessIdentifier() {
return PROCESS_IDENTIFIER;
}
/**
* Gets the current value of the auto-incrementing counter.
*
* @return the current counter value.
*/
public static int getCurrentCounter() {
return NEXT_COUNTER.get();
}
/**
* <p>Creates an ObjectId using time, machine and inc values. The Java driver used to create all ObjectIds this way, but it does not
* match the <a href="http://docs.mongodb.org/manual/reference/object-id/">ObjectId specification</a>, 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.</p>
* <p>
* <p>Ordinary users of the driver will not need this method. It's only for those that have written there own BSON decoders.</p>
* <p>
* <p>NOTE: This will not break any application that use ObjectIds. The 12-byte representation will be round-trippable from old to new
* driver releases.</p>
*
* @param time time in seconds
* @param machine machine ID
* @param inc incremental value
* @return a new {@code ObjectId} created from the given values
* @since 2.12.0
*/
public static ObjectId createFromLegacyFormat(final int time, final int machine, final int inc) {
return new ObjectId(time, machine, inc);
}
/**
* Create a new object id.
*/
public ObjectId() {
this(new Date());
}
/**
* Constructs a new instance using the given date.
*
* @param date the date
*/
public ObjectId(final Date date) {
this(dateToTimestampSeconds(date), MACHINE_IDENTIFIER, PROCESS_IDENTIFIER, NEXT_COUNTER.getAndIncrement(), false);
}
/**
* Constructs a new instances using the given date and counter.
*
* @param date the date
* @param counter the counter
* @throws IllegalArgumentException if the high order byte of counter is not zero
*/
public ObjectId(final Date date, final int counter) {
this(date, MACHINE_IDENTIFIER, PROCESS_IDENTIFIER, counter);
}
/**
* Constructs a new instances using the given date, machine identifier, process identifier, and counter.
*
* @param date the date
* @param machineIdentifier the machine identifier
* @param processIdentifier the process identifier
* @param counter the counter
* @throws IllegalArgumentException if the high order byte of machineIdentifier or counter is not zero
*/
public ObjectId(final Date date, final int machineIdentifier, final short processIdentifier, final int counter) {
this(dateToTimestampSeconds(date), machineIdentifier, processIdentifier, counter);
}
/**
* Creates an ObjectId using the given time, machine identifier, process identifier, and counter.
*
* @param timestamp the time in seconds
* @param machineIdentifier the machine identifier
* @param processIdentifier the process identifier
* @param counter the counter
* @throws IllegalArgumentException if the high order byte of machineIdentifier or counter is not zero
*/
public ObjectId(final int timestamp, final int machineIdentifier, final short processIdentifier, final int counter) {
this(timestamp, machineIdentifier, processIdentifier, counter, true);
}
private ObjectId(final int timestamp, final int machineIdentifier, final short processIdentifier, final int counter,
final boolean checkCounter) {
if ((machineIdentifier & 0xff000000) != 0) {
throw new IllegalArgumentException("The machine identifier must be between 0 and 16777215 (it must fit in three bytes).");
}
if (checkCounter && ((counter & 0xff000000) != 0)) {
throw new IllegalArg
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
mall.zip (80个子文件)
mall
sdk
pom.xml 3KB
src
main
java
org
exam
sdk
base
Constants.java 163B
ObjectId.java 19KB
domain
Authority.java 2KB
User.java 2KB
Role.java 2KB
service
RoleService.java 517B
UserService.java 577B
AuthorityService.java 457B
util
JSONUtils.java 585B
pom.xml 8KB
app
pom.xml 1KB
src
test
java
org
exam
app
service
RoleServiceTest.java 1KB
AuthorityServiceTest.java 1KB
UserServiceTest.java 2KB
main
resources
logback.xml 581B
config.properties 747B
java
com
alibaba
dubbo
config
spring
AnnotationBean.java 16KB
org
exam
app
config
AppConfig.java 5KB
base
AppServer.java 1KB
repository
AuthorityRepository.java 418B
RoleRepository.java 381B
UserRepository.java 432B
service
UserServiceImpl.java 3KB
RoleServiceImpl.java 2KB
AuthorityServiceImpl.java 2KB
web
pom.xml 3KB
src
test
java
org
exam
web
controller
UserControllerTest.java 1KB
service
RoleServiceTest.java 812B
AuthorityServiceTest.java 1KB
UserServiceTest.java 2KB
main
webapp
WEB-INF
role
list.jsp 2KB
save.jsp 3KB
authority
list.jsp 2KB
user
list.jsp 4KB
save.jsp 2KB
login.jsp 849B
index.jsp 263B
static
jquery
jquery.min.js 139KB
jquery-1.10.2.min.map 144KB
pagination
pagination.css 550B
jquery.pagination.js 10KB
ztree
metroStyle
img
line_conn.png 933B
metro.png 5KB
metro.gif 5KB
loading.gif 381B
metroStyle.css 7KB
zTreeStyle
img
diy
5.png 710B
9.png 467B
1_close.png 601B
1_open.png 580B
6.png 432B
2.png 570B
7.png 534B
4.png 399B
8.png 529B
3.png 762B
zTreeStandard.gif 5KB
line_conn.gif 45B
zTreeStandard.png 11KB
loading.gif 381B
zTreeStyle.css 7KB
jquery.ztree.core-3.5.min.js 45KB
awesomeStyle
img
loading.gif 381B
fa.less 11KB
awesome.css 9KB
awesome.less 10KB
jquery.ztree.excheck-3.5.min.js 17KB
resources
logback.xml 491B
config.properties 115B
java
org
exam
web
config
DispatcherServletInitializer.java 1KB
MvcConfig.java 2KB
AppConfig.java 2KB
base
Constants.java 174B
Auth.java 537B
Authentication.java 600B
AuthInterceptor.java 2KB
controller
AuthorityController.java 1015B
UserController.java 6KB
RoleController.java 7KB
共 80 条
- 1
资源评论
- zhangwei50952016-04-14demo可以跑起来 但是相对比较简陋
xiejx618
- 粉丝: 226
- 资源: 75
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功