Path: blob/master/src/java.management/share/classes/javax/management/BetweenQueryExp.java
41155 views
/*1* Copyright (c) 1999, 2008, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.management;262728/**29* This class is used by the query-building mechanism to represent binary30* relations.31* @serial include32*33* @since 1.534*/35class BetweenQueryExp extends QueryEval implements QueryExp {3637/* Serial version */38private static final long serialVersionUID = -2933597532866307444L;3940/**41* @serial The checked value42*/43private ValueExp exp1;4445/**46* @serial The lower bound value47*/48private ValueExp exp2;4950/**51* @serial The upper bound value52*/53private ValueExp exp3;545556/**57* Basic Constructor.58*/59public BetweenQueryExp() {60}6162/**63* Creates a new BetweenQueryExp with v1 checked value, v2 lower bound64* and v3 upper bound values.65*/66public BetweenQueryExp(ValueExp v1, ValueExp v2, ValueExp v3) {67exp1 = v1;68exp2 = v2;69exp3 = v3;70}717273/**74* Returns the checked value of the query.75*/76public ValueExp getCheckedValue() {77return exp1;78}7980/**81* Returns the lower bound value of the query.82*/83public ValueExp getLowerBound() {84return exp2;85}8687/**88* Returns the upper bound value of the query.89*/90public ValueExp getUpperBound() {91return exp3;92}9394/**95* Applies the BetweenQueryExp on an MBean.96*97* @param name The name of the MBean on which the BetweenQueryExp will be applied.98*99* @return True if the query was successfully applied to the MBean, false otherwise.100*101* @exception BadStringOperationException102* @exception BadBinaryOpValueExpException103* @exception BadAttributeValueExpException104* @exception InvalidApplicationException105*/106public boolean apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,107BadAttributeValueExpException, InvalidApplicationException {108ValueExp val1 = exp1.apply(name);109ValueExp val2 = exp2.apply(name);110ValueExp val3 = exp3.apply(name);111boolean numeric = val1 instanceof NumericValueExp;112113if (numeric) {114if (((NumericValueExp)val1).isLong()) {115long lval1 = ((NumericValueExp)val1).longValue();116long lval2 = ((NumericValueExp)val2).longValue();117long lval3 = ((NumericValueExp)val3).longValue();118return lval2 <= lval1 && lval1 <= lval3;119} else {120double dval1 = ((NumericValueExp)val1).doubleValue();121double dval2 = ((NumericValueExp)val2).doubleValue();122double dval3 = ((NumericValueExp)val3).doubleValue();123return dval2 <= dval1 && dval1 <= dval3;124}125126} else {127String sval1 = ((StringValueExp)val1).getValue();128String sval2 = ((StringValueExp)val2).getValue();129String sval3 = ((StringValueExp)val3).getValue();130return sval2.compareTo(sval1) <= 0 && sval1.compareTo(sval3) <= 0;131}132}133134/**135* Returns the string representing the object.136*/137@Override138public String toString() {139return "(" + exp1 + ") between (" + exp2 + ") and (" + exp3 + ")";140}141}142143144