01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: /*
20: * Created on May 5, 2003
21: */
22: package org.apache.jmeter.testelement.property;
23:
24: /**
25: * @author ano ano
26: * @version $Revision: 493779 $
27: */
28: public abstract class NumberProperty extends AbstractProperty {
29: public NumberProperty() {
30: super ();
31: }
32:
33: public NumberProperty(String name) {
34: super (name);
35: }
36:
37: /**
38: * Set the value of the property with a Number object.
39: */
40: protected abstract void setNumberValue(Number n);
41:
42: /**
43: * Set the value of the property with a String object.
44: */
45: protected abstract void setNumberValue(String n)
46: throws NumberFormatException;
47:
48: public void setObjectValue(Object v) {
49: if (v instanceof Number) {
50: setNumberValue((Number) v);
51: } else {
52: try {
53: setNumberValue(v.toString());
54: } catch (RuntimeException e) {
55: }
56: }
57: }
58:
59: /**
60: * @see Comparable#compareTo(Object)
61: */
62: public int compareTo(Object arg0) {
63: if (arg0 instanceof JMeterProperty) {
64: double compareValue = getDoubleValue()
65: - ((JMeterProperty) arg0).getDoubleValue();
66:
67: if (compareValue < 0) {
68: return -1;
69: } else if (compareValue == 0) {
70: return 0;
71: } else {
72: return 1;
73: }
74: } else {
75: return -1;
76: }
77: }
78: }
|