01: // kelondroHandle.java
02: // (C) 2003 - 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
03: // first published 2003 on http://yacy.net
04: //
05: // This is a part of YaCy, a peer-to-peer based web search engine
06: //
07: // $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
08: // $LastChangedRevision: 1986 $
09: // $LastChangedBy: orbiter $
10: //
11: // LICENSE
12: //
13: // This program is free software; you can redistribute it and/or modify
14: // it under the terms of the GNU General Public License as published by
15: // the Free Software Foundation; either version 2 of the License, or
16: // (at your option) any later version.
17: //
18: // This program is distributed in the hope that it will be useful,
19: // but WITHOUT ANY WARRANTY; without even the implied warranty of
20: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: // GNU General Public License for more details.
22: //
23: // You should have received a copy of the GNU General Public License
24: // along with this program; if not, write to the Free Software
25: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26:
27: package de.anomic.kelondro;
28:
29: public class kelondroHandle implements Comparable<kelondroHandle> {
30:
31: public final static int NUL = Integer.MIN_VALUE; // the meta value for the kelondroTray' NUL abstraction
32:
33: protected int index;
34:
35: protected kelondroHandle(int i) {
36: assert (i == NUL) || (i >= 0) : "node handle index too low: "
37: + i;
38: //assert (i == NUL) || (i < USAGE.allCount()) : "node handle index too high: " + i + ", USEDC=" + USAGE.USEDC + ", FREEC=" + USAGE.FREEC;
39: this .index = i;
40: //if ((USAGE != null) && (this.index != NUL)) USAGE.allocate(this.index);
41: }
42:
43: public boolean isNUL() {
44: return index == NUL;
45: }
46:
47: public String toString() {
48: if (index == NUL)
49: return "NULL";
50: String s = Integer.toHexString(index);
51: while (s.length() < 4)
52: s = "0" + s;
53: return s;
54: }
55:
56: public boolean equals(kelondroHandle h) {
57: assert (index != NUL);
58: assert (h.index != NUL);
59: return (this .index == h.index);
60: }
61:
62: public boolean equals(Object h) {
63: assert (index != NUL);
64: assert (((kelondroHandle) h).index != NUL);
65: return (this .index == ((kelondroHandle) h).index);
66: }
67:
68: public int compare(kelondroHandle h0, kelondroHandle h1) {
69: assert (((kelondroHandle) h0).index != NUL);
70: assert (((kelondroHandle) h1).index != NUL);
71: if (((kelondroHandle) h0).index < ((kelondroHandle) h1).index)
72: return -1;
73: if (((kelondroHandle) h0).index > ((kelondroHandle) h1).index)
74: return 1;
75: return 0;
76: }
77:
78: public int compareTo(kelondroHandle h) {
79: // this is needed for a TreeMap
80: assert (index != NUL) : "this.index is NUL in compareTo";
81: assert (((kelondroHandle) h).index != NUL) : "handle.index is NUL in compareTo";
82: if (index < ((kelondroHandle) h).index)
83: return -1;
84: if (index > ((kelondroHandle) h).index)
85: return 1;
86: return 0;
87: }
88:
89: public int hashCode() {
90: assert (index != NUL);
91: return this.index;
92: }
93: }
|