Skip to content
Merged

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions codestyle/druid-forbidden-apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ java.lang.Math#random() @ Use ThreadLocalRandom.current()
java.util.regex.Pattern#matches(java.lang.String,java.lang.CharSequence) @ Use String.startsWith(), endsWith(), contains(), or compile and cache a Pattern explicitly
org.apache.commons.io.FileUtils#getTempDirectory() @ Use org.junit.rules.TemporaryFolder for tests instead
java.lang.Class#getCanonicalName() @ Class.getCanonicalName can return null for anonymous types, use Class.getName instead.
com.google.common.base.Objects#firstNonNull(java.lang.Object, java.lang.Object) @ Use org.apache.druid.common.guava.GuavaUtils#firstNonNull(java.lang.Object, java.lang.Object) instead (probably... the GuavaUtils method return object is nullable)

@defaultMessage Use Locale.ENGLISH
com.ibm.icu.text.DateFormatSymbols#<init>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

package org.apache.druid.collections;

import org.apache.druid.common.guava.GuavaUtils;
import org.apache.druid.java.util.common.guava.MergeIterable;
import org.apache.druid.java.util.common.guava.nary.BinaryFn;

import java.util.Comparator;
import java.util.Iterator;
import java.util.function.BinaryOperator;

/**
*/
public class CombiningIterable<InType> implements Iterable<InType>
public class CombiningIterable<T> implements Iterable<T>
{
/**
* Creates a CombiningIterable around a MergeIterable such that equivalent elements are thrown away
Expand All @@ -38,50 +39,40 @@ public class CombiningIterable<InType> implements Iterable<InType>
*
* @param in An Iterable of Iterables to be merged
* @param comparator the Comparator to determine sort and equality
* @param <InType> Type of object
* @param <T> Type of object
* @return An Iterable that is the merge of all Iterables from in such that there is only one instance of
* equivalent objects.
*/
@SuppressWarnings("unchecked")
public static <InType> CombiningIterable<InType> createSplatted(
Iterable<? extends Iterable<InType>> in,
Comparator<InType> comparator
public static <T> CombiningIterable<T> createSplatted(
Iterable<? extends Iterable<T>> in,
Comparator<T> comparator
)
{
return create(
new MergeIterable<InType>(comparator, (Iterable<Iterable<InType>>) in),
new MergeIterable<>(comparator, (Iterable<Iterable<T>>) in),
comparator,
new BinaryFn<InType, InType, InType>()
{
@Override
public InType apply(InType arg1, InType arg2)
{
if (arg1 == null) {
return arg2;
}
return arg1;
}
}
GuavaUtils::firstNonNull
);
}

public static <InType> CombiningIterable<InType> create(
Iterable<InType> it,
Comparator<InType> comparator,
BinaryFn<InType, InType, InType> fn
public static <T> CombiningIterable<T> create(
Iterable<T> it,
Comparator<T> comparator,
BinaryOperator<T> fn
)
{
return new CombiningIterable<InType>(it, comparator, fn);
return new CombiningIterable<>(it, comparator, fn);
}

private final Iterable<InType> it;
private final Comparator<InType> comparator;
private final BinaryFn<InType, InType, InType> fn;
private final Iterable<T> it;
private final Comparator<T> comparator;
private final BinaryOperator<T> fn;

public CombiningIterable(
Iterable<InType> it,
Comparator<InType> comparator,
BinaryFn<InType, InType, InType> fn
Iterable<T> it,
Comparator<T> comparator,
BinaryOperator<T> fn
)
{
this.it = it;
Expand All @@ -90,7 +81,7 @@ public CombiningIterable(
}

@Override
public Iterator<InType> iterator()
public Iterator<T> iterator()
{
return CombiningIterator.create(it.iterator(), comparator, fn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@

import com.google.common.collect.Iterators;
import com.google.common.collect.PeekingIterator;
import org.apache.druid.java.util.common.guava.nary.BinaryFn;

import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.BinaryOperator;

/**
*/
public class CombiningIterator<InType> implements Iterator<InType>
public class CombiningIterator<T> implements Iterator<T>
{
public static <InType> CombiningIterator<InType> create(
Iterator<InType> it,
Comparator<InType> comparator,
BinaryFn<InType, InType, InType> fn
public static <T> CombiningIterator<T> create(
Iterator<T> it,
Comparator<T> comparator,
BinaryOperator<T> fn
)
{
return new CombiningIterator<InType>(it, comparator, fn);
return new CombiningIterator<>(it, comparator, fn);
}

private final PeekingIterator<InType> it;
private final Comparator<InType> comparator;
private final BinaryFn<InType, InType, InType> fn;
private final PeekingIterator<T> it;
private final Comparator<T> comparator;
private final BinaryOperator<T> fn;

public CombiningIterator(
Iterator<InType> it,
Comparator<InType> comparator,
BinaryFn<InType, InType, InType> fn
Iterator<T> it,
Comparator<T> comparator,
BinaryOperator<T> fn
)
{
this.it = Iterators.peekingIterator(it);
Expand All @@ -62,13 +62,13 @@ public boolean hasNext()
}

@Override
public InType next()
public T next()
{
if (!hasNext()) {
throw new NoSuchElementException();
}

InType res = null;
T res = null;

while (hasNext()) {
if (res == null) {
Expand Down

This file was deleted.

Loading