@@ -1992,19 +1992,6 @@ public <T extends XmlObject> void find_all_element_users(QName name, List<T> fil
1992
1992
}
1993
1993
}
1994
1994
1995
- @ SuppressWarnings ("unchecked" )
1996
- @ Override
1997
- public <T extends XmlObject > void find_multiple_element_users (final QName name , final List <T > fillMeUp ,
1998
- final int maxCount ) {
1999
- int count = 0 ;
2000
- for (Xobj x = _firstChild ; x != null && count < maxCount ; x = x ._nextSibling ) {
2001
- if (x .isElem () && x ._name .equals (name )) {
2002
- fillMeUp .add ((T ) x .getUser ());
2003
- count ++;
2004
- }
2005
- }
2006
- }
2007
-
2008
1995
@ SuppressWarnings ("unchecked" )
2009
1996
@ Override
2010
1997
public <T extends XmlObject > void find_all_element_users (QNameSet names , List <T > fillMeUp ) {
@@ -2015,19 +2002,6 @@ public <T extends XmlObject> void find_all_element_users(QNameSet names, List<T>
2015
2002
}
2016
2003
}
2017
2004
2018
- @ SuppressWarnings ("unchecked" )
2019
- @ Override
2020
- public <T extends XmlObject > void find_multiple_element_users (final QNameSet names , final List <T > fillMeUp ,
2021
- final int maxCount ) {
2022
- int count = 0 ;
2023
- for (Xobj x = _firstChild ; x != null && count < maxCount ; x = x ._nextSibling ) {
2024
- if (x .isElem () && names .contains (x ._name )) {
2025
- fillMeUp .add ((T ) x .getUser ());
2026
- count ++;
2027
- }
2028
- }
2029
- }
2030
-
2031
2005
private static TypeStoreUser insertElement (QName name , Xobj x , int pos ) {
2032
2006
x ._locale .enter ();
2033
2007
@@ -2043,26 +2017,6 @@ private static TypeStoreUser insertElement(QName name, Xobj x, int pos) {
2043
2017
}
2044
2018
}
2045
2019
2046
- private static TypeStoreUser [] insertElements (final QName name , final Xobj x ,
2047
- final int pos , final int count ) {
2048
- x ._locale .enter ();
2049
-
2050
- TypeStoreUser [] users = new TypeStoreUser [count ];
2051
- try {
2052
- Cur c = x ._locale .tempCur ();
2053
- c .moveTo (x , pos );
2054
- for (int i = count - 1 ; i >= 0 ; i --) {
2055
- c .createElement (name );
2056
- users [i ] = c .getUser ();
2057
- }
2058
- c .release ();
2059
- } finally {
2060
- x ._locale .exit ();
2061
- }
2062
- return users ;
2063
- }
2064
-
2065
- @ Override
2066
2020
public TypeStoreUser insert_element_user (QName name , int i ) {
2067
2021
if (i < 0 ) {
2068
2022
throw new IndexOutOfBoundsException ();
@@ -2085,35 +2039,6 @@ public TypeStoreUser insert_element_user(QName name, int i) {
2085
2039
return insertElement (name , x , 0 );
2086
2040
}
2087
2041
2088
- @ Override
2089
- public TypeStoreUser [] insert_elements_users (final QName name , final int i ,
2090
- final int count ) {
2091
- if (i < 0 ) {
2092
- throw new IndexOutOfBoundsException ();
2093
- }
2094
-
2095
- if (!isContainer ()) {
2096
- throw new IllegalStateException ();
2097
- }
2098
-
2099
- if (count <= 0 ) {
2100
- return new TypeStoreUser [0 ];
2101
- }
2102
-
2103
- Xobj x = _locale .findNthChildElem (this , name , null , i );
2104
-
2105
- if (x == null ) {
2106
- if (i > _locale .count (this , name , null ) + 1 ) {
2107
- throw new IndexOutOfBoundsException ();
2108
- }
2109
-
2110
- return add_elements_users (name , count );
2111
- }
2112
-
2113
- return insertElements (name , x , 0 , count );
2114
- }
2115
-
2116
- @ Override
2117
2042
public TypeStoreUser insert_element_user (QNameSet names , QName name , int i ) {
2118
2043
if (i < 0 ) {
2119
2044
throw new IndexOutOfBoundsException ();
@@ -2136,35 +2061,6 @@ public TypeStoreUser insert_element_user(QNameSet names, QName name, int i) {
2136
2061
return insertElement (name , x , 0 );
2137
2062
}
2138
2063
2139
- @ Override
2140
- public TypeStoreUser [] insert_elements_users (final QNameSet names , final QName name ,
2141
- final int i , final int count ) {
2142
- if (i < 0 ) {
2143
- throw new IndexOutOfBoundsException ();
2144
- }
2145
-
2146
- if (!isContainer ()) {
2147
- throw new IllegalStateException ();
2148
- }
2149
-
2150
- if (count <= 0 ) {
2151
- return new TypeStoreUser [0 ];
2152
- }
2153
-
2154
- Xobj x = _locale .findNthChildElem (this , null , names , i );
2155
-
2156
- if (x == null ) {
2157
- if (i > _locale .count (this , null , names ) + 1 ) {
2158
- throw new IndexOutOfBoundsException ();
2159
- }
2160
-
2161
- return add_elements_users (name , count );
2162
- }
2163
-
2164
- return insertElements (name , x , 0 , count );
2165
- }
2166
-
2167
- @ Override
2168
2064
public TypeStoreUser add_element_user (QName name ) {
2169
2065
if (!isContainer ()) {
2170
2066
throw new IllegalStateException ();
@@ -2198,51 +2094,6 @@ public TypeStoreUser add_element_user(QName name) {
2198
2094
: insertElement (name , candidate , 0 );
2199
2095
}
2200
2096
2201
- @ Override
2202
- public TypeStoreUser [] add_elements_users (final QName name , final int count ) {
2203
- if (!isContainer ()) {
2204
- throw new IllegalStateException ();
2205
- }
2206
-
2207
- if (count <= 0 ) {
2208
- return new TypeStoreUser [0 ];
2209
- }
2210
-
2211
- QNameSet endSet = null ;
2212
- boolean gotEndSet = false ;
2213
-
2214
- Xobj candidate = null ;
2215
-
2216
- for (Xobj x = _lastChild ; x != null ; x = x ._prevSibling ) {
2217
- if (x .isContainer ()) {
2218
- if (x ._name .equals (name )) {
2219
- break ;
2220
- }
2221
-
2222
- if (!gotEndSet ) {
2223
- endSet = _user .get_element_ending_delimiters (name );
2224
- gotEndSet = true ;
2225
- }
2226
-
2227
- if (endSet == null || endSet .contains (x ._name )) {
2228
- candidate = x ;
2229
- }
2230
- }
2231
- }
2232
-
2233
- final TypeStoreUser [] users ;
2234
- if (candidate == null ) {
2235
- // If there is no candidate, then I need to insert at the end of this container
2236
- // and create a new element for each of the count
2237
- users = insertElements (name , this , END_POS , count );
2238
- } else {
2239
- // If I have a candidate, then I need to insert at the candidate and create
2240
- // a new element for each of the count
2241
- users = insertElements (name , candidate , 0 , count );
2242
- }
2243
- return users ;
2244
- }
2245
-
2246
2097
private static void removeElement (Xobj x ) {
2247
2098
if (x == null ) {
2248
2099
throw new IndexOutOfBoundsException ();
@@ -2259,7 +2110,6 @@ private static void removeElement(Xobj x) {
2259
2110
}
2260
2111
}
2261
2112
2262
- @ Override
2263
2113
public void remove_element (QName name , int i ) {
2264
2114
if (i < 0 ) {
2265
2115
throw new IndexOutOfBoundsException ();
@@ -2280,63 +2130,6 @@ public void remove_element(QName name, int i) {
2280
2130
removeElement (x );
2281
2131
}
2282
2132
2283
- @ Override
2284
- public void remove_elements_after (QName name , int i ) {
2285
- if (i < 0 ) {
2286
- throw new IndexOutOfBoundsException ();
2287
- }
2288
-
2289
- if (!isContainer ()) {
2290
- throw new IllegalStateException ();
2291
- }
2292
-
2293
- ArrayList <Xobj > toRemove = new ArrayList <>();
2294
- Xobj x ;
2295
- for (x = _firstChild ; x != null ; x = x ._nextSibling ) {
2296
- if (x .isElem () && x ._name .equals (name ) && --i < 0 ) {
2297
- toRemove .add (x );
2298
- }
2299
- }
2300
- final int size = toRemove .size ();
2301
- for (int j = size - 1 ; j >= 0 ; j --) {
2302
- removeElement (toRemove .get (j ));
2303
- }
2304
- }
2305
-
2306
- @ Override
2307
- public void remove_elements_between (final QName name , final int m , final int n ) {
2308
- if (m < 0 || n < 0 ) {
2309
- throw new IndexOutOfBoundsException ();
2310
- }
2311
-
2312
- if (!isContainer ()) {
2313
- throw new IllegalStateException ();
2314
- }
2315
-
2316
- if (m >= n ) {
2317
- return ;
2318
- }
2319
-
2320
- ArrayList <Xobj > toRemove = new ArrayList <>();
2321
- Xobj x ;
2322
- int i = m ;
2323
- int count = 0 ;
2324
- for (x = _firstChild ; x != null ; x = x ._nextSibling ) {
2325
- if (x .isElem () && x ._name .equals (name ) && --i < 0 ) {
2326
- toRemove .add (x );
2327
- count ++;
2328
- if (count >= n - m ) {
2329
- break ; // no need to continue if we've removed enough
2330
- }
2331
- }
2332
- }
2333
- final int size = toRemove .size ();
2334
- for (int j = size - 1 ; j >= 0 ; j --) {
2335
- removeElement (toRemove .get (j ));
2336
- }
2337
- }
2338
-
2339
- @ Override
2340
2133
public void remove_element (QNameSet names , int i ) {
2341
2134
if (i < 0 ) {
2342
2135
throw new IndexOutOfBoundsException ();
@@ -2357,58 +2150,6 @@ public void remove_element(QNameSet names, int i) {
2357
2150
removeElement (x );
2358
2151
}
2359
2152
2360
- @ Override
2361
- public void remove_elements_after (QNameSet names , int i ) {
2362
- if (i < 0 ) {
2363
- throw new IndexOutOfBoundsException ();
2364
- }
2365
-
2366
- if (!isContainer ()) {
2367
- throw new IllegalStateException ();
2368
- }
2369
-
2370
- Xobj x ;
2371
-
2372
- for (x = _firstChild ; x != null ; x = x ._nextSibling ) {
2373
- if (x .isElem () && names .contains (x ._name ) && --i < 0 ) {
2374
- removeElement (x );
2375
- }
2376
- }
2377
- }
2378
-
2379
- @ Override
2380
- public void remove_elements_between (final QNameSet names , final int m , final int n ) {
2381
- if (m < 0 || n < 0 ) {
2382
- throw new IndexOutOfBoundsException ();
2383
- }
2384
-
2385
- if (!isContainer ()) {
2386
- throw new IllegalStateException ();
2387
- }
2388
-
2389
- if (m >= n ) {
2390
- return ;
2391
- }
2392
-
2393
- ArrayList <Xobj > toRemove = new ArrayList <>();
2394
- Xobj x ;
2395
- int i = m ;
2396
- int count = 0 ;
2397
- for (x = _firstChild ; x != null ; x = x ._nextSibling ) {
2398
- if (x .isElem () && names .contains (x ._name ) && --i < 0 ) {
2399
- toRemove .add (x );
2400
- count ++;
2401
- if (count >= n - m ) {
2402
- break ; // no need to continue if we've removed enough
2403
- }
2404
- }
2405
- }
2406
- final int size = toRemove .size ();
2407
- for (int j = size - 1 ; j >= 0 ; j --) {
2408
- removeElement (toRemove .get (j ));
2409
- }
2410
- }
2411
-
2412
2153
public TypeStoreUser find_attribute_user (QName name ) {
2413
2154
Xobj a = getAttr (name );
2414
2155
@@ -2553,7 +2294,7 @@ public void array_setter(XmlObject[] sources, QName elementName) {
2553
2294
try {
2554
2295
// TODO - this is the quick and dirty implementation, make this faster
2555
2296
2556
- final int m = sources .length ;
2297
+ int m = sources .length ;
2557
2298
2558
2299
List <Xobj > copies = new ArrayList <>();
2559
2300
List <SchemaType > types = new ArrayList <>();
@@ -2585,14 +2326,18 @@ public void array_setter(XmlObject[] sources, QName elementName) {
2585
2326
}
2586
2327
}
2587
2328
2588
- final int n = count_elements (elementName );
2329
+ int n = count_elements (elementName );
2330
+
2331
+ for (; n > m ; n --) {
2332
+ remove_element (elementName , m );
2333
+ }
2589
2334
2590
- if (n > m ) {
2591
- remove_elements_after (elementName , m );
2592
- } else if (n < m ) {
2593
- add_elements_users (elementName , m - n );
2335
+ for (; m > n ; n ++) {
2336
+ add_element_user (elementName );
2594
2337
}
2595
2338
2339
+ assert m == n ;
2340
+
2596
2341
List <XmlObject > elementsUser = new ArrayList <>();
2597
2342
2598
2343
find_all_element_users (elementName , elementsUser );
@@ -2603,6 +2348,8 @@ public void array_setter(XmlObject[] sources, QName elementName) {
2603
2348
.map (x -> (Xobj ) x )
2604
2349
.collect (Collectors .toList ());
2605
2350
2351
+ assert elements .size () == n ;
2352
+
2606
2353
Cur c = tempCur ();
2607
2354
2608
2355
for (int i = 0 ; i < n ; i ++) {
0 commit comments