001: /*
002: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: * 1. Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * 3. The name of the author may not be used to endorse or promote products
014: * derived from this software without specific prior written permission.
015:
016: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026: *
027: * $Id: AnonId.java,v 1.11 2008/01/02 12:05:48 andy_seaborne Exp $
028: */
029:
030: package com.hp.hpl.jena.rdf.model;
031:
032: import java.rmi.server.UID;
033:
034: import com.hp.hpl.jena.shared.impl.JenaParameters;
035:
036: /** Create a new id for an anonymous node.
037: *
038: * <p>This id is guaranteed to be unique on this machine.</p>
039: *
040: * @author bwm
041: * @version $Name: $ $Revision: 1.11 $ $Date: 2008/01/02 12:05:48 $
042: */
043:
044: // This version contains experimental modifications by der to
045: // switch off normal UID allocation for bNodes to assist tracking
046: // down apparent non-deterministic behaviour.
047: public class AnonId extends java.lang.Object {
048:
049: protected String id = null;
050:
051: /**
052: Support for debugging: global anonID counter. The intial value is just to
053: make the output look prettier if it has lots (but not lots and lots) of bnodes
054: in it.
055: */
056: private static int idCount = 100000;
057:
058: public static AnonId create() {
059: return new AnonId();
060: }
061:
062: public static AnonId create(String id) {
063: return new AnonId(id);
064: }
065:
066: /**
067: Creates new AnonId. Normally this id is guaranteed to be unique on this
068: machine: it is time-dependant. However, sometimes [incorrect] code is
069: sensitive to bnode ordering and produces bizarre bugs (both Dave and
070: Chris have been bitten by this, as have some users, I think). Hence the
071: disableBNodeUIDGeneration flag, which allows bnode IDs to be predictable.
072: */
073: public AnonId() {
074: if (JenaParameters.disableBNodeUIDGeneration) {
075: synchronized (AnonId.class) {
076: id = "A" + idCount++; // + rand.nextLong();
077: }
078: } else {
079: id = (new UID()).toString();
080: }
081: }
082:
083: /** Create a new AnonId from the string argument supplied
084: * @param id A string representation of the id to be created.
085: */
086: public AnonId(String id) {
087: this .id = id;
088: }
089:
090: /** Test whether two id's are the same
091: @param o the object to be compared
092: @return true if and only if the two id's are the same
093: */
094: public boolean equals(Object o) {
095: return o instanceof AnonId && id.equals(((AnonId) o).id);
096: }
097:
098: /** return a string representation of the id
099: * @return a string representation of the id
100: */
101: public String toString() {
102: return id;
103: }
104:
105: /**
106: Answer the label string of this AnonId. To be used in preference to
107: toString().
108: */
109: public String getLabelString() {
110: return id;
111: }
112:
113: /** return a hashcode for this id
114: * @return the hash code
115: */
116: public int hashCode() {
117: return id.hashCode();
118: }
119: }
|