Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/AddressOps.java
41161 views
/*1* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.utilities;2526import sun.jvm.hotspot.debugger.*;2728/** Helper class with operations on addresses. Solves the problem of29one or both of the arguments being null and needing to call30methods like greaterThan(), lessThan(), etc. on them. */3132public class AddressOps {33/** Returns true if a1 is less than a2. Either or both may be null. */34public static boolean lessThan(Address a1, Address a2) {35if (a2 == null) {36return false;37} else if (a1 == null) {38return true;39} else {40return a1.lessThan(a2);41}42}4344/** Returns true if a1 is less than or equal to a2. Either or both may be null. */45public static boolean lessThanOrEqual(Address a1, Address a2) {46if (a2 == null) {47return (a1 == null);48} else if (a1 == null) {49return true;50} else {51return a1.lessThanOrEqual(a2);52}53}5455/** Returns true if a1 is greater than a2. Either or both may be null. */56public static boolean greaterThan(Address a1, Address a2) {57if (a1 == null) {58return false;59} else if (a2 == null) {60return true;61} else {62return a1.greaterThan(a2);63}64}6566/** Returns true if a1 is greater than or equal to a2. Either or both may be null. */67public static boolean greaterThanOrEqual(Address a1, Address a2) {68if (a1 == null) {69return (a2 == null);70} else if (a2 == null) {71return true;72} else {73return a1.greaterThanOrEqual(a2);74}75}7677/** Returns true if a1 is equal to a2. Either or both may be null. */78public static boolean equal(Address a1, Address a2) {79if ((a1 == null) && (a2 == null)) {80return true;81}8283if ((a1 == null) || (a2 == null)) {84return false;85}8687return (a1.equals(a2));88}8990/** Shorthand for {@link #lessThan} */91public static boolean lt(Address a1, Address a2) {92return lessThan(a1, a2);93}9495/** Shorthand for {@link #lessThanOrEqual} */96public static boolean lte(Address a1, Address a2) {97return lessThanOrEqual(a1, a2);98}99100/** Shorthand for {@link #greaterThan} */101public static boolean gt(Address a1, Address a2) {102return greaterThan(a1, a2);103}104105/** Shorthand for {@link #greaterThanOrEqual} */106public static boolean gte(Address a1, Address a2) {107return greaterThanOrEqual(a1, a2);108}109110/** Returns maximum of the two addresses */111public static Address max(Address a1, Address a2) {112return (gt(a1, a2) ? a1 : a2);113}114115/** Returns minimum of the two addresses */116public static Address min(Address a1, Address a2) {117return (lt(a1, a2) ? a1 : a2);118}119}120121122