Skip to content

Commit

Permalink
Prohibit for loops which could be foreach with IntelliJ (apache#4653)
Browse files Browse the repository at this point in the history
* Replace for with foreach

* Replace for with for-each in GroupByQueryEngineV2

* Remove io.druid.collections.IntList
  • Loading branch information
leventov authored and drcrallen committed Aug 9, 2017
1 parent f18cc5d commit f5d4171
Show file tree
Hide file tree
Showing 35 changed files with 150 additions and 418 deletions.
15 changes: 14 additions & 1 deletion .idea/inspectionProfiles/Druid.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public void testContextualTimestampList() throws Exception
};
TimestampSpec spec = new TimestampSpec("TIMEstamp", DATE_FORMAT, null);

for (int i = 0; i < dates.length; ++i) {
String date = dates[i];
for (String date : dates) {
DateTime dateTime = spec.extractTimestamp(ImmutableMap.<String, Object>of("TIMEstamp", date));
DateTime expectedDateTime = ISODateTimeFormat.dateHourMinuteSecond().parseDateTime(date);
Assert.assertEquals(expectedDateTime, dateTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public void setup()
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void parseNoContext(Blackhole blackhole)
{
for (int i = 0; i < rows.length; ++i) {
blackhole.consume(timeFn.apply(rows[i]).getMillis());
for (String row : rows) {
blackhole.consume(timeFn.apply(row).getMillis());
}
}

Expand All @@ -92,10 +92,10 @@ public void parseWithContext(Blackhole blackhole)
{
String lastTimeString = null;
long lastTime = 0L;
for (int i = 0; i < rows.length; ++i) {
if (!rows[i].equals(lastTimeString)) {
lastTimeString = rows[i];
lastTime = timeFn.apply(rows[i]).getMillis();
for (String row : rows) {
if (!row.equals(lastTimeString)) {
lastTimeString = row;
lastTime = timeFn.apply(row).getMillis();
}
blackhole.consume(lastTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ private void initDistribution()
}
}
// give them all equal probability, the library will normalize probabilities to sum to 1.0
for (int i = 0; i < enumeratedValues.size(); i++) {
probabilities.add(new Pair<>(enumeratedValues.get(i), 0.1));
for (Object enumeratedValue : enumeratedValues) {
probabilities.add(new Pair<>(enumeratedValue, 0.1));
}
distribution = new EnumeratedTreeDistribution<>(probabilities);
break;
Expand Down
134 changes: 0 additions & 134 deletions common/src/main/java/io/druid/collections/IntList.java

This file was deleted.

10 changes: 0 additions & 10 deletions common/src/main/java/io/druid/common/utils/SerializerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.common.primitives.Floats;
import com.google.common.primitives.Ints;
import com.google.common.primitives.Longs;
import io.druid.collections.IntList;
import io.druid.java.util.common.StringUtils;

import java.io.IOException;
Expand Down Expand Up @@ -216,15 +215,6 @@ public void writeInts(OutputStream out, int[] ints) throws IOException
}
}

public void writeInts(OutputStream out, IntList ints) throws IOException
{
writeInt(out, ints.length());

for (int i = 0; i < ints.length(); i++) {
writeInt(out, ints.get(i));
}
}

public int[] readInts(InputStream in) throws IOException
{
int size = readInt(in);
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/java/io/druid/math/expr/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ public static Expr flatten(Expr expr)
List<Expr> args = functionExpr.args;
boolean flattened = false;
List<Expr> flattening = Lists.newArrayListWithCapacity(args.size());
for (int i = 0; i < args.size(); i++) {
Expr flatten = flatten(args.get(i));
flattened |= flatten != args.get(i);
for (Expr arg : args) {
Expr flatten = flatten(arg);
flattened |= flatten != arg;
flattening.add(flatten);
}
if (Evals.isAllConstants(flattening)) {
Expand Down
120 changes: 0 additions & 120 deletions common/src/test/java/io/druid/collections/IntListTest.java

This file was deleted.

Loading

0 comments on commit f5d4171

Please sign in to comment.