DbOid.java

src/net/sourceforge/pain/db/DbOid.java · 1.4 KB

From the archive pain_0_41.zip

Download the archive   « Back to the archive contents

package net.sourceforge.pain.db;

import java.io.*;

/**
 * Serializable DbObject ID
 */
public final class DbOid implements Serializable {

	int indexId;
	long versionId;

	private int hashCode;

	public DbOid() {
		hashCode = 0;
	}

	DbOid(final int indexId, final long versionId) {
		this.indexId = indexId;
		this.versionId = versionId;
		hashCode = 0;
	}

	public String toString() {
		return "[" + indexId + "/" + versionId + "]";
	}

	public boolean equals(final Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof DbOid)) {
			return false;
		}

		final DbOid dbOid = (DbOid) o;

		if (indexId != dbOid.indexId) {
			return false;
		}
		if (versionId != dbOid.versionId) {
			return false;
		}

		return true;
	}


	public int hashCode() {
		if (hashCode == 0) {
			hashCode = generateHashCode();
		}
		return hashCode;
	}

	private int generateHashCode() {
		int result;
		result = indexId;
		result = 29 * result + (int) (versionId ^ (versionId >>> 32));
		result = 29 * result + hashCode;
		return result;
	}

	/** this method use knowledge about PAiN DB internals
	 *  it public only for use with  PAiN Mud Codebase
	 */
	public int getIndexId() {
		return indexId;
	}


	/** this method use knowledge about PAiN DB internals
	 *  it public only for use with  PAiN Mud Codebase
	 */
	public long getVersionId() {
		return versionId;
	}

}


Site Stats

Snippets: 1791
Codebases: 571