@@ -68,19 +68,9 @@ public COSArray(List<? extends COSObjectable> cosObjectables)
6868 */
6969 public void add ( COSBase object )
7070 {
71- // wrap indirect objects
72- if ((object instanceof COSDictionary || object instanceof COSArray ) && !object .isDirect ()
73- && object .getKey () != null )
74- {
75- COSObject cosObject = new COSObject (object , object .getKey ());
76- objects .add (cosObject );
77- getUpdateState ().update (cosObject );
78- }
79- else
80- {
81- objects .add (object );
82- getUpdateState ().update (object );
83- }
71+ COSBase objectToAdd = maybeWrap (object );
72+ objects .add (objectToAdd );
73+ getUpdateState ().update (objectToAdd );
8474 }
8575
8676 /**
@@ -107,19 +97,9 @@ public void add( COSObjectable object )
10797 */
10898 public void add ( int i , COSBase object )
10999 {
110- // wrap indirect objects
111- if ((object instanceof COSDictionary || object instanceof COSArray ) && !object .isDirect ()
112- && object .getKey () != null )
113- {
114- COSObject cosObject = new COSObject (object , object .getKey ());
115- objects .add (i , cosObject );
116- getUpdateState ().update (cosObject );
117- }
118- else
119- {
120- objects .add (i , object );
121- getUpdateState ().update (object );
122- }
100+ COSBase objectToAdd = maybeWrap (object );
101+ objects .add (i , objectToAdd );
102+ getUpdateState ().update (objectToAdd );
123103 }
124104
125105 /**
@@ -207,19 +187,9 @@ public void addAll( int i, Collection<COSBase> objectList )
207187 */
208188 public void set ( int index , COSBase object )
209189 {
210- // wrap indirect objects
211- if ((object instanceof COSDictionary || object instanceof COSArray ) && !object .isDirect ()
212- && object .getKey () != null )
213- {
214- COSObject cosObject = new COSObject (object , object .getKey ());
215- objects .set (index , cosObject );
216- getUpdateState ().update (cosObject );
217- }
218- else
219- {
220- objects .set (index , object );
221- getUpdateState ().update (object );
222- }
190+ COSBase objectToAdd = maybeWrap (object );
191+ objects .set (index , objectToAdd );
192+ getUpdateState ().update (objectToAdd );
223193 }
224194
225195 /**
@@ -853,4 +823,16 @@ else if (cosBaseKey != null)
853823 }
854824 }
855825 }
826+
827+ // wrap indirect objects
828+ private COSBase maybeWrap (COSBase object )
829+ {
830+ COSBase objectToAdd = object ;
831+ if ((object instanceof COSDictionary || object instanceof COSArray ) && !object .isDirect ()
832+ && object .getKey () != null )
833+ {
834+ objectToAdd = new COSObject (object , object .getKey ());
835+ }
836+ return objectToAdd ;
837+ }
856838}
0 commit comments