KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > properties > LongProperty


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
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
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package gcc.properties;
20
21 import gcc.*;
22
23 public class LongProperty extends PropertyType
24 {
25     private long _defaultValue = 0;
26
27     private long _minimumValue = 0;
28
29     private long _maximumValue = Integer.MAX_VALUE;
30
31     public LongProperty(Class componentClass, String propertyName)
32     {
33         super(componentClass, propertyName);
34     }
35
36     public LongProperty displayName(String displayName)
37     {
38         setDisplayName(displayName);
39         return this;
40     }
41
42     public LongProperty displayOnlyIf(PropertyType other, String value)
43     {
44         setDisplayOnlyIf(other, value);
45         return this;
46     }
47
48     public LongProperty description(String description)
49     {
50         setDescription(description);
51         return this;
52     }
53
54     public LongProperty consoleHelp(String consoleHelp)
55     {
56         setConsoleHelp(consoleHelp);
57         return this;
58     }
59
60     public LongProperty sortOrder(int sortOrder)
61     {
62         setSortOrder(sortOrder);
63         return this;
64     }
65
66     public LongProperty defaultValue(long defaultValue)
67     {
68         _defaultValue = defaultValue;
69         return this;
70     }
71
72     public LongProperty minimumValue(long minimumValue)
73     {
74         _minimumValue = minimumValue;
75         return this;
76     }
77
78     public LongProperty maximumValue(long maximumValue)
79     {
80         _maximumValue = maximumValue;
81         return this;
82     }
83
84     public long getDefaultValue()
85     {
86         return _defaultValue;
87     }
88
89     public String getDefaultValueAsString()
90     {
91         return String.valueOf(_defaultValue);
92     }
93
94     public long getMinimumValue()
95     {
96         return _minimumValue;
97     }
98
99     public long getMaximumValue()
100     {
101         return _maximumValue;
102     }
103
104     public long getLong()
105     {
106         return getLong(null, getComponentProperties());
107     }
108
109     /*
110     public long getLong(Object instance)
111     {
112         return getLong(((Component.InstanceName)instance).getInstanceName(),
113             ((Component.InstanceProperties)instance).getInstanceProperties());
114     }
115     */

116
117     public long getLong(String instanceName, PropertyMap props)
118     {
119         long n;
120         boolean ok = true;
121         String value = props.getProperty(_propertyName, String.valueOf(_defaultValue));
122         try
123         {
124             n = Long.parseLong(value);
125         }
126         catch (NumberFormatException ex)
127         {
128             ok = false;
129             n = 0;
130         }
131         if (n < _minimumValue || n > _maximumValue)
132         {
133             ok = false;
134         }
135         if (! ok)
136         {
137             badPropertyValue(instanceName, value, expectedNumberInRange(_minimumValue, _maximumValue));
138         }
139         logPropertyValue(instanceName, value, n == _defaultValue);
140         return n;
141     }
142 }
143
Popular Tags