|
@@ -1,58 +1,58 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.bo.attributes; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
5 |
|
- |
import org.litesoft.core.simpletypes.*; |
6 |
|
- |
|
7 |
|
- |
import java.util.*; |
8 |
|
- |
|
9 |
|
- |
public class FormatControl implements PropertyOfAMD { |
10 |
|
- |
public static FormatControl of( String pFormat ) { |
11 |
|
- |
return null != (pFormat = Strings.noEmpty( pFormat )) ? getInstance( pFormat ) : null; |
12 |
|
- |
} |
13 |
|
- |
|
14 |
|
- |
public static NumericFormatControl get( AttributeMetaData pAMD ) { |
15 |
|
- |
PropertyOfAMD zProperty = pAMD.getProperties().get( MAP_KEY ); |
16 |
|
- |
if ( zProperty != null ) { |
17 |
|
- |
return ((FormatControl) zProperty).mValue; |
18 |
|
- |
} |
19 |
|
- |
return null; |
20 |
|
- |
} |
21 |
|
- |
|
22 |
|
- |
private static synchronized FormatControl getInstance( String pFormat ) { |
23 |
|
- |
FormatControl zInstance = sInstances.get( pFormat ); |
24 |
|
- |
if ( zInstance == null ) { |
25 |
|
- |
sInstances.put( pFormat, zInstance = new FormatControl( NumericFormatControl.rehydrate( pFormat ) ) ); |
26 |
|
- |
} |
27 |
|
- |
return zInstance; |
28 |
|
- |
} |
29 |
|
- |
|
30 |
|
- |
private static HashMap<String, FormatControl> sInstances = new HashMap<String, FormatControl>(); |
31 |
|
- |
|
32 |
|
- |
private static final String MAP_KEY = "FormatControl"; |
33 |
|
- |
|
34 |
|
- |
private FormatControl( NumericFormatControl pValue ) { |
35 |
|
- |
mValue = pValue; |
36 |
|
- |
} |
37 |
|
- |
|
38 |
|
- |
private NumericFormatControl mValue; |
39 |
|
- |
|
40 |
|
- |
@Override |
41 |
|
- |
public String toString() { |
42 |
|
- |
return MAP_KEY + ".of( \"" + mValue.desiccate() + "\" )"; |
43 |
|
- |
} |
44 |
|
- |
|
45 |
|
- |
public String getMapKey() { |
46 |
|
- |
return MAP_KEY; |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
@Override |
50 |
|
- |
public boolean equals( Object them ) { |
51 |
|
- |
return (this == them) || ((them != null) && (this.getClass() == them.getClass()) && (this.mValue == ((FormatControl) them).mValue)); |
52 |
|
- |
} |
53 |
|
- |
|
54 |
|
- |
@Override |
55 |
|
- |
public int hashCode() { |
56 |
|
- |
return mValue.hashCode(); |
57 |
|
- |
} |
58 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.bo.attributes; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
5 |
+ |
import org.litesoft.core.simpletypes.*; |
|
6 |
+ |
|
|
7 |
+ |
import java.util.*; |
|
8 |
+ |
|
|
9 |
+ |
public class FormatControl implements PropertyOfAMD { |
|
10 |
+ |
public static FormatControl of( String pFormat ) { |
|
11 |
+ |
return null != (pFormat = ConstrainTo.significantOrNull( pFormat )) ? getInstance( pFormat ) : null; |
|
12 |
+ |
} |
|
13 |
+ |
|
|
14 |
+ |
public static NumericFormatControl get( AttributeMetaData pAMD ) { |
|
15 |
+ |
PropertyOfAMD zProperty = pAMD.getProperties().get( MAP_KEY ); |
|
16 |
+ |
if ( zProperty != null ) { |
|
17 |
+ |
return ((FormatControl) zProperty).mValue; |
|
18 |
+ |
} |
|
19 |
+ |
return null; |
|
20 |
+ |
} |
|
21 |
+ |
|
|
22 |
+ |
private static synchronized FormatControl getInstance( String pFormat ) { |
|
23 |
+ |
FormatControl zInstance = sInstances.get( pFormat ); |
|
24 |
+ |
if ( zInstance == null ) { |
|
25 |
+ |
sInstances.put( pFormat, zInstance = new FormatControl( NumericFormatControl.rehydrate( pFormat ) ) ); |
|
26 |
+ |
} |
|
27 |
+ |
return zInstance; |
|
28 |
+ |
} |
|
29 |
+ |
|
|
30 |
+ |
private static HashMap<String, FormatControl> sInstances = new HashMap<String, FormatControl>(); |
|
31 |
+ |
|
|
32 |
+ |
private static final String MAP_KEY = "FormatControl"; |
|
33 |
+ |
|
|
34 |
+ |
private FormatControl( NumericFormatControl pValue ) { |
|
35 |
+ |
mValue = pValue; |
|
36 |
+ |
} |
|
37 |
+ |
|
|
38 |
+ |
private NumericFormatControl mValue; |
|
39 |
+ |
|
|
40 |
+ |
@Override |
|
41 |
+ |
public String toString() { |
|
42 |
+ |
return MAP_KEY + ".of( \"" + mValue.desiccate() + "\" )"; |
|
43 |
+ |
} |
|
44 |
+ |
|
|
45 |
+ |
public String getMapKey() { |
|
46 |
+ |
return MAP_KEY; |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
@Override |
|
50 |
+ |
public boolean equals( Object them ) { |
|
51 |
+ |
return (this == them) || ((them != null) && (this.getClass() == them.getClass()) && (this.mValue == ((FormatControl) them).mValue)); |
|
52 |
+ |
} |
|
53 |
+ |
|
|
54 |
+ |
@Override |
|
55 |
+ |
public int hashCode() { |
|
56 |
+ |
return mValue.hashCode(); |
|
57 |
+ |
} |
|
58 |
+ |
} |