|
@@ -1,11 +1,14 @@ |
1 |
1 |
|
package org.litesoft.memobeansupport; |
2 |
2 |
|
|
|
3 |
+ |
import java.util.*; |
|
4 |
+ |
|
3 |
5 |
|
import org.litesoft.charstreams.*; |
4 |
6 |
|
import org.litesoft.core.annotations.*; |
5 |
7 |
|
import org.litesoft.core.simpletypes.nonpublic.*; |
6 |
8 |
|
import org.litesoft.core.util.*; |
7 |
9 |
|
|
8 |
10 |
|
public abstract class AbstractMemoBean<CT extends AbstractMemoBean> implements Cloneable, |
|
11 |
+ |
ToStringBuilder, |
9 |
12 |
|
Memoable<CT> |
10 |
13 |
|
{ |
11 |
14 |
|
private AbstractAttributeProxy[] mAttributeProxies; |
|
@@ -27,7 +30,44 @@ |
27 |
30 |
|
return cast( this ); |
28 |
31 |
|
} |
29 |
32 |
|
CT zClone = clone(); |
30 |
|
- |
mAttributeProxies[pIndex] = getProxy( pIndex ).set( pValue ); |
|
33 |
+ |
AbstractAttributeProxy<T, ?> zProxy = getProxy( pIndex ); |
|
34 |
+ |
zClone.mAttributeProxies[pIndex] = zProxy.set( pValue ); |
|
35 |
+ |
return zClone; |
|
36 |
+ |
} |
|
37 |
+ |
|
|
38 |
+ |
protected <T> List<T> getRepeatingValueFor( int pIndex ) |
|
39 |
+ |
{ |
|
40 |
+ |
return cast( getProxy( pIndex ).getRepeating() ); |
|
41 |
+ |
} |
|
42 |
+ |
|
|
43 |
+ |
protected CT clearRepeatingValueFor( int pIndex ) |
|
44 |
+ |
{ |
|
45 |
+ |
return setRepeatingValueFor( pIndex, (List<? extends Object>) null ); |
|
46 |
+ |
} |
|
47 |
+ |
|
|
48 |
+ |
protected <T> CT addRepeatingValueFor( int pIndex, T pValue ) |
|
49 |
+ |
{ |
|
50 |
+ |
List<T> zCurList = getRepeatingValueFor( pIndex ); |
|
51 |
+ |
List<T> zNewList = (zCurList == null) ? new ArrayList<T>() : new ArrayList<T>( zCurList ); |
|
52 |
+ |
zNewList.add( pValue ); |
|
53 |
+ |
return setRepeatingValueFor( pIndex, zNewList ); |
|
54 |
+ |
} |
|
55 |
+ |
|
|
56 |
+ |
protected <T> CT setRepeatingValueFor( int pIndex, T... pValues ) |
|
57 |
+ |
{ |
|
58 |
+ |
List<T> zValues = (pValues == null) ? null : Arrays.asList( pValues ); |
|
59 |
+ |
return setRepeatingValueFor( pIndex, zValues ); |
|
60 |
+ |
} |
|
61 |
+ |
|
|
62 |
+ |
protected <T> CT setRepeatingValueFor( int pIndex, List<T> pValues ) |
|
63 |
+ |
{ |
|
64 |
+ |
if ( EqualSupport.equal( getRepeatingValueFor( pIndex ), pValues ) ) |
|
65 |
+ |
{ |
|
66 |
+ |
return cast( this ); |
|
67 |
+ |
} |
|
68 |
+ |
CT zClone = clone(); |
|
69 |
+ |
AbstractAttributeProxy<T, ?> zProxy = getProxy( pIndex ); |
|
70 |
+ |
zClone.mAttributeProxies[pIndex] = zProxy.setRepeating( pValues ); |
31 |
71 |
|
return zClone; |
32 |
72 |
|
} |
33 |
73 |
|
|
|
@@ -108,25 +148,32 @@ |
108 |
148 |
|
CT zClone = clone(); |
109 |
149 |
|
for ( int i = 0; i < mAttributeProxies.length; i++ ) |
110 |
150 |
|
{ |
111 |
|
- |
mAttributeProxies[i] = getProxy( i ).fromMemo( pToMemoValue ); |
|
151 |
+ |
zClone.mAttributeProxies[i] = getProxy( i ).fromMemo( pToMemoValue ); |
112 |
152 |
|
} |
113 |
153 |
|
return zClone; |
114 |
154 |
|
} |
115 |
155 |
|
|
116 |
156 |
|
@Override |
117 |
|
- |
public String toString() |
|
157 |
+ |
public final String toString() |
|
158 |
+ |
{ |
|
159 |
+ |
return toStringBuilder( new StringBuilder(), 0 ).toString(); |
|
160 |
+ |
} |
|
161 |
+ |
|
|
162 |
+ |
@Override |
|
163 |
+ |
public StringBuilder toStringBuilder( StringBuilder pSB, int pDepth ) |
118 |
164 |
|
{ |
119 |
|
- |
StringBuilder sb = new StringBuilder( UtilsCommon.justClassNameOf( this ) ); |
120 |
|
- |
String zPrefix = ":\n"; |
|
165 |
+ |
pSB.append( UtilsCommon.justClassNameOf( this ) ); |
|
166 |
+ |
String zIndex = UtilsCommon.spaces( ++pDepth * 4 ); |
|
167 |
+ |
String zPrefix = ":"; |
121 |
168 |
|
for ( AbstractAttributeProxy zProxy : mAttributeProxies ) |
122 |
169 |
|
{ |
123 |
|
- |
String s = zPrefix.toString(); |
|
170 |
+ |
String s = zProxy.toString(); |
124 |
171 |
|
if ( s != null ) |
125 |
172 |
|
{ |
126 |
|
- |
sb.append( zPrefix ).append( s ); |
127 |
|
- |
zPrefix = "\n"; |
|
173 |
+ |
zProxy.toStringBuilder( pSB.append( zPrefix ).append( '\n' ).append( zIndex ), pDepth ); |
|
174 |
+ |
zPrefix = ""; |
128 |
175 |
|
} |
129 |
176 |
|
} |
130 |
|
- |
return sb.toString(); |
|
177 |
+ |
return pSB; |
131 |
178 |
|
} |
132 |
179 |
|
} |