Save This Page
Home » openjdk-7 » javax » management » [javadoc | source]
    1   /*
    2    * Copyright 1999-2003 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.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   
   26   package javax.management;
   27   
   28   
   29   /**
   30    * This class is used by the query-building mechanism to represent binary
   31    * relations.
   32    * @serial include
   33    *
   34    * @since 1.5
   35    */
   36   class BetweenQueryExp extends QueryEval implements QueryExp {
   37   
   38       /* Serial version */
   39       private static final long serialVersionUID = -2933597532866307444L;
   40   
   41       /**
   42        * @serial The checked value
   43        */
   44       private ValueExp exp1;
   45   
   46       /**
   47        * @serial The lower bound value
   48        */
   49       private ValueExp exp2;
   50   
   51       /**
   52        * @serial The upper bound value
   53        */
   54       private ValueExp exp3;
   55   
   56   
   57       /**
   58        * Basic Constructor.
   59        */
   60       public BetweenQueryExp() {
   61       }
   62   
   63       /**
   64        * Creates a new BetweenQueryExp with v1 checked value, v2 lower bound
   65        * and v3 upper bound values.
   66        */
   67       public BetweenQueryExp(ValueExp v1, ValueExp v2, ValueExp v3) {
   68           exp1  = v1;
   69           exp2  = v2;
   70           exp3  = v3;
   71       }
   72   
   73   
   74       /**
   75        * Returns the checked value of the query.
   76        */
   77       public ValueExp getCheckedValue()  {
   78           return exp1;
   79       }
   80   
   81       /**
   82        * Returns the lower bound value of the query.
   83        */
   84       public ValueExp getLowerBound()  {
   85           return exp2;
   86       }
   87   
   88       /**
   89        * Returns the upper bound value of the query.
   90        */
   91       public ValueExp getUpperBound()  {
   92           return exp3;
   93       }
   94   
   95       /**
   96        * Applies the BetweenQueryExp on an MBean.
   97        *
   98        * @param name The name of the MBean on which the BetweenQueryExp will be applied.
   99        *
  100        * @return  True if the query was successfully applied to the MBean, false otherwise.
  101        *
  102        * @exception BadStringOperationException
  103        * @exception BadBinaryOpValueExpException
  104        * @exception BadAttributeValueExpException
  105        * @exception InvalidApplicationException
  106        */
  107       public boolean apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,
  108           BadAttributeValueExpException, InvalidApplicationException  {
  109           ValueExp val1 = exp1.apply(name);
  110           ValueExp val2 = exp2.apply(name);
  111           ValueExp val3 = exp3.apply(name);
  112           boolean numeric = val1 instanceof NumericValueExp;
  113   
  114           if (numeric) {
  115               if (((NumericValueExp)val1).isLong()) {
  116                   long lval1 = ((NumericValueExp)val1).longValue();
  117                   long lval2 = ((NumericValueExp)val2).longValue();
  118                   long lval3 = ((NumericValueExp)val3).longValue();
  119                   return lval2 <= lval1 && lval1 <= lval3;
  120               } else {
  121                   double dval1 = ((NumericValueExp)val1).doubleValue();
  122                   double dval2 = ((NumericValueExp)val2).doubleValue();
  123                   double dval3 = ((NumericValueExp)val3).doubleValue();
  124                   return dval2 <= dval1 && dval1 <= dval3;
  125               }
  126   
  127           } else {
  128               String sval1 = ((StringValueExp)val1).getValue();
  129               String sval2 = ((StringValueExp)val2).getValue();
  130               String sval3 = ((StringValueExp)val3).getValue();
  131               return sval2.compareTo(sval1) <= 0 && sval1.compareTo(sval3) <= 0;
  132           }
  133       }
  134   
  135       /**
  136        * Returns the string representing the object.
  137        */
  138       @Override
  139       public String toString()  {
  140           return "(" + exp1 + ") between (" + exp2 + ") and (" + exp3 + ")";
  141       }
  142   
  143       @Override
  144       String toQueryString() {
  145           return exp1 + " between " + exp2 + " and " + exp3;
  146       }
  147   }

Save This Page
Home » openjdk-7 » javax » management » [javadoc | source]