home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-tomcat-addon-1.4.9-installer.exe / jmx.jar / javax / management / BetweenQueryExp.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-10-28  |  2.5 KB  |  74 lines

  1. package javax.management;
  2.  
  3. class BetweenQueryExp extends QueryEval implements QueryExp {
  4.    private static final long serialVersionUID = -2933597532866307444L;
  5.    private ValueExp exp1;
  6.    private ValueExp exp2;
  7.    private ValueExp exp3;
  8.  
  9.    BetweenQueryExp(ValueExp exp1, ValueExp exp2, ValueExp exp3) {
  10.       this.exp1 = exp1;
  11.       this.exp2 = exp2;
  12.       this.exp3 = exp3;
  13.    }
  14.  
  15.    public void setMBeanServer(MBeanServer server) {
  16.       super.setMBeanServer(server);
  17.       if (this.exp1 != null) {
  18.          this.exp1.setMBeanServer(server);
  19.       }
  20.  
  21.       if (this.exp2 != null) {
  22.          this.exp2.setMBeanServer(server);
  23.       }
  24.  
  25.       if (this.exp3 != null) {
  26.          this.exp3.setMBeanServer(server);
  27.       }
  28.  
  29.    }
  30.  
  31.    public boolean apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException, BadAttributeValueExpException, InvalidApplicationException {
  32.       if (this.exp1 != null && this.exp2 != null && this.exp3 != null) {
  33.          ValueExp val1 = this.exp1.apply(name);
  34.          ValueExp val2 = this.exp2.apply(name);
  35.          ValueExp val3 = this.exp3.apply(name);
  36.          if (val1 instanceof NumericValueExp && val2 instanceof NumericValueExp && val3 instanceof NumericValueExp) {
  37.             NumericValueExp num1 = (NumericValueExp)val1;
  38.             NumericValueExp num2 = (NumericValueExp)val2;
  39.             NumericValueExp num3 = (NumericValueExp)val3;
  40.             if (!num1.isDouble() && !num2.isDouble() && !num3.isDouble()) {
  41.                return this.isBetween(new Long(num1.longValue()), new Long(num2.longValue()), new Long(num3.longValue()));
  42.             }
  43.  
  44.             return this.isBetween(new Double(num1.doubleValue()), new Double(num2.doubleValue()), new Double(num3.doubleValue()));
  45.          }
  46.  
  47.          if (val1 instanceof StringValueExp && val2 instanceof StringValueExp && val3 instanceof StringValueExp) {
  48.             String s1 = ((StringValueExp)val1).getValue();
  49.             String s2 = ((StringValueExp)val2).getValue();
  50.             String s3 = ((StringValueExp)val3).getValue();
  51.             return this.isBetween(s1, s2, s3);
  52.          }
  53.       }
  54.  
  55.       return false;
  56.    }
  57.  
  58.    private boolean isBetween(Comparable c1, Comparable c2, Comparable c3) {
  59.       if (c1 == null && c2 == null && c3 == null) {
  60.          return true;
  61.       } else if (c1 != null || c2 != null && c3 != null) {
  62.          if (c1 == null) {
  63.             return false;
  64.          } else if (c1 == null || c2 != null && c3 != null) {
  65.             return c1.compareTo(c2) >= 0 && c1.compareTo(c3) <= 0;
  66.          } else {
  67.             return false;
  68.          }
  69.       } else {
  70.          return true;
  71.       }
  72.    }
  73. }
  74.