01: /*
02: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
03:
04: This file is part of the JODB (Java Objects Database) open source project.
05:
06: JODB is free software; you can redistribute it and/or modify it under
07: the terms of version 2 of the GNU General Public License as published
08: by the Free Software Foundation.
09:
10: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
11: WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: for more details.
14:
15: You should have received a copy of the GNU General Public License along
16: with this program; if not, write to the Free Software Foundation, Inc.,
17: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19: package com.mobixess.jodb.core.query;
20:
21: import com.mobixess.jodb.core.JodbIOException;
22: import com.mobixess.jodb.core.query.SortDataCache.SortNodeRecord;
23:
24: class SortingDataContainer {
25:
26: Object[] _data;
27:
28: /**
29: * @param data
30: */
31: public SortingDataContainer(Object[] data) {
32: super ();
33: _data = data;
34: }
35:
36: public int compareTo(Object o, SortNodeRecord[] nodes)
37: throws JodbIOException {
38: if (o == null || !(o instanceof SortingDataContainer)) {
39: throw new JodbIOException("illegal opeation state");
40: }
41: SortingDataContainer otherObject = (SortingDataContainer) o;
42: if (otherObject._data.length != _data.length) {
43: throw new JodbIOException("illegal opeation state");
44: }
45: for (int i = 0; i < _data.length; i++) {
46: Object compObj = _data[i];
47: Object otherCompObject = otherObject._data[i];
48: if (compObj == null || otherCompObject == null
49: || compObj.getClass() != otherCompObject.getClass()) {
50: throw new JodbIOException("illegal opeation state");
51: }
52: if (!(compObj instanceof Comparable)) {
53: throw new JodbIOException("illegal opeation state");
54: }
55: int result = ((Comparable) compObj)
56: .compareTo(otherCompObject);
57: if (result != 0) {
58: if (!nodes[i].isOrderAscending()) {
59: result *= -1;
60: }
61: return result;
62: }
63: }
64: return 0;
65: }
66:
67: }
|