|
@@ -1,75 +1,75 @@ |
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.Objects; |
5 |
|
- |
|
6 |
|
- |
import java.util.*; |
7 |
|
- |
|
8 |
|
- |
public class Options implements PropertyOfAMD { |
9 |
|
- |
public static Options of( String... pOptions ) { |
10 |
|
- |
return Objects.isNotNullOrEmpty( pOptions ) ? new Options( pOptions ) : null; |
11 |
|
- |
} |
12 |
|
- |
|
13 |
|
- |
public static String[] get( AttributeMetaData pAMD ) { |
14 |
|
- |
PropertyOfAMD zProperty = pAMD.getProperties().get( MAP_KEY ); |
15 |
|
- |
if ( zProperty != null ) { |
16 |
|
- |
return ((Options) zProperty).mValue; |
17 |
|
- |
} |
18 |
|
- |
return null; |
19 |
|
- |
} |
20 |
|
- |
|
21 |
|
- |
public static Integer getLength( AttributeMetaData pAMD ) { |
22 |
|
- |
PropertyOfAMD zProperty = pAMD.getProperties().get( MAP_KEY ); |
23 |
|
- |
if ( zProperty != null ) { |
24 |
|
- |
return ((Options) zProperty).getLength(); |
25 |
|
- |
} |
26 |
|
- |
return null; |
27 |
|
- |
} |
28 |
|
- |
|
29 |
|
- |
private static final String MAP_KEY = "Options"; |
30 |
|
- |
|
31 |
|
- |
private Integer mLength; |
32 |
|
- |
|
33 |
|
- |
private Integer getLength() { |
34 |
|
- |
if ( mLength == null ) { |
35 |
|
- |
int zMax = 2; |
36 |
|
- |
for ( String zEntry : mValue ) { |
37 |
|
- |
if ( zEntry != null ) { |
38 |
|
- |
zMax = Math.max( zMax, zEntry.length() ); |
39 |
|
- |
} |
40 |
|
- |
} |
41 |
|
- |
mLength = zMax; |
42 |
|
- |
} |
43 |
|
- |
return mLength; |
44 |
|
- |
} |
45 |
|
- |
|
46 |
|
- |
private Options( String[] pValue ) { |
47 |
|
- |
mValue = pValue; |
48 |
|
- |
} |
49 |
|
- |
|
50 |
|
- |
private String[] mValue; |
51 |
|
- |
|
52 |
|
- |
@Override |
53 |
|
- |
public String toString() { |
54 |
|
- |
StringBuilder sb = new StringBuilder().append( MAP_KEY ).append( ".of( \"" ).append( mValue[0] ).append( '\"' ); |
55 |
|
- |
|
56 |
|
- |
for ( int i = 1; i < mValue.length; i++ ) { |
57 |
|
- |
sb.append( ", \"" ).append( mValue[i] ).append( '\"' ); |
58 |
|
- |
} |
59 |
|
- |
return sb.append( " )" ).toString(); |
60 |
|
- |
} |
61 |
|
- |
|
62 |
|
- |
public String getMapKey() { |
63 |
|
- |
return MAP_KEY; |
64 |
|
- |
} |
65 |
|
- |
|
66 |
|
- |
@Override |
67 |
|
- |
public boolean equals( Object them ) { |
68 |
|
- |
return (this == them) || ((them != null) && (this.getClass() == them.getClass()) && Arrays.equals( this.mValue, ((Options) them).mValue )); |
69 |
|
- |
} |
70 |
|
- |
|
71 |
|
- |
@Override |
72 |
|
- |
public int hashCode() { |
73 |
|
- |
return mValue.length; |
74 |
|
- |
} |
75 |
|
- |
} |
|
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 |
+ |
|
|
6 |
+ |
import java.util.*; |
|
7 |
+ |
|
|
8 |
+ |
public class Options implements PropertyOfAMD { |
|
9 |
+ |
public static Options of( String... pOptions ) { |
|
10 |
+ |
return Currently.isNotNullOrEmpty( pOptions ) ? new Options( pOptions ) : null; |
|
11 |
+ |
} |
|
12 |
+ |
|
|
13 |
+ |
public static String[] get( AttributeMetaData pAMD ) { |
|
14 |
+ |
PropertyOfAMD zProperty = pAMD.getProperties().get( MAP_KEY ); |
|
15 |
+ |
if ( zProperty != null ) { |
|
16 |
+ |
return ((Options) zProperty).mValue; |
|
17 |
+ |
} |
|
18 |
+ |
return null; |
|
19 |
+ |
} |
|
20 |
+ |
|
|
21 |
+ |
public static Integer getLength( AttributeMetaData pAMD ) { |
|
22 |
+ |
PropertyOfAMD zProperty = pAMD.getProperties().get( MAP_KEY ); |
|
23 |
+ |
if ( zProperty != null ) { |
|
24 |
+ |
return ((Options) zProperty).getLength(); |
|
25 |
+ |
} |
|
26 |
+ |
return null; |
|
27 |
+ |
} |
|
28 |
+ |
|
|
29 |
+ |
private static final String MAP_KEY = "Options"; |
|
30 |
+ |
|
|
31 |
+ |
private Integer mLength; |
|
32 |
+ |
|
|
33 |
+ |
private Integer getLength() { |
|
34 |
+ |
if ( mLength == null ) { |
|
35 |
+ |
int zMax = 2; |
|
36 |
+ |
for ( String zEntry : mValue ) { |
|
37 |
+ |
if ( zEntry != null ) { |
|
38 |
+ |
zMax = Math.max( zMax, zEntry.length() ); |
|
39 |
+ |
} |
|
40 |
+ |
} |
|
41 |
+ |
mLength = zMax; |
|
42 |
+ |
} |
|
43 |
+ |
return mLength; |
|
44 |
+ |
} |
|
45 |
+ |
|
|
46 |
+ |
private Options( String[] pValue ) { |
|
47 |
+ |
mValue = pValue; |
|
48 |
+ |
} |
|
49 |
+ |
|
|
50 |
+ |
private String[] mValue; |
|
51 |
+ |
|
|
52 |
+ |
@Override |
|
53 |
+ |
public String toString() { |
|
54 |
+ |
StringBuilder sb = new StringBuilder().append( MAP_KEY ).append( ".of( \"" ).append( mValue[0] ).append( '\"' ); |
|
55 |
+ |
|
|
56 |
+ |
for ( int i = 1; i < mValue.length; i++ ) { |
|
57 |
+ |
sb.append( ", \"" ).append( mValue[i] ).append( '\"' ); |
|
58 |
+ |
} |
|
59 |
+ |
return sb.append( " )" ).toString(); |
|
60 |
+ |
} |
|
61 |
+ |
|
|
62 |
+ |
public String getMapKey() { |
|
63 |
+ |
return MAP_KEY; |
|
64 |
+ |
} |
|
65 |
+ |
|
|
66 |
+ |
@Override |
|
67 |
+ |
public boolean equals( Object them ) { |
|
68 |
+ |
return (this == them) || ((them != null) && (this.getClass() == them.getClass()) && Arrays.equals( this.mValue, ((Options) them).mValue )); |
|
69 |
+ |
} |
|
70 |
+ |
|
|
71 |
+ |
@Override |
|
72 |
+ |
public int hashCode() { |
|
73 |
+ |
return mValue.length; |
|
74 |
+ |
} |
|
75 |
+ |
} |