|
@@ -1,16 +1,14 @@ |
1 |
1 |
|
package org.litesoft.aokeyhole.swing.mains.mementobeans.support; |
2 |
2 |
|
|
3 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
4 |
|
- |
|
5 |
|
- |
import java.util.*; |
6 |
|
- |
|
7 |
3 |
|
import org.litesoft.aokeyhole.objects.*; |
8 |
4 |
|
import org.litesoft.aokeyhole.objects.factories.*; |
9 |
5 |
|
import org.litesoft.aokeyhole.objects.factories.mementobean.*; |
|
6 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
10 |
7 |
|
import org.litesoft.commonfoundation.typeutils.Objects; |
11 |
8 |
|
|
12 |
|
- |
public class AttributeData implements BeanMagicStrings |
13 |
|
- |
{ |
|
9 |
+ |
import java.util.*; |
|
10 |
+ |
|
|
11 |
+ |
public class AttributeData implements BeanMagicStrings { |
14 |
12 |
|
private static final String[] VALID_TYPES = extractValidTypes( MementoBeanPropertyMetaDataDefinitionAccessor.INSTANCE ); |
15 |
13 |
|
|
16 |
14 |
|
private int mID; |
|
@@ -23,12 +21,10 @@ |
23 |
21 |
|
protected boolean mRepeating; |
24 |
22 |
|
private String[] mNotes = Strings.EMPTY_ARRAY; |
25 |
23 |
|
|
26 |
|
- |
private AttributeData() |
27 |
|
- |
{ |
|
24 |
+ |
private AttributeData() { |
28 |
25 |
|
} |
29 |
26 |
|
|
30 |
|
- |
public AttributeData( int pID, BeanAttributeBuilder pAttribute ) |
31 |
|
- |
{ |
|
27 |
+ |
public AttributeData( int pID, BeanAttributeBuilder pAttribute ) { |
32 |
28 |
|
mID = pID; |
33 |
29 |
|
mName = pAttribute.getName(); |
34 |
30 |
|
mRepeating = pAttribute.isRepeating(); |
|
@@ -40,8 +36,7 @@ |
40 |
36 |
|
mMementoableType = !Objects.isOneOf( mType, VALID_TYPES ); |
41 |
37 |
|
} |
42 |
38 |
|
|
43 |
|
- |
private AttributeData( AttributeData pCloneFrom ) |
44 |
|
- |
{ |
|
39 |
+ |
private AttributeData( AttributeData pCloneFrom ) { |
45 |
40 |
|
this.mID = pCloneFrom.mID; |
46 |
41 |
|
this.mName = pCloneFrom.mName; |
47 |
42 |
|
this.mType = pCloneFrom.mType; |
|
@@ -53,53 +48,43 @@ |
53 |
48 |
|
this.mNotes = pCloneFrom.mNotes; |
54 |
49 |
|
} |
55 |
50 |
|
|
56 |
|
- |
public int getID() |
57 |
|
- |
{ |
|
51 |
+ |
public int getID() { |
58 |
52 |
|
return mID; |
59 |
53 |
|
} |
60 |
54 |
|
|
61 |
|
- |
public String getName() |
62 |
|
- |
{ |
|
55 |
+ |
public String getName() { |
63 |
56 |
|
return mName; |
64 |
57 |
|
} |
65 |
58 |
|
|
66 |
|
- |
public String getType() |
67 |
|
- |
{ |
|
59 |
+ |
public String getType() { |
68 |
60 |
|
return mType; |
69 |
61 |
|
} |
70 |
62 |
|
|
71 |
|
- |
public boolean isMementoableType() |
72 |
|
- |
{ |
|
63 |
+ |
public boolean isMementoableType() { |
73 |
64 |
|
return mMementoableType; |
74 |
65 |
|
} |
75 |
66 |
|
|
76 |
|
- |
public boolean isNullEmpties() |
77 |
|
- |
{ |
|
67 |
+ |
public boolean isNullEmpties() { |
78 |
68 |
|
return mNullEmpties; |
79 |
69 |
|
} |
80 |
70 |
|
|
81 |
|
- |
public boolean isNullZeros() |
82 |
|
- |
{ |
|
71 |
+ |
public boolean isNullZeros() { |
83 |
72 |
|
return mNullZeros; |
84 |
73 |
|
} |
85 |
74 |
|
|
86 |
|
- |
public boolean isNullFalses() |
87 |
|
- |
{ |
|
75 |
+ |
public boolean isNullFalses() { |
88 |
76 |
|
return mNullFalses; |
89 |
77 |
|
} |
90 |
78 |
|
|
91 |
|
- |
public boolean isRepeating() |
92 |
|
- |
{ |
|
79 |
+ |
public boolean isRepeating() { |
93 |
80 |
|
return mRepeating; |
94 |
81 |
|
} |
95 |
82 |
|
|
96 |
|
- |
public String[] getNotes() |
97 |
|
- |
{ |
|
83 |
+ |
public String[] getNotes() { |
98 |
84 |
|
return mNotes; |
99 |
85 |
|
} |
100 |
86 |
|
|
101 |
|
- |
public void setNotes( String[] pNotes ) |
102 |
|
- |
{ |
|
87 |
+ |
public void setNotes( String[] pNotes ) { |
103 |
88 |
|
mNotes = Strings.deNull( pNotes ); |
104 |
89 |
|
} |
105 |
90 |
|
|
|
@@ -119,15 +104,13 @@ |
119 |
104 |
|
mID = Integer.parseInt( pID ); |
120 |
105 |
|
} |
121 |
106 |
|
|
122 |
|
- |
private void appendType( StringBuilder pSB ) |
123 |
|
- |
{ |
|
107 |
+ |
private void appendType( StringBuilder pSB ) { |
124 |
108 |
|
pSB.append( isMementoableType() ? MEMENTOABLE_ATTRIBUTE_PROXY_TYPE : getType() ); |
125 |
109 |
|
} |
126 |
110 |
|
|
127 |
111 |
|
private void appendMementoTypeExtension1( StringBuilder pSB ) // PART5 |
128 |
112 |
|
{ |
129 |
|
- |
if ( isMementoableType() ) |
130 |
|
- |
{ |
|
113 |
+ |
if ( isMementoableType() ) { |
131 |
114 |
|
pSB.append( '<' ).append( getType() ).append( '>' ); |
132 |
115 |
|
} |
133 |
116 |
|
} |
|
@@ -141,18 +124,15 @@ |
141 |
124 |
|
private void parseType( String pPreType, String pBracketedPostType ) // PART3 & PART5 |
142 |
125 |
|
{ |
143 |
126 |
|
// "String" & "" || "Mementoable" & "<DetailBean>" |
144 |
|
- |
if ( !MEMENTOABLE_ATTRIBUTE_PROXY_TYPE.equals( pPreType ) ) |
145 |
|
- |
{ |
|
127 |
+ |
if ( !MEMENTOABLE_ATTRIBUTE_PROXY_TYPE.equals( pPreType ) ) { |
146 |
128 |
|
Strings.assertNullOrEmpty( "BracketedPostType", pBracketedPostType ); |
147 |
129 |
|
mType = Objects.assertOneOf( pPreType, VALID_TYPES ); |
148 |
130 |
|
return; |
149 |
131 |
|
} |
150 |
132 |
|
mMementoableType = true; |
151 |
|
- |
if ( pBracketedPostType.startsWith( "<" ) && pBracketedPostType.endsWith( ">" ) ) |
152 |
|
- |
{ |
|
133 |
+ |
if ( pBracketedPostType.startsWith( "<" ) && pBracketedPostType.endsWith( ">" ) ) { |
153 |
134 |
|
mType = pBracketedPostType.substring( 1, pBracketedPostType.length() - 1 ); |
154 |
|
- |
if ( Strings.isValidAttributeIdentifier( mType ) ) |
155 |
|
- |
{ |
|
135 |
+ |
if ( Strings.isValidAttributeIdentifier( mType ) ) { |
156 |
136 |
|
return; |
157 |
137 |
|
} |
158 |
138 |
|
} |
|
@@ -161,20 +141,16 @@ |
161 |
141 |
|
|
162 |
142 |
|
private void appendMementoTypeExtension2( StringBuilder pSB ) // PART7b |
163 |
143 |
|
{ |
164 |
|
- |
if ( isMementoableType() ) |
165 |
|
- |
{ |
|
144 |
+ |
if ( isMementoableType() ) { |
166 |
145 |
|
pSB.append( ATTR_PART7b_PRE_TYPE ).append( mType ).append( ATTR_PART7b_POST_TYPE ); |
167 |
146 |
|
} |
168 |
147 |
|
} |
169 |
148 |
|
|
170 |
149 |
|
private void appendName( StringBuilder pSB ) // PART7a |
171 |
150 |
|
{ |
172 |
|
- |
if ( mName == null ) |
173 |
|
- |
{ |
174 |
|
- |
pSB.append( ATTR_PART7a_NO_NAME ); |
175 |
|
- |
} |
176 |
|
- |
else |
177 |
|
- |
{ |
|
151 |
+ |
if ( mName == null ) { |
|
152 |
+ |
pSB.append( ATTR_PART7a_NO_NAME ); |
|
153 |
+ |
} else { |
178 |
154 |
|
pSB.append( DOUBLE_QUOTE ).append( mName ).append( DOUBLE_QUOTE ); |
179 |
155 |
|
} |
180 |
156 |
|
} |
|
@@ -190,25 +166,20 @@ |
190 |
166 |
|
// "SpecialDetail", DetailBean.DEFAULT_INSTANCE |
191 |
167 |
|
// "Details", DetailBean.DEFAULT_INSTANCE |
192 |
168 |
|
String zName = pAttributeProxyParameters; |
193 |
|
- |
if ( mMementoableType ) |
194 |
|
- |
{ |
|
169 |
+ |
if ( mMementoableType ) { |
195 |
170 |
|
String zDefaultInstanceTail = ATTR_PART7b_PRE_TYPE + mType + ATTR_PART7b_POST_TYPE; |
196 |
|
- |
if ( !pAttributeProxyParameters.endsWith( zDefaultInstanceTail ) ) |
197 |
|
- |
{ |
|
171 |
+ |
if ( !pAttributeProxyParameters.endsWith( zDefaultInstanceTail ) ) { |
198 |
172 |
|
throw new IllegalArgumentException( |
199 |
173 |
|
"Mementoable attribute proxy, but not default instance in the parameter section: " + pAttributeProxyParameters ); |
200 |
174 |
|
} |
201 |
175 |
|
zName = pAttributeProxyParameters.substring( 0, pAttributeProxyParameters.length() - zDefaultInstanceTail.length() ); |
202 |
176 |
|
} |
203 |
|
- |
if ( !zName.equals( ATTR_PART7a_NO_NAME ) ) |
204 |
|
- |
{ |
205 |
|
- |
if ( (zName.length() < 3) || !zName.startsWith( DOUBLE_QUOTE ) || !zName.endsWith( DOUBLE_QUOTE ) ) |
206 |
|
- |
{ |
|
177 |
+ |
if ( !zName.equals( ATTR_PART7a_NO_NAME ) ) { |
|
178 |
+ |
if ( (zName.length() < 3) || !zName.startsWith( DOUBLE_QUOTE ) || !zName.endsWith( DOUBLE_QUOTE ) ) { |
207 |
179 |
|
throw new IllegalArgumentException( "Malformed name '" + zName + "' in: " + pAttributeProxyParameters ); |
208 |
180 |
|
} |
209 |
181 |
|
zName = zName.substring( 1, zName.length() - 1 ); |
210 |
|
- |
if ( !Strings.isAsciiIdentifier( zName ) ) |
211 |
|
- |
{ |
|
182 |
+ |
if ( !Strings.isAsciiIdentifier( zName ) ) { |
212 |
183 |
|
throw new IllegalArgumentException( "Name '" + zName + "' not an Ascii Identifier in: " + pAttributeProxyParameters ); |
213 |
184 |
|
} |
214 |
185 |
|
mName = zName; |
|
@@ -217,8 +188,7 @@ |
217 |
188 |
|
|
218 |
189 |
|
private void appendFlags( StringBuilder pSB ) // PART9 |
219 |
190 |
|
{ |
220 |
|
- |
for ( BeanAttributeProperties zValue : BeanAttributeProperties.values() ) |
221 |
|
- |
{ |
|
191 |
+ |
for ( BeanAttributeProperties zValue : BeanAttributeProperties.values() ) { |
222 |
192 |
|
zValue.appendFlag( this, pSB ); |
223 |
193 |
|
} |
224 |
194 |
|
} |
|
@@ -235,18 +205,15 @@ |
235 |
205 |
|
private void parseFlags( String pFlags ) // PART9 |
236 |
206 |
|
{ |
237 |
207 |
|
StringBuilder zFlags = new StringBuilder( pFlags ); |
238 |
|
- |
for ( BeanAttributeProperties zValue : BeanAttributeProperties.values() ) |
239 |
|
- |
{ |
|
208 |
+ |
for ( BeanAttributeProperties zValue : BeanAttributeProperties.values() ) { |
240 |
209 |
|
zValue.parseFlag( this, zFlags ); |
241 |
210 |
|
} |
242 |
|
- |
if ( zFlags.length() != 0 ) |
243 |
|
- |
{ |
|
211 |
+ |
if ( zFlags.length() != 0 ) { |
244 |
212 |
|
throw new IllegalArgumentException( "Don't understand '" + zFlags + "' in: " + pFlags ); |
245 |
213 |
|
} |
246 |
214 |
|
} |
247 |
215 |
|
|
248 |
|
- |
public String toParseLine() |
249 |
|
- |
{ |
|
216 |
+ |
public String toParseLine() { |
250 |
217 |
|
StringBuilder sb = new StringBuilder(); |
251 |
218 |
|
sb.append( ATTR_PART0 ); |
252 |
219 |
|
appendID( sb ); // PART1 |
|
@@ -262,8 +229,7 @@ |
262 |
229 |
|
return sb.append( ATTR_PART10 ).toString(); |
263 |
230 |
|
} |
264 |
231 |
|
|
265 |
|
- |
public static AttributeData parseLine( String pLine ) |
266 |
|
- |
{ |
|
232 |
+ |
public static AttributeData parseLine( String pLine ) { |
267 |
233 |
|
// /* 00 */ new StringAttributeProxy( "FirstName" ), // |
268 |
234 |
|
// /* 00 */ new StringAttributeProxy( "Name" ).nullEmpties(), // |
269 |
235 |
|
// /* 01 */ new StringAttributeProxy( null ), // |
|
@@ -279,11 +245,9 @@ |
279 |
245 |
|
int atPart8 = pLine.indexOf( ATTR_PART8, atPart6 + 1 ); |
280 |
246 |
|
if ( pLine.startsWith( ATTR_PART0 ) && // |
281 |
247 |
|
(atPart2 != -1) && (atPart4 != -1) && (atPart6 != -1) && (atPart8 != -1) && // |
282 |
|
- |
pLine.endsWith( ATTR_PART10 ) ) |
283 |
|
- |
{ |
|
248 |
+ |
pLine.endsWith( ATTR_PART10 ) ) { |
284 |
249 |
|
AttributeData zAttribute = new AttributeData(); |
285 |
|
- |
try |
286 |
|
- |
{ |
|
250 |
+ |
try { |
287 |
251 |
|
zAttribute.parseID( pLine.substring( ATTR_PART0.length(), atPart2 ) ); // PART1 |
288 |
252 |
|
zAttribute.parseType( pLine.substring( atPart2 + ATTR_PART2.length(), atPart4 ), // PART3 |
289 |
253 |
|
pLine.substring( atPart4 + ATTR_PART4.length(), atPart6 ) ); // PART5 |
|
@@ -291,8 +255,7 @@ |
291 |
255 |
|
zAttribute.parseFlags( pLine.substring( atPart8 + ATTR_PART8.length(), pLine.length() - ATTR_PART10.length() ) ); // PART9 |
292 |
256 |
|
return zAttribute; |
293 |
257 |
|
} |
294 |
|
- |
catch ( IllegalArgumentException e ) |
295 |
|
- |
{ |
|
258 |
+ |
catch ( IllegalArgumentException e ) { |
296 |
259 |
|
System.out.println( e.getMessage() ); |
297 |
260 |
|
// Fall thru... |
298 |
261 |
|
} |
|
@@ -300,27 +263,22 @@ |
300 |
263 |
|
return null; |
301 |
264 |
|
} |
302 |
265 |
|
|
303 |
|
- |
private static String[] extractValidTypes( PropertyMetaDataDefinitionAccessor pAccessor ) |
304 |
|
- |
{ |
|
266 |
+ |
private static String[] extractValidTypes( PropertyMetaDataDefinitionAccessor pAccessor ) { |
305 |
267 |
|
List<String> zTypes = Lists.newArrayList(); |
306 |
|
- |
for ( AttributeSet zAttribute : pAccessor.getAttributeSets() ) |
307 |
|
- |
{ |
|
268 |
+ |
for ( AttributeSet zAttribute : pAccessor.getAttributeSets() ) { |
308 |
269 |
|
AttributeType zType = zAttribute.getType(); |
309 |
|
- |
if ( zType.getFAT().isSimple() ) |
310 |
|
- |
{ |
|
270 |
+ |
if ( zType.getFAT().isSimple() ) { |
311 |
271 |
|
zTypes.add( zType.toString() ); |
312 |
272 |
|
} |
313 |
273 |
|
} |
314 |
274 |
|
return zTypes.toArray( new String[zTypes.size()] ); |
315 |
275 |
|
} |
316 |
276 |
|
|
317 |
|
- |
public AttributeData makePlaceHolder() |
318 |
|
- |
{ |
|
277 |
+ |
public AttributeData makePlaceHolder() { |
319 |
278 |
|
AttributeData zAttributeData = new AttributeData( this ); |
320 |
279 |
|
zAttributeData.mName = null; |
321 |
280 |
|
zAttributeData.setNotes( null ); |
322 |
|
- |
if ( isMementoableType() ) |
323 |
|
- |
{ |
|
281 |
+ |
if ( isMementoableType() ) { |
324 |
282 |
|
zAttributeData.mNullEmpties = true; |
325 |
283 |
|
zAttributeData.mType = "String"; |
326 |
284 |
|
zAttributeData.mMementoableType = false; |
|
@@ -328,8 +286,7 @@ |
328 |
286 |
|
return zAttributeData; |
329 |
287 |
|
} |
330 |
288 |
|
|
331 |
|
- |
public boolean isUpdatableFrom( BeanAttributeBuilder pAttribute ) |
332 |
|
- |
{ |
|
289 |
+ |
public boolean isUpdatableFrom( BeanAttributeBuilder pAttribute ) { |
333 |
290 |
|
return Objects.areNonArraysEqual( this.getName(), pAttribute.getName() ) && // |
334 |
291 |
|
Objects.areNonArraysEqual( this.getType(), pAttribute.getType() ) && // |
335 |
292 |
|
(this.isRepeating() == pAttribute.isRepeating()); |
|
@@ -340,10 +297,8 @@ |
340 |
297 |
|
* <p/> |
341 |
298 |
|
* Note: <code>pAttribute</code> must have already passed thru <code>isUpdatableFrom</code> |
342 |
299 |
|
*/ |
343 |
|
- |
public AttributeData updateWith( BeanAttributeBuilder pAttribute ) |
344 |
|
- |
{ |
345 |
|
- |
if ( isUpdatableFromRestIsEquivalent( pAttribute ) ) |
346 |
|
- |
{ |
|
300 |
+ |
public AttributeData updateWith( BeanAttributeBuilder pAttribute ) { |
|
301 |
+ |
if ( isUpdatableFromRestIsEquivalent( pAttribute ) ) { |
347 |
302 |
|
return this; |
348 |
303 |
|
} |
349 |
304 |
|
AttributeData zAttributeData = new AttributeData( this ); |
|
@@ -354,8 +309,7 @@ |
354 |
309 |
|
return zAttributeData; |
355 |
310 |
|
} |
356 |
311 |
|
|
357 |
|
- |
private boolean isUpdatableFromRestIsEquivalent( BeanAttributeBuilder pAttribute ) |
358 |
|
- |
{ |
|
312 |
+ |
private boolean isUpdatableFromRestIsEquivalent( BeanAttributeBuilder pAttribute ) { |
359 |
313 |
|
return Objects.areArraysEqual( this.getNotes(), pAttribute.getNotes() ) && // |
360 |
314 |
|
(this.isNullEmpties() == pAttribute.isNullEmpties()) && // |
361 |
315 |
|
(this.isNullZeros() == pAttribute.isNullZeros()) && // |