-
Notifications
You must be signed in to change notification settings - Fork 614
/
abstractPrimitiveIterable.stg
198 lines (166 loc) · 4.4 KB
/
abstractPrimitiveIterable.stg
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import "copyright.stg"
import "primitiveEquals.stg"
import "primitiveHashCode.stg"
import "primitiveLiteral.stg"
targetPath() ::= "org/eclipse/collections/impl/primitive"
fileName(primitive) ::= "Abstract<primitive.name>Iterable"
class(primitive) ::= <<
<body(primitive.type, primitive.name)>
>>
body(type, name) ::= <<
<copyright()>
package org.eclipse.collections.impl.primitive;
import java.util.Arrays;
import org.eclipse.collections.api.<name>Iterable;
import org.eclipse.collections.api.Lazy<name>Iterable;
import org.eclipse.collections.api.bag.primitive.Mutable<name>Bag;
import org.eclipse.collections.api.block.predicate.primitive.<name>Predicate;
import org.eclipse.collections.api.list.primitive.Mutable<name>List;
import org.eclipse.collections.api.set.primitive.Mutable<name>Set;
import org.eclipse.collections.impl.bag.mutable.primitive.<name>HashBag;
import org.eclipse.collections.impl.lazy.primitive.Lazy<name>IterableAdapter;
import org.eclipse.collections.impl.list.mutable.primitive.<name>ArrayList;
import org.eclipse.collections.impl.set.mutable.primitive.<name>HashSet;
/**
* This file was automatically generated from template file abstractPrimitiveIterable.stg.
* @since 6.0
*/
public abstract class Abstract<name>Iterable implements <name>Iterable
{
@Override
public String toString()
{
return this.makeString("[", ", ", "]");
}
public String makeString()
{
return this.makeString(", ");
}
public String makeString(String separator)
{
return this.makeString("", separator, "");
}
public String makeString(String start, String separator, String end)
{
Appendable stringBuilder = new StringBuilder();
this.appendString(stringBuilder, start, separator, end);
return stringBuilder.toString();
}
public void appendString(Appendable appendable)
{
this.appendString(appendable, ", ");
}
public void appendString(Appendable appendable, String separator)
{
this.appendString(appendable, "", separator, "");
}
<(arithmeticMethods.(type))()>
public Mutable<name>List toList()
{
return <name>ArrayList.newList(this);
}
public Mutable<name>Set toSet()
{
return <name>HashSet.newSet(this);
}
public Mutable<name>Bag toBag()
{
return <name>HashBag.newBag(this);
}
public boolean containsAll(<type>... source)
{
for (<type> item : source)
{
if (!this.contains(item))
{
return false;
}
}
return true;
}
public boolean containsAll(<name>Iterable source)
{
return source.allSatisfy(new <name>Predicate()
{
public boolean accept(<type> each)
{
return Abstract<name>Iterable.this.contains(each);
}
});
}
public boolean isEmpty()
{
return this.size() == 0;
}
public boolean notEmpty()
{
return this.size() != 0;
}
}
>>
arithmeticMethods ::= [
"boolean": "noMethods",
"default": "allMethods"
]
allMethods() ::= <<
public <type> minIfEmpty(<type> defaultValue)
{
if (this.isEmpty())
{
return defaultValue;
}
return this.min();
}
public <type> maxIfEmpty(<type> defaultValue)
{
if (this.isEmpty())
{
return defaultValue;
}
return this.max();
}
public double average()
{
if (this.isEmpty())
{
throw new ArithmeticException();
}
return (double) this.sum() / (double) this.size();
}
public double median()
{
if (this.isEmpty())
{
throw new ArithmeticException();
}
<type>[] sortedArray = this.toSortedArray();
int middleIndex = sortedArray.length >\> 1;
if (sortedArray.length > 1 && (sortedArray.length & 1) == 0)
{
<type> first = sortedArray[middleIndex];
<type> second = sortedArray[middleIndex - 1];
return ((double) first + (double) second) / 2.0;
}
return (double) sortedArray[middleIndex];
}
public <type>[] toSortedArray()
{
<type>[] array = this.toArray();
Arrays.sort(array);
return array;
}
public Mutable<name>List toSortedList()
{
return this.toList().sortThis();
}
public Lazy<name>Iterable asLazy()
{
return new Lazy<name>IterableAdapter(this);
}
>>
noMethods() ::= <<
public Lazy<name>Iterable asLazy()
{
return new Lazy<name>IterableAdapter(this);
}
>>