KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > testelement > property > NumberProperty


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testelement/property/NumberProperty.java,v 1.3 2004/02/13 02:40:53 sebb Exp $
2
/*
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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: 1.3 $
27  */

28 public abstract class NumberProperty extends AbstractProperty
29 {
30     public NumberProperty()
31     {
32         super();
33     }
34
35     public NumberProperty(String JavaDoc name)
36     {
37         super(name);
38     }
39
40     /**
41      * Set the value of the property with a Number object.
42      */

43     protected abstract void setNumberValue(Number JavaDoc n);
44
45     /**
46      * Set the value of the property with a String object.
47      */

48     protected abstract void setNumberValue(String JavaDoc n)
49         throws NumberFormatException JavaDoc;
50
51     public void setObjectValue(Object JavaDoc v)
52     {
53         if (v instanceof Number JavaDoc)
54         {
55             setNumberValue((Number JavaDoc) v);
56         }
57         else
58         {
59             try
60             {
61                 setNumberValue(v.toString());
62             }
63             catch (RuntimeException JavaDoc e)
64             {
65             }
66         }
67     }
68     
69     /**
70      * @see Comparable#compareTo(Object)
71      */

72     public int compareTo(Object JavaDoc arg0)
73     {
74         if(arg0 instanceof JMeterProperty)
75         {
76             double compareValue =
77                 getDoubleValue() - ((JMeterProperty) arg0).getDoubleValue();
78
79             if(compareValue < 0)
80             {
81                 return -1;
82             }
83             else if(compareValue == 0)
84             {
85                 return 0;
86             }
87             else
88             {
89                 return 1;
90             }
91         }
92         else
93         {
94             return -1;
95         }
96     }
97 }
98
Popular Tags