001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.collection;
022:
023: import org.omg.CosCollection.*;
024:
025: import org.jacorb.collection.util.*;
026:
027: class KeyComparator implements ObjectComparator {
028:
029: private KeyNode current = null;
030:
031: private OperationsOperations ops;
032:
033: KeyComparator(OperationsOperations ops) {
034:
035: this .ops = ops;
036:
037: };
038:
039: public int compare(Object obj1, Object obj2) throws ObjectInvalid {
040:
041: if (obj1 == null || obj2 == null) {
042:
043: throw new ObjectInvalid();
044:
045: }
046:
047: check_object(obj1);
048:
049: check_object(obj2);
050:
051: return ops.key_compare(((KeyNode) obj1).key,
052: ((KeyNode) obj2).key);
053:
054: };
055:
056: public void element(Object obj) throws ObjectInvalid {
057:
058: check_object(obj);
059:
060: current = (KeyNode) obj;
061:
062: };
063:
064: public Object element() {
065:
066: return current;
067:
068: };
069:
070: public int compare_with(Object obj) throws ObjectInvalid {
071:
072: if (current == null || obj == null) {
073:
074: throw new ObjectInvalid();
075:
076: }
077:
078: check_object(obj);
079:
080: return ops.key_compare(current.key, ((KeyNode) obj).key);
081:
082: };
083:
084: public boolean equal(Object obj1, Object obj2) throws ObjectInvalid {
085:
086: if (obj1 == null || obj2 == null) {
087:
088: throw new ObjectInvalid();
089:
090: }
091:
092: check_object(obj1);
093:
094: check_object(obj2);
095:
096: return ops
097: .key_equal(((KeyNode) obj1).key, ((KeyNode) obj2).key);
098:
099: };
100:
101: public boolean equal(Object obj) throws ObjectInvalid {
102:
103: if (current == null || obj == null) {
104:
105: throw new ObjectInvalid();
106:
107: }
108:
109: check_object(obj);
110:
111: return ops.key_equal(current.key, ((KeyNode) obj).key);
112:
113: };
114:
115: private void check_object(Object obj) throws ObjectInvalid {
116:
117: if (!(obj instanceof KeyNode)) {
118:
119: throw new ObjectInvalid();
120:
121: }
122:
123: };
124:
125: };
|