package edu.exam.online.professional.utils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.net.NetworkInterface;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.Enumeration;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
/**
* A globally unique identifier for objects.
* <p>Consists of 12 bytes, divided as follows:
* <blockquote><pre>
* <table border="1">
* <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>
* </pre></blockquote>
*
* @guodandan objectids
*/
public class ObjectId implements Comparable<ObjectId>, java.io.Serializable {
private static final long serialVersionUID = -4415279469780082174L;
public static Logger log = LogManager.getLogger(ObjectId.class.getName());
/**
* 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</code>.
*
* @return whether the string could be an object id
*/
public static boolean isValid(String s) {
if (s == null)
return false;
final int len = s.length();
if (len != 24)
return false;
for (int i = 0; i < len; i++) {
char c = s.charAt(i);
if (c >= '0' && c <= '9')
continue;
if (c >= 'a' && c <= 'f')
continue;
if (c >= 'A' && c <= 'F')
continue;
return false;
}
return true;
}
/**
* Turn an object into an <code>ObjectId</code>, if possible.
* Strings will be converted into <code>ObjectId</code>s, if possible, and <code>ObjectId</code>s will
* be cast and returned. Passing in <code>null</code> returns <code>null</code>.
*
* @param o the object to convert
* @return an <code>ObjectId</code> if it can be massaged, null otherwise
*/
public static ObjectId massageToObjectId(Object o) {
if (o == null)
return null;
if (o instanceof ObjectId)
return (ObjectId) o;
if (o instanceof String) {
String s = o.toString();
if (isValid(s))
return new ObjectId(s);
}
return null;
}
public ObjectId(Date time) {
this(time, _genmachine, _nextInc.getAndIncrement());
}
public ObjectId(Date time, int inc) {
this(time, _genmachine, inc);
}
public ObjectId(Date time, int machine, int inc) {
_time = (int) (time.getTime() / 1000);
_machine = machine;
_inc = inc;
_new = false;
}
/**
* Creates a new instance from a string.
*
* @param s the string to convert
* @throws IllegalArgumentException if the string is not a valid id
*/
public ObjectId(String s) {
this(s, false);
}
public ObjectId(String s, boolean babble) {
if (!isValid(s))
throw new IllegalArgumentException("invalid ObjectId [" + s + "]");
if (babble)
s = babbleToMongod(s);
byte b[] = new byte[12];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16);
}
ByteBuffer bb = ByteBuffer.wrap(b);
_time = bb.getInt();
_machine = bb.getInt();
_inc = bb.getInt();
_new = false;
}
public ObjectId(byte[] b) {
if (b.length != 12)
throw new IllegalArgumentException("need 12 bytes");
ByteBuffer bb = ByteBuffer.wrap(b);
_time = bb.getInt();
_machine = bb.getInt();
_inc = bb.getInt();
_new = false;
}
/**
* Creates an ObjectId
*
* @param time time in seconds
* @param machine machine ID
* @param inc incremental value
*/
public ObjectId(int time, int machine, int inc) {
_time = time;
_machine = machine;
_inc = inc;
_new = false;
}
/**
* Create a new object id.
*/
public ObjectId() {
_time = (int) (System.currentTimeMillis() / 1000);
_machine = _genmachine;
_inc = _nextInc.getAndIncrement();
_new = true;
}
public int hashCode() {
int x = _time;
x += (_machine * 111);
x += (_inc * 17);
return x;
}
public boolean equals(Object o) {
if (this == o)
return true;
ObjectId other = massageToObjectId(o);
if (other == null)
return false;
return
_time == other._time &&
_machine == other._machine &&
_inc == other._inc;
}
public String toStringBabble() {
return babbleToMongod(toStringMongod());
}
public String toStringMongod() {
byte b[] = toByteArray();
StringBuilder buf = new StringBuilder(24);
for (int i = 0; i < b.length; i++) {
int x = b[i] & 0xFF;
String s = Integer.toHexString(x);
if (s.length() == 1)
buf.append("0");
buf.append(s);
}
return buf.toString();
}
public byte[] toByteArray() {
byte b[] = new byte[12];
ByteBuffer bb = ByteBuffer.wrap(b);
// by default BB is big endian like we need
bb.putInt(_time);
bb.putInt(_machine);
bb.putInt(_inc);
return b;
}
static String _pos(String s, int p) {
return s.substring(p * 2, (p * 2) + 2);
}
public static String babbleToMongod(String b) {
if (!isValid(b))
throw new IllegalArgumentException("invalid object id: " + b);
StringBuilder buf = new StringBuilder(24);
for (int i = 7; i >= 0; i--)
buf.append(_pos(b, i));
for (int i = 11; i >= 8; i--)
buf.append(_pos(b, i));
return buf.toString();
}
public String toString() {
return toStringMongod();
}
int _compareUnsigned(int i, int j) {
long li = 0xFFFFFFFFL;
li = i & li;
long lj = 0xFFFFFFFFL;
lj = j & lj;
long diff = li - lj;
if (diff < Integer.MIN_VALUE)
return Integer.MIN_VALUE;
if (diff > Integer.MAX_VALUE)
return Integer.MAX_VALUE;
return (int) diff;
}
public int compareTo(ObjectId id) {
if (id == null)
return -1;
int x = _compareUnsigned(_time, id._time);
if (x != 0)
return x;
x = _compareUnsigned(_machine, id._machine);
if (x != 0)
return x;
return _compareUnsigned(_inc, id._inc);
}
public int getMachine() {
return _machine;
}
/**
* Gets the time of this ID, in milliseconds
*/
public long getTime() {
return _time * 1000L;
}
/**
* Gets the time of this ID, in seconds
*/
public int getTimeSecond() {
return _time;
}
public int getInc() {
return _inc;
}
public int _time() {
return _time;
}
public int _machine() {
return _machine;
}
public int _inc() {
return _inc;
}
public boolean isNew() {
return _new;
}
public void notNew() {
_new = false;
}
/**
* Gets the generated machine ID, identifying the machine / process / class loader
*/
public static int getGenMachineId() {
return _genmachine;
}
/**
* Gets the current value of the auto increment
*/
public static int g
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该套系统是一套集考试题库管理、考试信息管理和考试成绩管理三位一体的综合性考试管理系统。 做毕业设计,课程设计或者正在学习相关技术知识的朋友可以下载资源学习。想继续学习相关知识的可以关注我。 技术说明 前端使用技术: AngularJS--数据双向绑定 jQuery--优秀的Javascript库 及其基于jQuery的相关组件 后端使用技术: Spring MVC--MVC架构的Controller层 Spring --MVC架构的Sevice、Domain层 MyBtais --MVC架构的Dao层 Mysql --最流行开源的关系型数据库 创建数据库 1、创建数据库:opp CREATE DATABASE opp; USE opp; 创建数据库表: 导入webapp/sql文件的opp.sql文件 2、mysql账号密码在db.properties文件中修改 jdbc.username = root jdbc.password = root
资源推荐
资源详情
资源评论
收起资源包目录
计算机在线考试系统 附源码和文档 (403个子文件)
bootstrap.css 140KB
bootstrap.css 140KB
thememenu.css 37KB
theme.css 36KB
theme.css 36KB
select2.css 17KB
select2.css 17KB
jquery.dataTables.css 15KB
font-awesome.min.css 14KB
font-awesome.min.css 14KB
bootstrap-datetimepicker.css 12KB
layer.css 11KB
layer.css 11KB
fullcalendar.css 10KB
fullcalendar.css 10KB
alertify.css 7KB
alertify.css 7KB
datepicker.css 4KB
datepicker.css 4KB
layer.ext.css 3KB
layer.ext.css 3KB
colorpicker.css 2KB
colorpicker.css 2KB
facybox.css 2KB
facybox.css 2KB
timepicker.css 2KB
timepicker.css 2KB
fullcalendar.print.css 1KB
fullcalendar.print.css 1KB
opp-app.css 135B
default.css 21B
fontawesome-webfont.eot 27KB
fontawesome-webfont.eot 27KB
fontawesome-webfont.eot@ 27KB
fontawesome-webfont.eot@ 27KB
loading-0.gif 6KB
loading-0.gif 6KB
spinner.gif 2KB
spinner.gif 2KB
loading-2.gif 2KB
loading-2.gif 2KB
loading-1.gif 701B
loading-1.gif 701B
examinee.htm 6KB
index.htm 4KB
index.html 40KB
index-2.html 40KB
ui_features.html 38KB
forms.html 37KB
tables.html 24KB
users.html 24KB
buttons.html 22KB
tasks.html 19KB
organization_exam.html 19KB
analytics.html 18KB
examinee.html 17KB
examinee_batch.html 16KB
make_test.html 15KB
multiple_choice.html 15KB
single_choice.html 15KB
analytics_examinee.html 15KB
tickets.html 14KB
judge_choice.html 13KB
404.html 12KB
analytics_exam.html 12KB
gallery.html 12KB
notifications.html 12KB
score_examinee.html 11KB
score_exam.html 11KB
mysetting.html 11KB
setting.html 10KB
exam.html 10KB
online_exam.html 10KB
500.html 9KB
history_exam.html 8KB
calendar.html 8KB
index_admin.html 7KB
index_examinee.html 7KB
score_personal.html 7KB
openexam.html 6KB
400.html 5KB
login.html 4KB
new_account.html 4KB
login.html 4KB
menu.html 3KB
test.html 2KB
navbar.html 1KB
jquery.elfinder.min.html 1006B
jquery.elfinder.min.html 1006B
favicon.html 993B
favicon.html 993B
index-o.html 698B
favicon.ico 894B
favicon.ico 894B
favicon.ico 894B
favicon.ico 894B
favicon.ico 894B
dataSources.ids 10KB
opp.iml 6KB
aopalliance-1.0-sources.jar 21KB
共 403 条
- 1
- 2
- 3
- 4
- 5
资源评论
- qq_351746972017-02-17请问博主这个项目怎么运行,我平常都是用eclipse开发,没见过这样的项目结构,请博主指导万分感激
- qq_338242742018-10-11东西很好 哈哈
huangyueranbbc
- 粉丝: 587
- 资源: 214
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab开发的根据rvm回归模型自己编的matlab程序.rar
- 高效C++学生成绩管理系统:教育技术+C++17编程+数据管理+教务自动化
- 基于matlab开发的Tipping的相关向量机RVM的回归MATLAB程序,有英文注释,可以运行.rar
- 一个点击正反转程序实例,可实现案件电机正反转
- 搜索链接淘特搜索引擎共享版-tot-search-engine.rar
- 第十八届全国大学生智能汽车竞赛 摄像头组/镜头组
- 基于matlab开发的AUV惯性导航系统matlab仿真程序,包括轨迹生成、gps和sins组合、gps和dvl组合.rar
- 基于SSM的“个性化电子相册”的设计与实现.zip
- 如何在撰写科研文献时,使用ai工具辅助去完成科研工作
- 吉林大学计组笔记 自用 基于b站翼云图灵的课.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功