01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1999-2004 Gerald Brose
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Library General Public License for more details.
15: *
16: * You should have received a copy of the GNU Library General Public
17: * License along with this library; if not, write to the Free
18: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19: *
20: */
21: package org.jacorb.collection;
22:
23: import org.omg.CosCollection.OperationsOperations;
24: import org.omg.CORBA.Any;
25: import org.jacorb.collection.util.*;
26:
27: class SequenceComparator implements ObjectComparator {
28: private OperationsOperations ops;
29: private Any current = null;
30:
31: /* ------------------------------------------------------------------------- */
32: SequenceComparator(OperationsOperations ops) {
33: this .ops = ops;
34: }
35:
36: /* ------------------------------------------------------------------------- */
37: public synchronized int compare(Object obj1, Object obj2)
38: throws ObjectInvalid {
39: if (obj1 == null || obj2 == null) {
40: throw new ObjectInvalid();
41: }
42: check_object(obj1);
43: check_object(obj2);
44: return ops.compare((Any) obj1, (Any) obj2);
45: }
46:
47: /* ------------------------------------------------------------------------- */
48: public synchronized void element(Object obj) throws ObjectInvalid {
49: check_object(obj);
50: current = (Any) obj;
51: }
52:
53: /* ------------------------------------------------------------------------- */
54: public synchronized Object element() {
55: return current;
56: }
57:
58: /* ------------------------------------------------------------------------- */
59: public synchronized int compare_with(Object obj)
60: throws ObjectInvalid {
61: if (obj == null || current == null) {
62: throw new ObjectInvalid();
63: }
64: check_object(obj);
65: return ops.compare(current, (Any) obj);
66: }
67:
68: /* ------------------------------------------------------------------------- */
69: public synchronized boolean equal(Object obj1, Object obj2)
70: throws ObjectInvalid {
71: if (obj1 == null || obj2 == null) {
72: throw new ObjectInvalid();
73: }
74: check_object(obj1);
75: check_object(obj2);
76: return ops.equal((Any) obj1, (Any) obj2);
77: }
78:
79: /* ------------------------------------------------------------------------- */
80: public synchronized boolean equal(Object obj1) throws ObjectInvalid {
81: if (obj1 == null || current == null) {
82: throw new ObjectInvalid();
83: }
84: check_object(obj1);
85: return ops.equal(current, (Any) obj1);
86: }
87:
88: /* ------------------------------------------------------------------------- */
89: private void check_object(Object obj) throws ObjectInvalid {
90: if (!(obj instanceof Any)
91: || !((Any) obj).type().equal(ops.element_type())) {
92: throw new ObjectInvalid();
93: }
94: }
95:
96: }
|