@@ -82,18 +82,9 @@ private COSArray(ArrayList<COSBase> cosObjects, boolean direct)
8282 */
8383 public void add ( COSBase object )
8484 {
85- if ((object instanceof COSDictionary || object instanceof COSArray ) && !object .isDirect ()
86- && object .getKey () != null )
87- {
88- COSObject cosObject = new COSObject (object , object .getKey ());
89- objects .add (cosObject );
90- getUpdateState ().update (cosObject );
91- }
92- else
93- {
94- objects .add (object );
95- getUpdateState ().update (object );
96- }
85+ COSBase objectToAdd = maybeWrap (object );
86+ objects .add (objectToAdd );
87+ getUpdateState ().update (objectToAdd );
9788 }
9889
9990 /**
@@ -120,18 +111,9 @@ public void add( COSObjectable object )
120111 */
121112 public void add ( int i , COSBase object )
122113 {
123- if ((object instanceof COSDictionary || object instanceof COSArray ) && !object .isDirect ()
124- && object .getKey () != null )
125- {
126- COSObject cosObject = new COSObject (object , object .getKey ());
127- objects .add (i , cosObject );
128- getUpdateState ().update (cosObject );
129- }
130- else
131- {
132- objects .add (i , object );
133- getUpdateState ().update (object );
134- }
114+ COSBase objectToAdd = maybeWrap (object );
115+ objects .add (i , objectToAdd );
116+ getUpdateState ().update (objectToAdd );
135117 }
136118
137119 /**
@@ -219,18 +201,9 @@ public void addAll( int i, Collection<COSBase> objectList )
219201 */
220202 public void set ( int index , COSBase object )
221203 {
222- if ((object instanceof COSDictionary || object instanceof COSArray ) && !object .isDirect ()
223- && object .getKey () != null )
224- {
225- COSObject cosObject = new COSObject (object , object .getKey ());
226- objects .set (index , cosObject );
227- getUpdateState ().update (cosObject );
228- }
229- else
230- {
231- objects .set (index , object );
232- getUpdateState ().update (object );
233- }
204+ COSBase objectToAdd = maybeWrap (object );
205+ objects .set (index , objectToAdd );
206+ getUpdateState ().update (objectToAdd );
234207 }
235208
236209 /**
@@ -861,4 +834,15 @@ else if (cosBaseKey != null)
861834 }
862835 }
863836
837+ // wrap indirect objects
838+ private COSBase maybeWrap (COSBase object )
839+ {
840+ COSBase objectToAdd = object ;
841+ if ((object instanceof COSDictionary || object instanceof COSArray ) && !object .isDirect ()
842+ && object .getKey () != null )
843+ {
844+ objectToAdd = new COSObject (object , object .getKey ());
845+ }
846+ return objectToAdd ;
847+ }
864848}
0 commit comments