⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 id.java

📁 发布/订阅系统路由重配算法,可应用于ad hoc环境
💻 JAVA
字号:
/* * project: RebecaSim * package: util * file:    ID.java  * version: 0.1 * date:    31.03.2005 *  * This software is part of the diploma thesis "Ein adaptives Brokernetz  * für Publish/Subscribe Systeme". */package util;/** * The <code>ID</code> class provides identifier objects based on  * <code>long</code> values. * Assuming the same <code>IDGenerator</code> is used, each created  * <code>ID</code> object will be unique (unless the <code>long</code>  * value range is exhausted). * @version 0.1 31.03.2005 * @author  Helge Parzyjegla */public class ID implements Comparable{	/** 	 * The default <code>IDGenerator</code> providing the <code>long</code> 	 * id-values for new <code>ID</code> objects.	 */ 	private static IDGenerator generator = new IDGenerator();		/** The id value. */	private long id;		/**	 * Creates a new ID using the default <code>IDGenerator</code>.	 */	public ID() {		id = generator.getId();	}		/**	 * Creates a new ID using the specified IDGenerator <code>generator</code>. 	 * @param generator the <code>IDGenerator</code> to use.	 */	public ID(IDGenerator generator) {		id = generator.getId();	}	    /**     * Compares this object to the specified object.  The result is     * <code>true</code> if and only if the argument is not     * <code>null</code> and is a <code>ID</code> object that     * is based on the same <code>long</code> id-value as this object.     * @param  o the object to compare with.     * @return <code>true</code> if the objects are the same;     *         <code>false</code> otherwise.     */	public boolean equals(Object o) {		return ( (o instanceof ID) && (this.id == ((ID)o).id) ); 	}    /**     * Returns a hash code for this <code>ID</code>.     * The result is the exclusive OR of the two halves of the primitive     * <code>long</code> value this <code>ID</code> object is based on.     * So it is computed similarly to the hash code of a      * <code>Long</code> object.     * @return a hash code value for this <code>ID</code> object.     */    public int hashCode() {    	return (int)(id ^ (id >>> 32));    }	    /**     * Compares two <code>ID</code> objects by comparing the <code>long</code>     * values numerically the <code>ID</code> objects are based on.     * @param  id the <code>ID</code> object to compare to.     * @return the value <code>0</code> if this <code>ID</code> is     * 		   equal to the argument <code>ID</code>;      *         a value less than <code>0</code> if this <code>ID</code>     *         is numerically less than the argument <code>ID</code>;      *         and a value greater than <code>0</code> if this <code>ID</code>     *         is numerically greater than the argument <code>ID</code>.     */	public int compareTo(ID id) {		return (this.id<id.id ? -1 : (this.id>id.id ? 1 : 0));	}	    /**     * Compares this <code>ID</code> object to another object.  If     * the object is an <code>ID</code>, this function behaves like     * <code>compareTo(ID id)</code>.  Otherwise, it throws a     * <code>ClassCastException</code> (as <code>ID</code> objects     * are comparable only to other <code>ID</code> objects).     * @param  o the <code>Object</code> to compare to.     * @return the value <code>0</code> if this <code>ID</code> is     * 		   equal to the argument <code>ID</code>;      *         a value less than <code>0</code> if this <code>ID</code>     *         is numerically less than the argument <code>ID</code>;      *         and a value greater than <code>0</code> if this <code>ID</code>     *         is numerically greater than the argument <code>ID</code>.     * @throws <code>ClassCastException</code> if the argument is not an     *		   <code>ID</code>.     * @see    java.lang.Comparable     */	public int compareTo(Object o) {		return compareTo((ID)o);	}	/**	 * Sets the default <code>IDGenerator</code> providing the 	 * <code>long</code> id-values for new <code>ID</code> objects.	 * @param  generator the <code>IDGenerator</code> to use.	 * @throws <code>IllegalStateException</code> if the argument is 	 *         <code>null</null>.	 */	public static void setIDGenerator(IDGenerator generator) {		if (generator == null) {			throw new NullPointerException("IDGenerator cannot be set to " +											"null.");		}		ID.generator = generator;	}		/**	 * Resets the default <code>IDGenerator</code> to <code>0</code>.	 */	public static void resetIDGenerator() {		generator.reset();	}		/**	 * Resets the default <code>IDGenerator</code> to <code>value</code>.	 * @param  value <code>long</code> value to set the default	 *         <code>IDGenerator</code> to.	 */	public static void resetIDGenerator(long value) {		generator.reset(value);	}		public long getValue() {		return id;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -