/
InternalIterable.java
116 lines (109 loc) · 3.96 KB
/
InternalIterable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright (c) 2015 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.api;
import java.util.function.Consumer;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.ordered.OrderedIterable;
/**
* The base interface for all Eclipse Collections. All Eclipse Collections are internally iterable, and this interface provides
* the base set of internal iterators that every Eclipse collection should implement.
*/
public interface InternalIterable<T>
extends Iterable<T>
{
/**
* The procedure is executed for each element in the iterable.
* <p>
* Example using a Java 8 lambda:
* <pre>
* people.forEach(Procedures.cast(person -> LOGGER.info(person.getName())));
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* people.forEach(new Procedure<Person>()
* {
* public void value(Person person)
* {
* LOGGER.info(person.getName());
* }
* });
* </pre>
* NOTE: This method started to conflict with {@link Iterable#forEach(java.util.function.Consumer)}
* since Java 1.8. It is recommended to use {@link RichIterable#each(Procedure)} instead to avoid casting to Procedure.
*
* @see RichIterable#each(Procedure)
* @see Iterable#forEach(java.util.function.Consumer)
*/
@SuppressWarnings("UnnecessaryFullyQualifiedName")
void forEach(Procedure<? super T> procedure);
@Override
default void forEach(Consumer<? super T> consumer)
{
Procedure<? super T> procedure = consumer::accept;
this.forEach(procedure);
}
/**
* Iterates over the iterable passing each element and the current relative int index to the specified instance of
* ObjectIntProcedure.
* <p>
* Example using a Java 8 lambda:
* <pre>
* people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* people.forEachWithIndex(new ObjectIntProcedure<Person>()
* {
* public void value(Person person, int index)
* {
* LOGGER.info("Index: " + index + " person: " + person.getName());
* }
* });
* </pre>
*
* @deprecated in 6.0. Use {@link OrderedIterable#forEachWithIndex(ObjectIntProcedure)} instead.
*/
@Deprecated
void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure);
/**
* The procedure2 is evaluated for each element in the iterable with the specified parameter provided
* as the second argument.
* <p>
* Example using a Java 8 lambda:
* <pre>
* people.forEachWith((Person person, Person other) ->
* {
* if (person.isRelatedTo(other))
* {
* LOGGER.info(person.getName());
* }
* }, fred);
* </pre>
* <p>
* Example using an anonymous inner class:
* <pre>
* people.forEachWith(new Procedure2<Person, Person>()
* {
* public void value(Person person, Person other)
* {
* if (person.isRelatedTo(other))
* {
* LOGGER.info(person.getName());
* }
* }
* }, fred);
* </pre>
*/
<P> void forEachWith(Procedure2<? super T, ? super P> procedure, P parameter);
}