KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > AnonId


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $Id: AnonId.java,v 1.6 2005/02/21 12:13:58 andy_seaborne Exp $
28  */

29
30 package com.hp.hpl.jena.rdf.model;
31
32 import java.rmi.server.UID JavaDoc;
33
34 import com.hp.hpl.jena.shared.impl.JenaParameters;
35
36 /** Create a new id for an anonymous node.
37  *
38  * <p>This id is guaranteed to be unique on this machine.</p>
39  *
40  * @author bwm
41  * @version $Name: $ $Revision: 1.6 $ $Date: 2005/02/21 12:13:58 $
42  */

43
44 // This version contains experimental modifications by der to
45
// switch off normal UID allocation for bNodes to assist tracking
46
// down apparent non-deterministic behaviour.
47

48 public class AnonId extends java.lang.Object JavaDoc {
49     
50     String JavaDoc id = null;
51
52     /**
53         Support for debugging: global anonID counter. The intial value is just to
54         make the output look prettier if it has lots (but not lots and lots) of bnodes
55         in it.
56     */

57     private static int idCount = 100000;
58     
59     /**
60         Creates new AnonId. Normally this id is guaranteed to be unique on this
61         machine: it is time-dependant. However, sometimes [incorrect] code is
62         sensitive to bnode ordering and produces bizarre bugs (both Dave and
63         Chris have been bitten by this, as have some users, I think). Hence the
64         disableBNodeUIDGeneration flag, which allows bnode IDs to be predictable.
65     */

66     public AnonId() {
67         if (JenaParameters.disableBNodeUIDGeneration) {
68             synchronized (AnonId.class) {
69                 id = "A" + idCount++; // + rand.nextLong();
70
}
71         } else {
72             id = (new UID JavaDoc()).toString();
73         }
74     }
75     
76 /** Create a new AnonId from the string argument supplied
77  * @param id A string representation of the id to be created.
78  */

79     public AnonId(String JavaDoc id) {
80         this.id = id;
81     }
82     
83 /** Test whether two id's are the same
84  * @param o the object to be compared
85  * @return true if and only if the two id's are the same
86  */

87     public boolean equals(Object JavaDoc o) {
88         return (o instanceof AnonId && id.equals(((AnonId)o).id));
89     }
90     
91 /** return a string representation of the id
92  * @return a string representation of the id
93  */

94     public String JavaDoc toString() {
95         return id;
96     }
97     
98 /** return a hashcode for this id
99  * @return the hash code
100  */

101     public int hashCode() {
102         return id.hashCode();
103     }
104 }
105
Popular Tags