0
|
1 /*
|
|
2 * Copyright 2000-2002 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 package sun.jvm.hotspot.utilities;
|
|
26
|
|
27 import sun.jvm.hotspot.debugger.*;
|
|
28
|
|
29 /** Helper class with operations on addresses. Solves the problem of
|
|
30 one or both of the arguments being null and needing to call
|
|
31 methods like greaterThan(), lessThan(), etc. on them. */
|
|
32
|
|
33 public class AddressOps {
|
|
34 /** Returns true if a1 is less than a2. Either or both may be null. */
|
|
35 public static boolean lessThan(Address a1, Address a2) {
|
|
36 if (a2 == null) {
|
|
37 return false;
|
|
38 } else if (a1 == null) {
|
|
39 return true;
|
|
40 } else {
|
|
41 return a1.lessThan(a2);
|
|
42 }
|
|
43 }
|
|
44
|
|
45 /** Returns true if a1 is less than or equal to a2. Either or both may be null. */
|
|
46 public static boolean lessThanOrEqual(Address a1, Address a2) {
|
|
47 if (a2 == null) {
|
|
48 return (a1 == null);
|
|
49 } else if (a1 == null) {
|
|
50 return true;
|
|
51 } else {
|
|
52 return a1.lessThanOrEqual(a2);
|
|
53 }
|
|
54 }
|
|
55
|
|
56 /** Returns true if a1 is greater than a2. Either or both may be null. */
|
|
57 public static boolean greaterThan(Address a1, Address a2) {
|
|
58 if (a1 == null) {
|
|
59 return false;
|
|
60 } else if (a2 == null) {
|
|
61 return true;
|
|
62 } else {
|
|
63 return a1.greaterThan(a2);
|
|
64 }
|
|
65 }
|
|
66
|
|
67 /** Returns true if a1 is greater than or equal to a2. Either or both may be null. */
|
|
68 public static boolean greaterThanOrEqual(Address a1, Address a2) {
|
|
69 if (a1 == null) {
|
|
70 return (a2 == null);
|
|
71 } else if (a2 == null) {
|
|
72 return true;
|
|
73 } else {
|
|
74 return a1.greaterThanOrEqual(a2);
|
|
75 }
|
|
76 }
|
|
77
|
|
78 /** Returns true if a1 is equal to a2. Either or both may be null. */
|
|
79 public static boolean equal(Address a1, Address a2) {
|
|
80 if ((a1 == null) && (a2 == null)) {
|
|
81 return true;
|
|
82 }
|
|
83
|
|
84 if ((a1 == null) || (a2 == null)) {
|
|
85 return false;
|
|
86 }
|
|
87
|
|
88 return (a1.equals(a2));
|
|
89 }
|
|
90
|
|
91 /** Shorthand for {@link #lessThan} */
|
|
92 public static boolean lt(Address a1, Address a2) {
|
|
93 return lessThan(a1, a2);
|
|
94 }
|
|
95
|
|
96 /** Shorthand for {@link #lessThanOrEqual} */
|
|
97 public static boolean lte(Address a1, Address a2) {
|
|
98 return lessThanOrEqual(a1, a2);
|
|
99 }
|
|
100
|
|
101 /** Shorthand for {@link #greaterThan} */
|
|
102 public static boolean gt(Address a1, Address a2) {
|
|
103 return greaterThan(a1, a2);
|
|
104 }
|
|
105
|
|
106 /** Shorthand for {@link #greaterThanOrEqual} */
|
|
107 public static boolean gte(Address a1, Address a2) {
|
|
108 return greaterThanOrEqual(a1, a2);
|
|
109 }
|
|
110
|
|
111 /** Returns maximum of the two addresses */
|
|
112 public static Address max(Address a1, Address a2) {
|
|
113 return (gt(a1, a2) ? a1 : a2);
|
|
114 }
|
|
115
|
|
116 /** Returns minimum of the two addresses */
|
|
117 public static Address min(Address a1, Address a2) {
|
|
118 return (lt(a1, a2) ? a1 : a2);
|
|
119 }
|
|
120 }
|