Skip to content

Commit

Permalink
Enforce spacing around foreach colon with Checkstyle (apache#5271)
Browse files Browse the repository at this point in the history
  • Loading branch information
leventov authored and b-slim committed Jan 22, 2018
1 parent f99c27e commit a346bbc
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 64 deletions.
1 change: 1 addition & 0 deletions codestyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyLambdas" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="ignoreEnhancedForColon" value="false"/>
</module>
<module name="ParenPad"/>
<module name="SingleSpaceSeparator"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private void verifyJob(IndexGeneratorJob job) throws IOException
QueryableIndex index = HadoopDruidIndexerConfig.INDEX_IO.loadIndex(dir);
QueryableIndexIndexableAdapter adapter = new QueryableIndexIndexableAdapter(index);

for (Rowboat row: adapter.getRows()) {
for (Rowboat row : adapter.getRows()) {
Object[] metrics = row.getMetrics();

rowCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testBufferAggregator()
ByteBuffer buffer = ByteBuffer.wrap(new byte[Longs.BYTES]);
aggregator.init(buffer, 0);

for (Timestamp value: values) {
for (Timestamp value : values) {
aggregate(selector, aggregator, buffer, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@

package io.druid.query.aggregation.datasketches.quantiles;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;

import com.yahoo.sketches.quantiles.DoublesSketch;
import io.druid.java.util.common.IAE;
import io.druid.query.aggregation.AggregatorFactory;
import io.druid.query.aggregation.AggregatorUtil;
import io.druid.query.aggregation.PostAggregator;
import io.druid.query.cache.CacheKeyBuilder;

import com.yahoo.sketches.quantiles.DoublesSketch;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.Set;

public class DoublesSketchToHistogramPostAggregator implements PostAggregator
{
Expand Down Expand Up @@ -138,7 +136,7 @@ public byte[] getCacheKey()
{
final CacheKeyBuilder builder = new CacheKeyBuilder(
AggregatorUtil.QUANTILES_DOUBLES_SKETCH_TO_HISTOGRAM_CACHE_TYPE_ID).appendCacheable(field);
for (final double value: splitPoints) {
for (final double value : splitPoints) {
builder.appendDouble(value);
}
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@

package io.druid.query.aggregation.datasketches.quantiles;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;

import com.yahoo.sketches.quantiles.DoublesSketch;
import io.druid.java.util.common.IAE;
import io.druid.query.aggregation.AggregatorFactory;
import io.druid.query.aggregation.AggregatorUtil;
import io.druid.query.aggregation.PostAggregator;
import io.druid.query.cache.CacheKeyBuilder;

import com.yahoo.sketches.quantiles.DoublesSketch;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.Set;

public class DoublesSketchToQuantilesPostAggregator implements PostAggregator
{
Expand Down Expand Up @@ -132,7 +130,7 @@ public byte[] getCacheKey()
{
final CacheKeyBuilder builder = new CacheKeyBuilder(
AggregatorUtil.QUANTILES_DOUBLES_SKETCH_TO_QUANTILES_CACHE_TYPE_ID).appendCacheable(field);
for (final double value: fractions) {
for (final double value : fractions) {
builder.appendDouble(value);
}
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void ingestingSketches() throws Exception
Object histogramObject = row.getRaw("histogram");
Assert.assertTrue(histogramObject instanceof double[]);
double[] histogram = (double[]) histogramObject;
for (final double bin: histogram) {
for (final double bin : histogram) {
Assert.assertEquals(100, bin, 100 * 0.2); // 400 items uniformly
// distributed into 4 bins
}
Expand Down Expand Up @@ -221,7 +221,7 @@ public void buildingSketchesAtIngestionTime() throws Exception
Assert.assertTrue(histogramObject instanceof double[]);
double[] histogram = (double[]) histogramObject;
Assert.assertEquals(4, histogram.length);
for (final double bin: histogram) {
for (final double bin : histogram) {
Assert.assertEquals(100, bin, 100 * 0.2); // 400 items uniformly
// distributed into 4 bins
}
Expand Down Expand Up @@ -292,7 +292,7 @@ public void buildingSketchesAtQueryTime() throws Exception
Object histogramObject = row.getRaw("histogram");
Assert.assertTrue(histogramObject instanceof double[]);
double[] histogram = (double[]) histogramObject;
for (final double bin: histogram) {
for (final double bin : histogram) {
Assert.assertEquals(100, bin, 100 * 0.2); // 400 items uniformly
// distributed into 4 bins
}
Expand Down Expand Up @@ -365,7 +365,7 @@ public void QueryingDataWithFieldNameValueAsFloatInsteadOfSketch() throws Except
Object histogramObject = row.getRaw("histogram");
Assert.assertTrue(histogramObject instanceof double[]);
double[] histogram = (double[]) histogramObject;
for (final double bin: histogram) {
for (final double bin : histogram) {
Assert.assertEquals(100, bin, 100 * 0.2); // 400 items uniformly
// distributed into 4 bins
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@

package io.druid.server.lookup.cache.polling;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class OnHeapPollingCache<K, V> implements PollingCache<K, V>
{
Expand All @@ -46,33 +44,25 @@ public OnHeapPollingCache(Iterable<Map.Entry<K, V>> entries)
} else {
ImmutableSet.Builder<V> setOfValuesBuilder = ImmutableSet.builder();
ImmutableMap.Builder<K, V> mapBuilder = ImmutableMap.builder();
for (Map.Entry<K, V> entry: entries
) {
for (Map.Entry<K, V> entry : entries) {
setOfValuesBuilder.add(entry.getValue());
mapBuilder.put(entry.getKey(), entry.getValue());
}
final Set<V> setOfValues = setOfValuesBuilder.build();
immutableMap = mapBuilder.build();
immutableReverseMap = ImmutableMap.copyOf(Maps.asMap(
setOfValues, new Function<V, List<K>>()
{
@Override
public List<K> apply(final V input)
{
return Lists.newArrayList(Maps.filterKeys(immutableMap, new Predicate<K>()
{
@Override
public boolean apply(K key)
{
V retVal = immutableMap.get(key);
if (retVal == null) {
return false;
}
return retVal.equals(input);
}
}).keySet());
}
}));
immutableReverseMap = ImmutableMap.copyOf(
Maps.asMap(
setOfValues,
val -> immutableMap
.keySet()
.stream()
.filter(key -> {
V retVal = immutableMap.get(key);
return retVal != null && retVal.equals(val);
})
.collect(Collectors.toList())
)
);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class JdbcDataFetcherTest
);

@Before
public void setUp() throws InterruptedException
public void setUp()
{
jdbcDataFetcher = new JdbcDataFetcher(derbyConnectorRule.getMetadataConnectorConfig(), "tableName", "keyColumn", "valueColumn",
100);
Expand Down Expand Up @@ -91,7 +91,7 @@ public void tearDown()
}

@Test
public void testFetch() throws InterruptedException
public void testFetch()
{
Assert.assertEquals("null check", null, jdbcDataFetcher.fetch("baz"));
assertMapLookup(lookupMap, jdbcDataFetcher);
Expand All @@ -101,26 +101,20 @@ public void testFetch() throws InterruptedException
public void testFetchAll()
{
ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder();
for (Map.Entry<String, String> entry: jdbcDataFetcher.fetchAll()
) {
mapBuilder.put(entry.getKey(), entry.getValue());
}
jdbcDataFetcher.fetchAll().forEach(mapBuilder::put);
Assert.assertEquals("maps should match", lookupMap, mapBuilder.build());
}

@Test
public void testFetchKeys()
{
ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder();
for (Map.Entry<String, String> entry: jdbcDataFetcher.fetch(lookupMap.keySet())) {
mapBuilder.put(entry.getKey(), entry.getValue());
}

jdbcDataFetcher.fetch(lookupMap.keySet()).forEach(mapBuilder::put);
Assert.assertEquals(lookupMap, mapBuilder.build());
}

@Test
public void testReverseFetch() throws InterruptedException
public void testReverseFetch()
{
Assert.assertEquals(
"reverse lookup should match",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public Result<SelectResultValue> apply(Object input)
for (int idx = 0; idx < dimOutputNames.size(); idx++) {
if (!cachedOutputNames.get(idx).equals(dimOutputNames.get(idx))) {
// rename outputName in the EventHolder
for (EventHolder eventHolder: eventHolders) {
for (EventHolder eventHolder : eventHolders) {
Object obj = eventHolder.getEvent().remove(cachedOutputNames.get(idx));
if (obj != null) {
eventHolder.getEvent().put(dimOutputNames.get(idx), obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class CompressedLongsSerdeTest
public static Iterable<Object[]> compressionStrategies()
{
List<Object[]> data = new ArrayList<>();
for (CompressionFactory.LongEncodingStrategy encodingStrategy: CompressionFactory.LongEncodingStrategy.values()) {
for (CompressionFactory.LongEncodingStrategy encodingStrategy : CompressionFactory.LongEncodingStrategy.values()) {
for (CompressionStrategy strategy : CompressionStrategy.values()) {
data.add(new Object[]{encodingStrategy, strategy, ByteOrder.BIG_ENDIAN});
data.add(new Object[]{encodingStrategy, strategy, ByteOrder.LITTLE_ENDIAN});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
request.setAttribute(AVATICA_QUERY_ATTRIBUTE, requestBytes);
} else if (isQueryEndpoint && HttpMethod.DELETE.is(request.getMethod())) {
// query cancellation request
for (final Server server: hostFinder.getAllServers()) {
for (final Server server : hostFinder.getAllServers()) {
// send query cancellation to all brokers this query may have gone to
// to keep the code simple, the proxy servlet will also send a request to one of the default brokers
if (!server.getHost().equals(defaultServer.getHost())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private ServiceDiscovery createAndAnnounceServices(List<String> serviceNames) th
.basePath("/test")
.client(curator)
.build();
for (String serviceName: serviceNames) {
for (String serviceName : serviceNames) {
String serviceNameToUse = CuratorServiceUtils.makeCanonicalServiceName(serviceName);
ServiceInstance instance = ServiceInstance.<Void>builder()
.name(serviceNameToUse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void testPeriodSegmentGranularity()
final Optional<SortedSet<Interval>> sortedSetOptional = spec.bucketIntervals();
final SortedSet<Interval> intervals = sortedSetOptional.get();
ArrayList<Long> actualIntervals = new ArrayList<>();
for (Interval interval: intervals) {
for (Interval interval : intervals) {
actualIntervals.add(interval.toDurationMillis());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private static VersionedIntervalTimeline<String, DataSegment> createTimeline(
orderedSpecs.sort((s1, s2) -> Comparators.intervalsByStartThenEnd().compare(s1.totalInterval, s2.totalInterval));
Collections.reverse(orderedSpecs);

for (SegmentGenerateSpec spec: orderedSpecs) {
for (SegmentGenerateSpec spec : orderedSpecs) {
Interval remaininInterval = spec.totalInterval;

while (!Intervals.isEmpty(remaininInterval)) {
Expand Down

0 comments on commit a346bbc

Please sign in to comment.