litesoft
Diff Revisions
949
vs
950
for /trunk/Java/KeyHole/src/org/litesoft/aokeyhole/objects/support/PropertyIntPositiveMetaData.java
|
@@ -1,43 +1,43 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.aokeyhole.objects.support; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.aokeyhole.objects.*; |
5 |
|
- |
import org.litesoft.aokeyhole.toolkit.*; |
6 |
|
- |
|
7 |
|
- |
public abstract class PropertyIntPositiveMetaData extends PropertyMetaData { |
8 |
|
- |
public PropertyIntPositiveMetaData( String pName, String pDisplayLabel, Required pRequired, Integer pInitialValue ) { |
9 |
|
- |
super( pName, pDisplayLabel, DataType.INT_POSITIVE, pRequired, parse( pInitialValue ) ); |
10 |
|
- |
} |
11 |
|
- |
|
12 |
|
- |
@Override |
13 |
|
- |
public Object validateAndNormalize( Object pValue ) |
14 |
|
- |
throws ParseException { |
15 |
|
- |
return parse( pValue ); |
16 |
|
- |
} |
17 |
|
- |
|
18 |
|
- |
public static Object parse( Object pValue ) |
19 |
|
- |
throws ParseException { |
20 |
|
- |
if ( pValue == null ) { |
21 |
|
- |
return pValue; |
22 |
|
- |
} |
23 |
|
- |
int iValue; |
24 |
|
- |
if ( pValue instanceof Integer ) { |
25 |
|
- |
iValue = ((Integer) pValue); |
26 |
|
- |
} else { |
27 |
|
- |
String value = trimEmptyToNull( pValue.toString() ); |
28 |
|
- |
if ( value == null ) { |
29 |
|
- |
return value; |
30 |
|
- |
} |
31 |
|
- |
try { |
32 |
|
- |
iValue = Integer.parseInt( value ); |
33 |
|
- |
} |
34 |
|
- |
catch ( NumberFormatException e ) { |
35 |
|
- |
throw new ParseException( value + " is not a valid integer" ); |
36 |
|
- |
} |
37 |
|
- |
} |
38 |
|
- |
if ( iValue < 1 ) { |
39 |
|
- |
throw new ParseException( "" + iValue + " is not a positive integer" ); |
40 |
|
- |
} |
41 |
|
- |
return iValue; |
42 |
|
- |
} |
43 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.aokeyhole.objects.support; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.aokeyhole.objects.*; |
|
5 |
+ |
import org.litesoft.aokeyhole.toolkit.*; |
|
6 |
+ |
|
|
7 |
+ |
public abstract class PropertyIntPositiveMetaData extends PropertyMetaData { |
|
8 |
+ |
public PropertyIntPositiveMetaData( String pName, String pDisplayLabel, Required pRequired, Integer pInitialValue ) { |
|
9 |
+ |
super( pName, pDisplayLabel, DataType.INT_POSITIVE, pRequired, parse( pInitialValue ) ); |
|
10 |
+ |
} |
|
11 |
+ |
|
|
12 |
+ |
@Override |
|
13 |
+ |
public Object validateAndNormalize( Object pValue ) |
|
14 |
+ |
throws ParseException { |
|
15 |
+ |
return parse( pValue ); |
|
16 |
+ |
} |
|
17 |
+ |
|
|
18 |
+ |
public static Object parse( Object pValue ) |
|
19 |
+ |
throws ParseException { |
|
20 |
+ |
if ( pValue == null ) { |
|
21 |
+ |
return pValue; |
|
22 |
+ |
} |
|
23 |
+ |
int iValue; |
|
24 |
+ |
if ( pValue instanceof Integer ) { |
|
25 |
+ |
iValue = ((Integer) pValue); |
|
26 |
+ |
} else { |
|
27 |
+ |
String value = trimEmptyToNull( pValue.toString() ); |
|
28 |
+ |
if ( value == null ) { |
|
29 |
+ |
return value; |
|
30 |
+ |
} |
|
31 |
+ |
try { |
|
32 |
+ |
iValue = Integer.parseInt( value ); |
|
33 |
+ |
} |
|
34 |
+ |
catch ( NumberFormatException e ) { |
|
35 |
+ |
throw new ParseException( value + " is not a valid integer" ); |
|
36 |
+ |
} |
|
37 |
+ |
} |
|
38 |
+ |
if ( iValue < 1 ) { |
|
39 |
+ |
throw new ParseException( "" + iValue + " is not a positive integer" ); |
|
40 |
+ |
} |
|
41 |
+ |
return iValue; |
|
42 |
+ |
} |
|
43 |
+ |
} |