Skip to content

Commit 3e6e66c

Browse files
committed
调整代码顺序
1 parent a9b3cd9 commit 3e6e66c

File tree

1 file changed

+132
-132
lines changed
  • src/main/java/com/bestvike/linq/enumerable

1 file changed

+132
-132
lines changed

src/main/java/com/bestvike/linq/enumerable/Where.java

Lines changed: 132 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,6 @@ public AbstractIterator<TSource> clone() {
126126
return new WhereArrayIterator<>(this.source, this.predicate);
127127
}
128128

129-
@Override
130-
public <TResult> IEnumerable<TResult> _select(Func1<TSource, TResult> selector) {
131-
return new WhereSelectArrayIterator<>(this.source, this.predicate, selector);
132-
}
133-
134-
@Override
135-
public IEnumerable<TSource> _where(Func1<TSource, Boolean> predicate) {
136-
return new WhereArrayIterator<>(this.source, Utilities.combinePredicates(this.predicate, predicate));
137-
}
138-
139129
@Override
140130
public boolean moveNext() {
141131
switch (this.state) {
@@ -158,17 +148,13 @@ public boolean moveNext() {
158148
}
159149

160150
@Override
161-
public int _getCount(boolean onlyIfCheap) {
162-
if (onlyIfCheap)
163-
return -1;
164-
165-
int count = 0;
166-
for (TSource item : this.source) {
167-
if (this.predicate.apply(item))
168-
count = Math.addExact(count, 1);
169-
}
151+
public <TResult> IEnumerable<TResult> _select(Func1<TSource, TResult> selector) {
152+
return new WhereSelectArrayIterator<>(this.source, this.predicate, selector);
153+
}
170154

171-
return count;
155+
@Override
156+
public IEnumerable<TSource> _where(Func1<TSource, Boolean> predicate) {
157+
return new WhereArrayIterator<>(this.source, Utilities.combinePredicates(this.predicate, predicate));
172158
}
173159

174160
@Override
@@ -203,6 +189,20 @@ public List<TSource> _toList() {
203189

204190
return list;
205191
}
192+
193+
@Override
194+
public int _getCount(boolean onlyIfCheap) {
195+
if (onlyIfCheap)
196+
return -1;
197+
198+
int count = 0;
199+
for (TSource item : this.source) {
200+
if (this.predicate.apply(item))
201+
count = Math.addExact(count, 1);
202+
}
203+
204+
return count;
205+
}
206206
}
207207

208208

@@ -223,16 +223,6 @@ public Iterator<TSource> clone() {
223223
return new WhereListIterator<>(this.source, this.predicate);
224224
}
225225

226-
@Override
227-
public <TResult> IEnumerable<TResult> _select(Func1<TSource, TResult> selector) {
228-
return new WhereSelectListIterator<>(this.source, this.predicate, selector);
229-
}
230-
231-
@Override
232-
public IEnumerable<TSource> _where(Func1<TSource, Boolean> predicate) {
233-
return new WhereListIterator<>(this.source, Utilities.combinePredicates(this.predicate, predicate));
234-
}
235-
236226
@Override
237227
public boolean moveNext() {
238228
switch (this.state) {
@@ -255,17 +245,22 @@ public boolean moveNext() {
255245
}
256246

257247
@Override
258-
public int _getCount(boolean onlyIfCheap) {
259-
if (onlyIfCheap)
260-
return -1;
261-
262-
int count = 0;
263-
for (TSource item : this.source) {
264-
if (this.predicate.apply(item))
265-
count = Math.addExact(count, 1);
248+
public void close() {
249+
if (this.enumerator != null) {
250+
this.enumerator.close();
251+
this.enumerator = null;
266252
}
253+
super.close();
254+
}
267255

268-
return count;
256+
@Override
257+
public <TResult> IEnumerable<TResult> _select(Func1<TSource, TResult> selector) {
258+
return new WhereSelectListIterator<>(this.source, this.predicate, selector);
259+
}
260+
261+
@Override
262+
public IEnumerable<TSource> _where(Func1<TSource, Boolean> predicate) {
263+
return new WhereListIterator<>(this.source, Utilities.combinePredicates(this.predicate, predicate));
269264
}
270265

271266
@Override
@@ -302,12 +297,17 @@ public List<TSource> _toList() {
302297
}
303298

304299
@Override
305-
public void close() {
306-
if (this.enumerator != null) {
307-
this.enumerator.close();
308-
this.enumerator = null;
300+
public int _getCount(boolean onlyIfCheap) {
301+
if (onlyIfCheap)
302+
return -1;
303+
304+
int count = 0;
305+
for (TSource item : this.source) {
306+
if (this.predicate.apply(item))
307+
count = Math.addExact(count, 1);
309308
}
310-
super.close();
309+
310+
return count;
311311
}
312312
}
313313

@@ -329,16 +329,6 @@ public AbstractIterator<TSource> clone() {
329329
return new WhereEnumerableIterator<>(this.source, this.predicate);
330330
}
331331

332-
@Override
333-
public <TResult> IEnumerable<TResult> _select(Func1<TSource, TResult> selector) {
334-
return new WhereSelectEnumerableIterator<>(this.source, this.predicate, selector);
335-
}
336-
337-
@Override
338-
public IEnumerable<TSource> _where(Func1<TSource, Boolean> predicate) {
339-
return new WhereEnumerableIterator<>(this.source, Utilities.combinePredicates(this.predicate, predicate));
340-
}
341-
342332
@Override
343333
public boolean moveNext() {
344334
switch (this.state) {
@@ -361,17 +351,22 @@ public boolean moveNext() {
361351
}
362352

363353
@Override
364-
public int _getCount(boolean onlyIfCheap) {
365-
if (onlyIfCheap)
366-
return -1;
367-
368-
int count = 0;
369-
for (TSource item : this.source) {
370-
if (this.predicate.apply(item))
371-
count = Math.addExact(count, 1);
354+
public void close() {
355+
if (this.enumerator != null) {
356+
this.enumerator.close();
357+
this.enumerator = null;
372358
}
359+
super.close();
360+
}
373361

374-
return count;
362+
@Override
363+
public <TResult> IEnumerable<TResult> _select(Func1<TSource, TResult> selector) {
364+
return new WhereSelectEnumerableIterator<>(this.source, this.predicate, selector);
365+
}
366+
367+
@Override
368+
public IEnumerable<TSource> _where(Func1<TSource, Boolean> predicate) {
369+
return new WhereEnumerableIterator<>(this.source, Utilities.combinePredicates(this.predicate, predicate));
375370
}
376371

377372
@Override
@@ -408,12 +403,17 @@ public List<TSource> _toList() {
408403
}
409404

410405
@Override
411-
public void close() {
412-
if (this.enumerator != null) {
413-
this.enumerator.close();
414-
this.enumerator = null;
406+
public int _getCount(boolean onlyIfCheap) {
407+
if (onlyIfCheap)
408+
return -1;
409+
410+
int count = 0;
411+
for (TSource item : this.source) {
412+
if (this.predicate.apply(item))
413+
count = Math.addExact(count, 1);
415414
}
416-
super.close();
415+
416+
return count;
417417
}
418418
}
419419

@@ -438,24 +438,6 @@ public Iterator<TResult> clone() {
438438
return new WhereSelectArrayIterator<>(this.source, this.predicate, this.selector);
439439
}
440440

441-
@Override
442-
public int _getCount(boolean onlyIfCheap) {
443-
// In case someone uses Count() to force evaluation of
444-
// the selector, run it provided `onlyIfCheap` is false.
445-
if (onlyIfCheap)
446-
return -1;
447-
448-
int count = 0;
449-
for (TSource item : this.source) {
450-
if (this.predicate.apply(item)) {
451-
this.selector.apply(item);
452-
count = Math.addExact(count, 1);
453-
}
454-
}
455-
456-
return count;
457-
}
458-
459441
@Override
460442
public boolean moveNext() {
461443
switch (this.state) {
@@ -515,6 +497,24 @@ public List<TResult> _toList() {
515497

516498
return list;
517499
}
500+
501+
@Override
502+
public int _getCount(boolean onlyIfCheap) {
503+
// In case someone uses Count() to force evaluation of
504+
// the selector, run it provided `onlyIfCheap` is false.
505+
if (onlyIfCheap)
506+
return -1;
507+
508+
int count = 0;
509+
for (TSource item : this.source) {
510+
if (this.predicate.apply(item)) {
511+
this.selector.apply(item);
512+
count = Math.addExact(count, 1);
513+
}
514+
}
515+
516+
return count;
517+
}
518518
}
519519

520520

@@ -538,24 +538,6 @@ public Iterator<TResult> clone() {
538538
return new WhereSelectListIterator<>(this.source, this.predicate, this.selector);
539539
}
540540

541-
@Override
542-
public int _getCount(boolean onlyIfCheap) {
543-
// In case someone uses Count() to force evaluation of
544-
// the selector, run it provided `onlyIfCheap` is false.
545-
if (onlyIfCheap)
546-
return -1;
547-
548-
int count = 0;
549-
for (TSource item : this.source) {
550-
if (this.predicate.apply(item)) {
551-
this.selector.apply(item);
552-
count = Math.addExact(count, 1);
553-
}
554-
}
555-
556-
return count;
557-
}
558-
559541
@Override
560542
public boolean moveNext() {
561543
switch (this.state) {
@@ -577,6 +559,15 @@ public boolean moveNext() {
577559
}
578560
}
579561

562+
@Override
563+
public void close() {
564+
if (this.enumerator != null) {
565+
this.enumerator.close();
566+
this.enumerator = null;
567+
}
568+
super.close();
569+
}
570+
580571
@Override
581572
public <TResult2> IEnumerable<TResult2> _select(Func1<TResult, TResult2> selector) {
582573
return new WhereSelectListIterator<>(this.source, this.predicate, Utilities.combineSelectors(this.selector, selector));
@@ -616,12 +607,21 @@ public List<TResult> _toList() {
616607
}
617608

618609
@Override
619-
public void close() {
620-
if (this.enumerator != null) {
621-
this.enumerator.close();
622-
this.enumerator = null;
610+
public int _getCount(boolean onlyIfCheap) {
611+
// In case someone uses Count() to force evaluation of
612+
// the selector, run it provided `onlyIfCheap` is false.
613+
if (onlyIfCheap)
614+
return -1;
615+
616+
int count = 0;
617+
for (TSource item : this.source) {
618+
if (this.predicate.apply(item)) {
619+
this.selector.apply(item);
620+
count = Math.addExact(count, 1);
621+
}
623622
}
624-
super.close();
623+
624+
return count;
625625
}
626626
}
627627

@@ -646,24 +646,6 @@ public Iterator<TResult> clone() {
646646
return new WhereSelectEnumerableIterator<>(this.source, this.predicate, this.selector);
647647
}
648648

649-
@Override
650-
public int _getCount(boolean onlyIfCheap) {
651-
// In case someone uses Count() to force evaluation of
652-
// the selector, run it provided `onlyIfCheap` is false.
653-
if (onlyIfCheap)
654-
return -1;
655-
656-
int count = 0;
657-
for (TSource item : this.source) {
658-
if (this.predicate.apply(item)) {
659-
this.selector.apply(item);
660-
count = Math.addExact(count, 1);
661-
}
662-
}
663-
664-
return count;
665-
}
666-
667649
@Override
668650
public boolean moveNext() {
669651
switch (this.state) {
@@ -685,6 +667,15 @@ public boolean moveNext() {
685667
}
686668
}
687669

670+
@Override
671+
public void close() {
672+
if (this.enumerator != null) {
673+
this.enumerator.close();
674+
this.enumerator = null;
675+
}
676+
super.close();
677+
}
678+
688679
@Override
689680
public <TResult2> IEnumerable<TResult2> _select(Func1<TResult, TResult2> selector) {
690681
return new WhereSelectEnumerableIterator<>(this.source, this.predicate, Utilities.combineSelectors(this.selector, selector));
@@ -724,11 +715,20 @@ public List<TResult> _toList() {
724715
}
725716

726717
@Override
727-
public void close() {
728-
if (this.enumerator != null) {
729-
this.enumerator.close();
730-
this.enumerator = null;
718+
public int _getCount(boolean onlyIfCheap) {
719+
// In case someone uses Count() to force evaluation of
720+
// the selector, run it provided `onlyIfCheap` is false.
721+
if (onlyIfCheap)
722+
return -1;
723+
724+
int count = 0;
725+
for (TSource item : this.source) {
726+
if (this.predicate.apply(item)) {
727+
this.selector.apply(item);
728+
count = Math.addExact(count, 1);
729+
}
731730
}
732-
super.close();
731+
732+
return count;
733733
}
734734
}

0 commit comments

Comments
 (0)