01: /*
02: *
03: *
04: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
05: * Reserved. Use is subject to license terms.
06: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License version
10: * 2 only, as published by the Free Software Foundation.
11: *
12: * This program is distributed in the hope that it will be useful, but
13: * WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License version 2 for more details (a copy is
16: * included at /legal/license.txt).
17: *
18: * You should have received a copy of the GNU General Public License
19: * version 2 along with this work; if not, write to the Free Software
20: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21: * 02110-1301 USA
22: *
23: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
24: * Clara, CA 95054 or visit www.sun.com if you need additional
25: * information or have any questions.
26: *
27: * Copyright 2000 Motorola, Inc. All Rights Reserved.
28: * This notice does not imply publication.
29: */
30:
31: package javax.microedition.rms;
32:
33: /**
34: * An interface defining a comparator which compares two records (in an
35: * implementation-defined manner) to see if they match or what their
36: * relative sort order is. The application implements this interface
37: * to compare two candidate records. The return value must indicate
38: * the ordering of the two records. The compare method is called by
39: * RecordEnumeration to sort and return records in an application
40: * specified order. For example:
41: * <pre>
42: * RecordComparator c = new AddressRecordComparator();
43: * if (c.compare(recordStore.getRecord(rec1), recordStore.getRecord(rec2))
44: * == RecordComparator.PRECEDES)
45: * return rec1;
46: * </pre>
47: *
48: * @since MIDP 1.0
49: */
50:
51: public interface RecordComparator {
52: /**
53: * EQUIVALENT means that in terms of search or sort order, the
54: * two records are the same. This does not necessarily mean that
55: * the two records are identical.
56: * <P>The value of EQUIVALENT is 0.</P>
57: */
58: public static final int EQUIVALENT = 0;
59:
60: /**
61: * FOLLOWS means that the left (first parameter) record <em>follows</em>
62: * the right (second parameter) record in terms of search or
63: * sort order.
64: * <P>The value of FOLLOWS is 1.</P>
65: */
66: public static final int FOLLOWS = 1;
67:
68: /**
69: * PRECEDES means that the left (first parameter) record <em>precedes</em>
70: * the right (second parameter) record in terms of search or
71: * sort order.
72: * <P>The value of PRECEDES is -1.</P>
73: */
74: public static final int PRECEDES = -1;
75:
76: /**
77: * Returns <code>RecordComparator.PRECEDES</code> if rec1
78: * precedes rec2 in sort order, or <code>RecordComparator.FOLLOWS</code>
79: * if rec1 follows rec2 in sort order, or
80: * <code>RecordComparator.EQUIVALENT</code> if rec1 and rec2
81: * are equivalent in terms of sort order.
82: *
83: * @param rec1 the first record to use for comparison. Within this
84: * method, the application must treat this parameter as
85: * read-only.
86: * @param rec2 the second record to use for comparison. Within
87: * this method, the application must treat this parameter
88: * as read-only.
89: * @return <code>RecordComparator.PRECEDES</code> if rec1 precedes
90: * rec2 in sort order, or
91: * <code>RecordComparator.FOLLOWS</code> if rec1 follows
92: * rec2 in sort order, or
93: * <code>RecordComparator.EQUIVALENT</code> if rec1 and
94: * rec2 are equivalent in terms of sort order
95: */
96: public abstract int compare(byte[] rec1, byte[] rec2);
97:
98: }
|