History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/javax/management/BetweenQueryExp.java (1 of 18352 files). Show all

Unified · Split

java/pkg/javax/management/BetweenQueryExp.java+142−0
@@ -0,0 +1,142 @@
1+/*
2+ * Copyright (c) 1999, 2008, Oracle and/or its affiliates. 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. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * 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+}