|
30 | 30 |
|
31 | 31 | public class DocumentWriteSetImpl implements Set<DocumentWriteOperation>,DocumentWriteSet { |
32 | 32 |
|
33 | | - final private static String SET_TYPE = System.getProperty("com.marklogic.client.DocumentWriteSet.type", "sorted"); |
34 | | - private Set<DocumentWriteOperation> operations; |
| 33 | + private List<DocumentWriteOperation> operations; |
| 34 | + private int metadataCount; |
35 | 35 |
|
36 | 36 | DocumentWriteSetImpl(){ |
37 | | - setOperations(SET_TYPE); |
38 | | - |
| 37 | + operations = new ArrayList<>(); |
| 38 | + metadataCount = 0; |
39 | 39 | } |
40 | 40 | @Override |
41 | 41 | public DocumentWriteSet addDefault(DocumentMetadataWriteHandle metadataHandle) { |
| 42 | + this.metadataCount++; |
42 | 43 | add(new DocumentWriteOperationImpl(OperationType.METADATA_DEFAULT, |
43 | 44 | null, metadataHandle, null)); |
44 | 45 | return this; |
45 | 46 | } |
46 | 47 |
|
47 | 48 | @Override |
48 | 49 | public DocumentWriteSet disableDefault() { |
| 50 | + this.metadataCount++; |
49 | 51 | add(new DocumentWriteOperationImpl(OperationType.DISABLE_METADATA_DEFAULT, |
50 | 52 | null, new StringHandle("{ }").withFormat(Format.JSON), null)); |
51 | 53 | return this; |
@@ -159,6 +161,8 @@ public boolean contains(Object o) { |
159 | 161 |
|
160 | 162 | @Override |
161 | 163 | public Iterator<DocumentWriteOperation> iterator() { |
| 164 | + if(metadataCount <=1) |
| 165 | + Collections.sort(operations); |
162 | 166 | return operations.iterator(); |
163 | 167 | } |
164 | 168 |
|
@@ -207,14 +211,4 @@ public void clear() { |
207 | 211 | operations.clear(); |
208 | 212 | } |
209 | 213 |
|
210 | | - private void setOperations(String SET_TYPE) { |
211 | | - |
212 | | - if(SET_TYPE.equals("sorted")) { |
213 | | - this.operations = new TreeSet<DocumentWriteOperation>(); |
214 | | - } else if(SET_TYPE.equals("unsorted")) { |
215 | | - this.operations = new LinkedHashSet<DocumentWriteOperation>(); |
216 | | - } else { |
217 | | - throw new IllegalStateException("SET_TYPE should be either sorted or unsorted"); |
218 | | - } |
219 | | - } |
220 | 214 | } |
0 commit comments