Path: blob/master/src/java.management/share/classes/javax/management/InQueryExp.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* operations.31* @serial include32*33* @since 1.534*/35class InQueryExp extends QueryEval implements QueryExp {3637/* Serial version */38private static final long serialVersionUID = -5801329450358952434L;3940/**41* @serial The {@link ValueExp} to be found42*/43private ValueExp val;4445/**46* @serial The array of {@link ValueExp} to be searched47*/48private ValueExp[] valueList;495051/**52* Basic Constructor.53*/54public InQueryExp() {55}5657/**58* Creates a new InQueryExp with the specified ValueExp to be found in59* a specified array of ValueExp.60*/61public InQueryExp(ValueExp v1, ValueExp items[]) {62val = v1;63valueList = items;64}656667/**68* Returns the checked value of the query.69*/70public ValueExp getCheckedValue() {71return val;72}7374/**75* Returns the array of values of the query.76*/77public ValueExp[] getExplicitValues() {78return valueList;79}8081/**82* Applies the InQueryExp on a MBean.83*84* @param name The name of the MBean on which the InQueryExp will be applied.85*86* @return True if the query was successfully applied to the MBean, false otherwise.87*88* @exception BadStringOperationException89* @exception BadBinaryOpValueExpException90* @exception BadAttributeValueExpException91* @exception InvalidApplicationException92*/93public boolean apply(ObjectName name)94throws BadStringOperationException, BadBinaryOpValueExpException,95BadAttributeValueExpException, InvalidApplicationException {96if (valueList != null) {97ValueExp v = val.apply(name);98boolean numeric = v instanceof NumericValueExp;99100for (ValueExp element : valueList) {101element = element.apply(name);102if (numeric) {103if (((NumericValueExp) element).doubleValue() ==104((NumericValueExp) v).doubleValue()) {105return true;106}107} else {108if (((StringValueExp) element).getValue().equals(109((StringValueExp) v).getValue())) {110return true;111}112}113}114}115return false;116}117118/**119* Returns the string representing the object.120*/121public String toString() {122return val + " in (" + generateValueList() + ")";123}124125126private String generateValueList() {127if (valueList == null || valueList.length == 0) {128return "";129}130131final StringBuilder result =132new StringBuilder(valueList[0].toString());133134for (int i = 1; i < valueList.length; i++) {135result.append(", ");136result.append(valueList[i]);137}138139return result.toString();140}141142}143144145