http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/tools/RelBuilder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java index e5fb2aa..491be00 100644 --- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java +++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java @@ -31,12 +31,21 @@ import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.core.Aggregate; import org.apache.calcite.rel.core.AggregateCall; import org.apache.calcite.rel.core.CorrelationId; +import org.apache.calcite.rel.core.Filter; +import org.apache.calcite.rel.core.Intersect; +import org.apache.calcite.rel.core.Join; import org.apache.calcite.rel.core.JoinRelType; +import org.apache.calcite.rel.core.Match; +import org.apache.calcite.rel.core.Minus; import org.apache.calcite.rel.core.Project; import org.apache.calcite.rel.core.RelFactories; +import org.apache.calcite.rel.core.SemiJoin; import org.apache.calcite.rel.core.Sort; import org.apache.calcite.rel.core.TableScan; +import org.apache.calcite.rel.core.Union; import org.apache.calcite.rel.core.Values; +import org.apache.calcite.rel.logical.LogicalFilter; +import org.apache.calcite.rel.logical.LogicalProject; import org.apache.calcite.rel.metadata.RelMetadataQuery; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeFactory; @@ -73,8 +82,6 @@ import org.apache.calcite.util.Util; import org.apache.calcite.util.mapping.Mapping; import org.apache.calcite.util.mapping.Mappings; -import com.google.common.base.Function; -import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -109,21 +116,14 @@ import static org.apache.calcite.util.Static.RESOURCE; * * <p>{@code RelBuilder} uses factories to create relational expressions. * By default, it uses the default factories, which create logical relational - * expressions ({@link org.apache.calcite.rel.logical.LogicalFilter}, - * {@link org.apache.calcite.rel.logical.LogicalProject} and so forth). + * expressions ({@link LogicalFilter}, + * {@link LogicalProject} and so forth). * But you could override those factories so that, say, {@code filter} creates * instead a {@code HiveFilter}. * * <p>It is not thread-safe. */ public class RelBuilder { - private static final Function<RexNode, String> FN_TYPE = - new Function<RexNode, String>() { - public String apply(RexNode input) { - return input + ": " + input.getType(); - } - }; - protected final RelOptCluster cluster; protected final RelOptSchema relOptSchema; private final RelFactories.FilterFactory filterFactory; @@ -222,11 +222,7 @@ public class RelBuilder { /** Creates a {@link RelBuilderFactory}, a partially-created RelBuilder. * Just add a {@link RelOptCluster} and a {@link RelOptSchema} */ public static RelBuilderFactory proto(final Context context) { - return new RelBuilderFactory() { - public RelBuilder create(RelOptCluster cluster, RelOptSchema schema) { - return new RelBuilder(context, cluster, schema); - } - }; + return (cluster, schema) -> new RelBuilder(context, cluster, schema); } /** Creates a {@link RelBuilderFactory} that uses a given set of factories. */ @@ -434,8 +430,8 @@ public class RelBuilder { * given alias. Searches for the relation starting at the top of the * stack. */ public RexNode field(int inputCount, String alias, String fieldName) { - Preconditions.checkNotNull(alias); - Preconditions.checkNotNull(fieldName); + Objects.requireNonNull(alias); + Objects.requireNonNull(fieldName); final List<String> fields = new ArrayList<>(); for (int inputOrdinal = 0; inputOrdinal < inputCount; ++inputOrdinal) { final Frame frame = peek_(inputOrdinal); @@ -545,7 +541,8 @@ public class RelBuilder { final RelDataType type = builder.deriveReturnType(operator, operandList); if (type == null) { throw new IllegalArgumentException("cannot derive type: " + operator - + "; operands: " + Lists.transform(operandList, FN_TYPE)); + + "; operands: " + + Lists.transform(operandList, e -> e + ": " + e.getType())); } return builder.makeCall(type, operator, operandList); } @@ -656,7 +653,7 @@ public class RelBuilder { /** Creates an empty group key. */ public GroupKey groupKey() { - return groupKey(ImmutableList.<RexNode>of()); + return groupKey(ImmutableList.of()); } /** Creates a group key. */ @@ -720,11 +717,7 @@ public class RelBuilder { fields(ImmutableIntList.of(groupSet.toArray())); final List<ImmutableList<RexNode>> nodeLists = Lists.transform(groupSets, - new Function<ImmutableBitSet, ImmutableList<RexNode>>() { - public ImmutableList<RexNode> apply(ImmutableBitSet input) { - return fields(ImmutableIntList.of(input.toArray())); - } - }); + bitSet -> fields(ImmutableIntList.of(bitSet.toArray()))); return groupKey(nodes, indicator, nodeLists); } @@ -884,7 +877,7 @@ public class RelBuilder { // Methods that create relational expressions - /** Creates a {@link org.apache.calcite.rel.core.TableScan} of the table + /** Creates a {@link TableScan} of the table * with a given name. * * <p>Throws if the table does not exist. @@ -897,14 +890,14 @@ public class RelBuilder { final List<String> names = ImmutableList.copyOf(tableNames); final RelOptTable relOptTable = relOptSchema.getTableForMember(names); if (relOptTable == null) { - throw RESOURCE.tableNotFound(Joiner.on(".").join(names)).ex(); + throw RESOURCE.tableNotFound(String.join(".", names)).ex(); } final RelNode scan = scanFactory.createScan(cluster, relOptTable); push(scan); return this; } - /** Creates a {@link org.apache.calcite.rel.core.TableScan} of the table + /** Creates a {@link TableScan} of the table * with a given name. * * <p>Throws if the table does not exist. @@ -917,7 +910,7 @@ public class RelBuilder { return scan(ImmutableList.copyOf(tableNames)); } - /** Creates a {@link org.apache.calcite.rel.core.Filter} of an array of + /** Creates a {@link Filter} of an array of * predicates. * * <p>The predicates are combined using AND, @@ -927,7 +920,7 @@ public class RelBuilder { return filter(ImmutableList.copyOf(predicates)); } - /** Creates a {@link org.apache.calcite.rel.core.Filter} of a list of + /** Creates a {@link Filter} of a list of * predicates. * * <p>The predicates are combined using AND, @@ -948,7 +941,7 @@ public class RelBuilder { return this; } - /** Creates a {@link org.apache.calcite.rel.core.Project} of the given list + /** Creates a {@link Project} of the given list * of expressions. * * <p>Infers names as would {@link #project(Iterable, Iterable)} if all @@ -957,10 +950,10 @@ public class RelBuilder { * @param nodes Expressions */ public RelBuilder project(Iterable<? extends RexNode> nodes) { - return project(nodes, ImmutableList.<String>of()); + return project(nodes, ImmutableList.of()); } - /** Creates a {@link org.apache.calcite.rel.core.Project} of the given list + /** Creates a {@link Project} of the given list * of expressions and field names. * * @param nodes Expressions @@ -971,7 +964,7 @@ public class RelBuilder { return project(nodes, fieldNames, false); } - /** Creates a {@link org.apache.calcite.rel.core.Project} of the given list + /** Creates a {@link Project} of the given list * of expressions, using the given names. * * <p>Names are deduced as follows: @@ -983,7 +976,7 @@ public class RelBuilder { * or is a cast an input field, * uses the input field name; otherwise * <li>If an expression is a call to - * {@link org.apache.calcite.sql.fun.SqlStdOperatorTable#AS} + * {@link SqlStdOperatorTable#AS} * (see {@link #alias}), removes the call but uses the intended alias. * </ul> * @@ -1039,7 +1032,7 @@ public class RelBuilder { field = new Field(frame.fields.get(index).left, fieldType); break; default: - field = new Field(ImmutableSet.<String>of(), fieldType); + field = new Field(ImmutableSet.of(), fieldType); break; } uniqueNameList.add(name); @@ -1065,13 +1058,13 @@ public class RelBuilder { return this; } - /** Creates a {@link org.apache.calcite.rel.core.Project} of the given + /** Creates a {@link Project} of the given * expressions. */ public RelBuilder project(RexNode... nodes) { return project(ImmutableList.copyOf(nodes)); } - /** Creates a {@link org.apache.calcite.rel.core.Project} of the given + /** Creates a {@link Project} of the given * expressions and field names, and optionally optimizing. * * <p>If {@code fieldNames} is null, or if a particular entry in @@ -1195,19 +1188,19 @@ public class RelBuilder { } } - /** Creates an {@link org.apache.calcite.rel.core.Aggregate} that makes the + /** Creates an {@link Aggregate} that makes the * relational expression distinct on all fields. */ public RelBuilder distinct() { return aggregate(groupKey(fields())); } - /** Creates an {@link org.apache.calcite.rel.core.Aggregate} with an array of + /** Creates an {@link Aggregate} with an array of * calls. */ public RelBuilder aggregate(GroupKey groupKey, AggCall... aggCalls) { return aggregate(groupKey, ImmutableList.copyOf(aggCalls)); } - /** Creates an {@link org.apache.calcite.rel.core.Aggregate} with a list of + /** Creates an {@link Aggregate} with a list of * calls. */ public RelBuilder aggregate(GroupKey groupKey, Iterable<AggCall> aggCalls) { final Registrar registrar = new Registrar(); @@ -1326,7 +1319,7 @@ public class RelBuilder { String name = aggregateFields.get(i).getName(); RelDataTypeField fieldType = new RelDataTypeFieldImpl(name, i, node.getType()); - fields.add(new Field(ImmutableSet.<String>of(), fieldType)); + fields.add(new Field(ImmutableSet.of(), fieldType)); break; } i++; @@ -1337,7 +1330,7 @@ public class RelBuilder { final RelDataTypeField field = aggregateFields.get(i); final RelDataTypeField fieldType = new RelDataTypeFieldImpl(field.getName(), i, field.getType()); - fields.add(new Field(ImmutableSet.<String>of(), fieldType)); + fields.add(new Field(ImmutableSet.of(), fieldType)); i++; } } @@ -1347,7 +1340,7 @@ public class RelBuilder { final RelDataTypeField fieldType = new RelDataTypeFieldImpl(aggregateFields.get(i + j).getName(), i + j, call.getType()); - fields.add(new Field(ImmutableSet.<String>of(), fieldType)); + fields.add(new Field(ImmutableSet.of(), fieldType)); } stack.push(new Frame(aggregate, fields.build())); return this; @@ -1378,7 +1371,7 @@ public class RelBuilder { } } - /** Creates a {@link org.apache.calcite.rel.core.Union} of the two most recent + /** Creates a {@link Union} of the two most recent * relational expressions on the stack. * * @param all Whether to create UNION ALL @@ -1387,7 +1380,7 @@ public class RelBuilder { return union(all, 2); } - /** Creates a {@link org.apache.calcite.rel.core.Union} of the {@code n} + /** Creates a {@link Union} of the {@code n} * most recent relational expressions on the stack. * * @param all Whether to create UNION ALL @@ -1397,7 +1390,7 @@ public class RelBuilder { return setOp(all, SqlKind.UNION, n); } - /** Creates an {@link org.apache.calcite.rel.core.Intersect} of the two most + /** Creates an {@link Intersect} of the two most * recent relational expressions on the stack. * * @param all Whether to create INTERSECT ALL @@ -1406,7 +1399,7 @@ public class RelBuilder { return intersect(all, 2); } - /** Creates an {@link org.apache.calcite.rel.core.Intersect} of the {@code n} + /** Creates an {@link Intersect} of the {@code n} * most recent relational expressions on the stack. * * @param all Whether to create INTERSECT ALL @@ -1416,7 +1409,7 @@ public class RelBuilder { return setOp(all, SqlKind.INTERSECT, n); } - /** Creates a {@link org.apache.calcite.rel.core.Minus} of the two most recent + /** Creates a {@link Minus} of the two most recent * relational expressions on the stack. * * @param all Whether to create EXCEPT ALL @@ -1425,7 +1418,7 @@ public class RelBuilder { return minus(all, 2); } - /** Creates a {@link org.apache.calcite.rel.core.Minus} of the {@code n} + /** Creates a {@link Minus} of the {@code n} * most recent relational expressions on the stack. * * @param all Whether to create EXCEPT ALL @@ -1434,25 +1427,25 @@ public class RelBuilder { return setOp(all, SqlKind.EXCEPT, n); } - /** Creates a {@link org.apache.calcite.rel.core.Join}. */ + /** Creates a {@link Join}. */ public RelBuilder join(JoinRelType joinType, RexNode condition0, RexNode... conditions) { return join(joinType, Lists.asList(condition0, conditions)); } - /** Creates a {@link org.apache.calcite.rel.core.Join} with multiple + /** Creates a {@link Join} with multiple * conditions. */ public RelBuilder join(JoinRelType joinType, Iterable<? extends RexNode> conditions) { return join(joinType, and(conditions), - ImmutableSet.<CorrelationId>of()); + ImmutableSet.of()); } public RelBuilder join(JoinRelType joinType, RexNode condition) { - return join(joinType, condition, ImmutableSet.<CorrelationId>of()); + return join(joinType, condition, ImmutableSet.of()); } - /** Creates a {@link org.apache.calcite.rel.core.Join} with correlating + /** Creates a {@link Join} with correlating * variables. */ public RelBuilder join(JoinRelType joinType, RexNode condition, Set<CorrelationId> variablesSet) { @@ -1495,7 +1488,7 @@ public class RelBuilder { return this; } - /** Creates a {@link org.apache.calcite.rel.core.Join} using USING syntax. + /** Creates a {@link Join} using USING syntax. * * <p>For each of the field names, both left and right inputs must have a * field of that name. Constructs a join condition that the left and right @@ -1515,7 +1508,7 @@ public class RelBuilder { return join(joinType, conditions); } - /** Creates a {@link org.apache.calcite.rel.core.SemiJoin}. */ + /** Creates a {@link SemiJoin}. */ public RelBuilder semiJoin(Iterable<? extends RexNode> conditions) { final Frame right = stack.pop(); final RelNode semiJoin = @@ -1524,7 +1517,7 @@ public class RelBuilder { return this; } - /** Creates a {@link org.apache.calcite.rel.core.SemiJoin}. */ + /** Creates a {@link SemiJoin}. */ public RelBuilder semiJoin(RexNode... conditions) { return semiJoin(ImmutableList.copyOf(conditions)); } @@ -1533,12 +1526,9 @@ public class RelBuilder { public RelBuilder as(final String alias) { final Frame pair = stack.pop(); List<Field> newFields = - Lists.transform(pair.fields, new Function<Field, Field>() { - public Field apply(Field field) { - return new Field(ImmutableSet.<String>builder().addAll(field.left) - .add(alias).build(), field.right); - } - }); + Lists.transform(pair.fields, field -> + new Field(ImmutableSet.<String>builder().addAll(field.left) + .add(alias).build(), field.right)); stack.push(new Frame(pair.rel, ImmutableList.copyOf(newFields))); return this; } @@ -1707,7 +1697,7 @@ public class RelBuilder { /** Creates a limit without a sort. */ public RelBuilder limit(int offset, int fetch) { - return sortLimit(offset, fetch, ImmutableList.<RexNode>of()); + return sortLimit(offset, fetch, ImmutableList.of()); } /** Creates a {@link Sort} by field ordinals. @@ -1859,7 +1849,7 @@ public class RelBuilder { if (mapping.isIdentity()) { return this; } - final List<RexNode> exprList = Lists.newArrayList(); + final List<RexNode> exprList = new ArrayList<>(); for (int i = 0; i < mapping.getTargetCount(); i++) { exprList.add(field(mapping.getSource(i))); } @@ -1869,15 +1859,10 @@ public class RelBuilder { public RelBuilder aggregate(GroupKey groupKey, List<AggregateCall> aggregateCalls) { return aggregate(groupKey, - Lists.transform( - aggregateCalls, new Function<AggregateCall, AggCall>() { - public AggCall apply(AggregateCall input) { - return new AggCallImpl2(input); - } - })); + Lists.transform(aggregateCalls, AggCallImpl2::new)); } - /** Creates a {@link org.apache.calcite.rel.core.Match}. */ + /** Creates a {@link Match}. */ public RelBuilder match(RexNode pattern, boolean strictStart, boolean strictEnd, Map<String, RexNode> patternDefinitions, Iterable<? extends RexNode> measureList, RexNode after, @@ -1965,7 +1950,7 @@ public class RelBuilder { GroupKey alias(String alias); } - /** Implementation of {@link RelBuilder.GroupKey}. */ + /** Implementation of {@link GroupKey}. */ protected static class GroupKeyImpl implements GroupKey { final ImmutableList<RexNode> nodes; final boolean indicator; @@ -1974,7 +1959,7 @@ public class RelBuilder { GroupKeyImpl(ImmutableList<RexNode> nodes, boolean indicator, ImmutableList<ImmutableList<RexNode>> nodeLists, String alias) { - this.nodes = Preconditions.checkNotNull(nodes); + this.nodes = Objects.requireNonNull(nodes); assert !indicator; this.indicator = indicator; this.nodeLists = nodeLists; @@ -1992,7 +1977,7 @@ public class RelBuilder { } } - /** Implementation of {@link RelBuilder.AggCall}. */ + /** Implementation of {@link AggCall}. */ private static class AggCallImpl implements AggCall { private final SqlAggFunction aggFunction; private final boolean distinct; @@ -2013,13 +1998,13 @@ public class RelBuilder { } } - /** Implementation of {@link RelBuilder.AggCall} that wraps an + /** Implementation of {@link AggCall} that wraps an * {@link AggregateCall}. */ private static class AggCallImpl2 implements AggCall { private final AggregateCall aggregateCall; AggCallImpl2(AggregateCall aggregateCall) { - this.aggregateCall = Preconditions.checkNotNull(aggregateCall); + this.aggregateCall = Objects.requireNonNull(aggregateCall); } } @@ -2075,7 +2060,7 @@ public class RelBuilder { String tableAlias = deriveAlias(rel); ImmutableList.Builder<Field> builder = ImmutableList.builder(); ImmutableSet<String> aliases = tableAlias == null - ? ImmutableSet.<String>of() + ? ImmutableSet.of() : ImmutableSet.of(tableAlias); for (RelDataTypeField field : rel.getRowType().getFieldList()) { builder.add(new Field(aliases, field)); @@ -2109,7 +2094,7 @@ public class RelBuilder { /** Shuttle that shifts a predicate's inputs to the left, replacing early * ones with references to a - * {@link org.apache.calcite.rex.RexCorrelVariable}. */ + * {@link RexCorrelVariable}. */ private class Shifter extends RexShuttle { private final RelNode left; private final CorrelationId id;
http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/BitSets.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/BitSets.java b/core/src/main/java/org/apache/calcite/util/BitSets.java index 492dcfb..50cd9c5 100644 --- a/core/src/main/java/org/apache/calcite/util/BitSets.java +++ b/core/src/main/java/org/apache/calcite/util/BitSets.java @@ -85,25 +85,21 @@ public final class BitSets { * @return Iterable */ public static Iterable<Integer> toIter(final BitSet bitSet) { - return new Iterable<Integer>() { - public Iterator<Integer> iterator() { - return new Iterator<Integer>() { - int i = bitSet.nextSetBit(0); + return () -> new Iterator<Integer>() { + int i = bitSet.nextSetBit(0); - public boolean hasNext() { - return i >= 0; - } + public boolean hasNext() { + return i >= 0; + } - public Integer next() { - int prev = i; - i = bitSet.nextSetBit(i + 1); - return prev; - } + public Integer next() { + int prev = i; + i = bitSet.nextSetBit(i + 1); + return prev; + } - public void remove() { - throw new UnsupportedOperationException(); - } - }; + public void remove() { + throw new UnsupportedOperationException(); } }; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/CancelFlag.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/CancelFlag.java b/core/src/main/java/org/apache/calcite/util/CancelFlag.java index 61e678b..2a14dad 100644 --- a/core/src/main/java/org/apache/calcite/util/CancelFlag.java +++ b/core/src/main/java/org/apache/calcite/util/CancelFlag.java @@ -19,8 +19,7 @@ package org.apache.calcite.util; import org.apache.calcite.plan.Context; import org.apache.calcite.plan.RelOptPlanner; -import com.google.common.base.Preconditions; - +import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -36,7 +35,7 @@ public class CancelFlag { public final AtomicBoolean atomicBoolean; public CancelFlag(AtomicBoolean atomicBoolean) { - this.atomicBoolean = Preconditions.checkNotNull(atomicBoolean); + this.atomicBoolean = Objects.requireNonNull(atomicBoolean); } //~ Methods ---------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/Compatible.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/Compatible.java b/core/src/main/java/org/apache/calcite/util/Compatible.java index 761edb2..6146792 100644 --- a/core/src/main/java/org/apache/calcite/util/Compatible.java +++ b/core/src/main/java/org/apache/calcite/util/Compatible.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Maps; import java.lang.reflect.Array; -import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.sql.Connection; @@ -74,59 +73,56 @@ public interface Compatible { Compatible create() { return (Compatible) Proxy.newProxyInstance( Compatible.class.getClassLoader(), - new Class<?>[] {Compatible.class}, - new InvocationHandler() { - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - if (method.getName().equals("asMap")) { - // Use the Guava implementation Maps.asMap if it is available - try { - //noinspection ConfusingArgumentToVarargsMethod - final Method guavaMethod = Maps.class.getMethod( - method.getName(), method.getParameterTypes()); - return guavaMethod.invoke(null, args); - } catch (NoSuchMethodException e) { - Set set = (Set) args[0]; - Function function = (Function) args[1]; - return CompatibleGuava11.asMap(set, function); - } + new Class<?>[] {Compatible.class}, (proxy, method, args) -> { + if (method.getName().equals("asMap")) { + // Use the Guava implementation Maps.asMap if it is available + try { + //noinspection ConfusingArgumentToVarargsMethod + final Method guavaMethod = Maps.class.getMethod( + method.getName(), method.getParameterTypes()); + return guavaMethod.invoke(null, args); + } catch (NoSuchMethodException e) { + Set set = (Set) args[0]; + Function function = (Function) args[1]; + return CompatibleGuava11.asMap(set, function); } - if (method.getName().equals("navigableSet")) { - ImmutableSortedSet set = (ImmutableSortedSet) args[0]; - return CompatibleGuava11.navigableSet(set); - } - if (method.getName().equals("navigableMap")) { - ImmutableSortedMap map = (ImmutableSortedMap) args[0]; - return CompatibleGuava11.navigableMap(map); - } - if (method.getName().equals("immutableNavigableMap")) { - Map map = (Map) args[0]; - ImmutableSortedMap sortedMap = ImmutableSortedMap.copyOf(map); - return CompatibleGuava11.navigableMap(sortedMap); - } - if (method.getName().equals("setSchema")) { - Connection connection = (Connection) args[0]; - String schema = (String) args[1]; + } + if (method.getName().equals("navigableSet")) { + ImmutableSortedSet set = (ImmutableSortedSet) args[0]; + return CompatibleGuava11.navigableSet(set); + } + if (method.getName().equals("navigableMap")) { + ImmutableSortedMap map = (ImmutableSortedMap) args[0]; + return CompatibleGuava11.navigableMap(map); + } + if (method.getName().equals("immutableNavigableMap")) { + Map map = (Map) args[0]; + ImmutableSortedMap sortedMap = ImmutableSortedMap.copyOf(map); + return CompatibleGuava11.navigableMap(sortedMap); + } + if (method.getName().equals("setSchema")) { + Connection connection = (Connection) args[0]; + String schema = (String) args[1]; + final Method method1 = + connection.getClass().getMethod("setSchema", String.class); + return method1.invoke(connection, schema); + } + if (method.getName().equals("getParameterName")) { + final Method m = (Method) args[0]; + final int i = (Integer) args[1]; + try { final Method method1 = - connection.getClass().getMethod("setSchema", String.class); - return method1.invoke(connection, schema); - } - if (method.getName().equals("getParameterName")) { - final Method m = (Method) args[0]; - final int i = (Integer) args[1]; - try { - final Method method1 = - m.getClass().getMethod("getParameters"); - Object parameters = method1.invoke(m); - final Object parameter = Array.get(parameters, i); - final Method method3 = parameter.getClass().getMethod("getName"); - return method3.invoke(parameter); - } catch (NoSuchMethodException e) { - return "arg" + i; - } + m.getClass().getMethod("getParameters"); + Object parameters = method1.invoke(m); + final Object parameter = Array.get(parameters, i); + final Method method3 = + parameter.getClass().getMethod("getName"); + return method3.invoke(parameter); + } catch (NoSuchMethodException e) { + return "arg" + i; } - return null; } + return null; }); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/CompatibleGuava11.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/CompatibleGuava11.java b/core/src/main/java/org/apache/calcite/util/CompatibleGuava11.java index 21b437a..6b9dc61 100644 --- a/core/src/main/java/org/apache/calcite/util/CompatibleGuava11.java +++ b/core/src/main/java/org/apache/calcite/util/CompatibleGuava11.java @@ -17,7 +17,6 @@ package org.apache.calcite.util; import com.google.common.base.Function; -import com.google.common.base.Objects; import com.google.common.collect.Collections2; import com.google.common.collect.ForwardingSet; import com.google.common.collect.ImmutableSortedMap; @@ -30,16 +29,16 @@ import java.util.AbstractCollection; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.NavigableMap; import java.util.NavigableSet; +import java.util.Objects; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; -import static com.google.common.base.Preconditions.checkNotNull; - /** Helper methods to provide modern Guava functionality based on Guava 11. * * @see Compatible @@ -64,7 +63,7 @@ class CompatibleGuava11 { } @Override public boolean retainAll(Collection<?> c) { - return super.retainAll(checkNotNull(c)); // GWT compatibility + return super.retainAll(Objects.requireNonNull(c)); // GWT compatibility } } @@ -80,7 +79,7 @@ class CompatibleGuava11 { } static boolean removeAllImpl(Set<?> set, Collection<?> collection) { - checkNotNull(collection); // for GWT + Objects.requireNonNull(collection); // for GWT if (collection instanceof Multiset) { collection = ((Multiset<?>) collection).elementSet(); } @@ -239,8 +238,8 @@ class CompatibleGuava11 { } AsMapView(Set<K> set, Function<? super K, V> function) { - this.set = checkNotNull(set); - this.function = checkNotNull(function); + this.set = Objects.requireNonNull(set); + this.function = Objects.requireNonNull(function); } @Override public Set<K> keySet() { @@ -319,7 +318,7 @@ class CompatibleGuava11 { Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o; Object key = entry.getKey(); V value = map().get(key); - return Objects.equal(value, entry.getValue()) + return Objects.equals(value, entry.getValue()) && (value != null || map().containsKey(key)); } return false; @@ -339,7 +338,7 @@ class CompatibleGuava11 { @Override public boolean removeAll(Collection<?> c) { try { - return super.removeAll(checkNotNull(c)); + return super.removeAll(Objects.requireNonNull(c)); } catch (UnsupportedOperationException e) { // if the iterators don't support remove boolean changed = true; @@ -352,7 +351,7 @@ class CompatibleGuava11 { @Override public boolean retainAll(Collection<?> c) { try { - return super.retainAll(checkNotNull(c)); + return super.retainAll(Objects.requireNonNull(c)); } catch (UnsupportedOperationException e) { // if the iterators don't support remove Set<Object> keys = Sets.newHashSetWithExpectedSize(c.size()); @@ -392,7 +391,7 @@ class CompatibleGuava11 { return super.remove(o); } catch (UnsupportedOperationException e) { for (Map.Entry<K, V> entry : map().entrySet()) { - if (com.google.common.base.Objects.equal(o, entry.getValue())) { + if (Objects.equals(o, entry.getValue())) { map().remove(entry.getKey()); return true; } @@ -403,9 +402,9 @@ class CompatibleGuava11 { @Override public boolean removeAll(Collection<?> c) { try { - return super.removeAll(checkNotNull(c)); + return super.removeAll(Objects.requireNonNull(c)); } catch (UnsupportedOperationException e) { - Set<K> toRemove = Sets.newHashSet(); + Set<K> toRemove = new HashSet<>(); for (Map.Entry<K, V> entry : map().entrySet()) { if (c.contains(entry.getValue())) { toRemove.add(entry.getKey()); @@ -417,9 +416,9 @@ class CompatibleGuava11 { @Override public boolean retainAll(Collection<?> c) { try { - return super.retainAll(checkNotNull(c)); + return super.retainAll(Objects.requireNonNull(c)); } catch (UnsupportedOperationException e) { - Set<K> toRetain = Sets.newHashSet(); + Set<K> toRetain = new HashSet<>(); for (Map.Entry<K, V> entry : map().entrySet()) { if (c.contains(entry.getValue())) { toRetain.add(entry.getKey()); @@ -454,7 +453,7 @@ class CompatibleGuava11 { final Iterator<? extends F> backingIterator; TransformedIterator(Iterator<? extends F> backingIterator) { - this.backingIterator = checkNotNull(backingIterator); + this.backingIterator = Objects.requireNonNull(backingIterator); } abstract T transform(F from); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/ImmutableBitSet.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/ImmutableBitSet.java b/core/src/main/java/org/apache/calcite/util/ImmutableBitSet.java index 4f514bb..ef49e80 100644 --- a/core/src/main/java/org/apache/calcite/util/ImmutableBitSet.java +++ b/core/src/main/java/org/apache/calcite/util/ImmutableBitSet.java @@ -19,12 +19,9 @@ package org.apache.calcite.util; import org.apache.calcite.linq4j.Linq4j; import org.apache.calcite.runtime.Utilities; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Ordering; import java.io.Serializable; @@ -50,21 +47,18 @@ public class ImmutableBitSet implements Iterable<Integer>, Serializable, Comparable<ImmutableBitSet> { /** Compares bit sets topologically, so that enclosing bit sets come first, * using natural ordering to break ties. */ - public static final Comparator<ImmutableBitSet> COMPARATOR = - new Comparator<ImmutableBitSet>() { - public int compare(ImmutableBitSet o1, ImmutableBitSet o2) { - if (o1.equals(o2)) { - return 0; - } - if (o1.contains(o2)) { - return -1; - } - if (o2.contains(o1)) { - return 1; - } - return o1.compareTo(o2); - } - }; + public static final Comparator<ImmutableBitSet> COMPARATOR = (o1, o2) -> { + if (o1.equals(o2)) { + return 0; + } + if (o1.contains(o2)) { + return -1; + } + if (o2.contains(o1)) { + return 1; + } + return o1.compareTo(o2); + }; public static final Ordering<ImmutableBitSet> ORDERING = Ordering.from(COMPARATOR); @@ -83,12 +77,11 @@ public class ImmutableBitSet private static final ImmutableBitSet EMPTY = new ImmutableBitSet(EMPTY_LONGS); - public static final Function<? super BitSet, ImmutableBitSet> FROM_BIT_SET = - new Function<BitSet, ImmutableBitSet>() { - public ImmutableBitSet apply(BitSet input) { - return ImmutableBitSet.of(BitSets.toIter(input)); - } - }; + @SuppressWarnings("Guava") + @Deprecated // to be removed before 2.0 + public static final + com.google.common.base.Function<? super BitSet, ImmutableBitSet> + FROM_BIT_SET = ImmutableBitSet::fromBitSet; private final long[] words; @@ -203,6 +196,14 @@ public class ImmutableBitSet } /** + * Returns a new immutable bit set containing all the bits in the given + * {@link BitSet}. + */ + public static ImmutableBitSet fromBitSet(BitSet input) { + return ImmutableBitSet.of(BitSets.toIter(input)); + } + + /** * Creates an ImmutableBitSet with bits from {@code fromIndex} (inclusive) to * specified {@code toIndex} (exclusive) set to {@code true}. * @@ -257,17 +258,13 @@ public class ImmutableBitSet /** Computes the power set (set of all sets) of this bit set. */ public Iterable<ImmutableBitSet> powerSet() { - List<List<ImmutableBitSet>> singletons = Lists.newArrayList(); - for (Integer bit : this) { + List<List<ImmutableBitSet>> singletons = new ArrayList<>(); + for (int bit : this) { singletons.add( ImmutableList.of(ImmutableBitSet.of(), ImmutableBitSet.of(bit))); } return Iterables.transform(Linq4j.product(singletons), - new Function<List<ImmutableBitSet>, ImmutableBitSet>() { - public ImmutableBitSet apply(List<ImmutableBitSet> input) { - return ImmutableBitSet.union(input); - } - }); + ImmutableBitSet::union); } /** @@ -465,7 +462,7 @@ public class ImmutableBitSet * <p>Bit sets {@code (), (0), (0, 1), (0, 1, 3), (1), (2, 3)} are in sorted * order.</p> */ - public int compareTo(ImmutableBitSet o) { + public int compareTo(@Nonnull ImmutableBitSet o) { int i = 0; for (;;) { int n0 = nextSetBit(i); @@ -888,12 +885,7 @@ public class ImmutableBitSet public static Iterable<ImmutableBitSet> permute( Iterable<ImmutableBitSet> bitSets, final Map<Integer, Integer> map) { - return Iterables.transform(bitSets, - new Function<ImmutableBitSet, ImmutableBitSet>() { - public ImmutableBitSet apply(ImmutableBitSet bitSet) { - return bitSet.permute(map); - } - }); + return Iterables.transform(bitSets, bitSet -> bitSet.permute(map)); } /** Returns a bit set with every bit moved up {@code offset} positions. @@ -921,7 +913,7 @@ public class ImmutableBitSet private static class Closure { private SortedMap<Integer, ImmutableBitSet> equivalence; private final SortedMap<Integer, ImmutableBitSet> closure = - Maps.newTreeMap(); + new TreeMap<>(); Closure(SortedMap<Integer, ImmutableBitSet> equivalence) { this.equivalence = equivalence; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/ImmutableNullableList.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/ImmutableNullableList.java b/core/src/main/java/org/apache/calcite/util/ImmutableNullableList.java index 9345214..109153d 100644 --- a/core/src/main/java/org/apache/calcite/util/ImmutableNullableList.java +++ b/core/src/main/java/org/apache/calcite/util/ImmutableNullableList.java @@ -19,7 +19,6 @@ package org.apache.calcite.util; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; import java.util.AbstractList; import java.util.ArrayList; @@ -60,6 +59,9 @@ public class ImmutableNullableList<E> extends AbstractList<E> { //noinspection unchecked return (List<E>) elements; } + if (elements == Collections.EMPTY_LIST) { + return ImmutableList.of(); + } // If there are no nulls, ImmutableList is better. for (E object : elements) { if (object == null) { @@ -204,7 +206,7 @@ public class ImmutableNullableList<E> extends AbstractList<E> { * @param <E> element type */ public static final class Builder<E> { - private final List<E> contents = Lists.newArrayList(); + private final List<E> contents = new ArrayList<>(); /** * Creates a new builder. The returned builder is equivalent to the builder http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/IntegerIntervalSet.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/IntegerIntervalSet.java b/core/src/main/java/org/apache/calcite/util/IntegerIntervalSet.java index 1105461..37ef25d 100644 --- a/core/src/main/java/org/apache/calcite/util/IntegerIntervalSet.java +++ b/core/src/main/java/org/apache/calcite/util/IntegerIntervalSet.java @@ -91,13 +91,10 @@ public class IntegerIntervalSet extends AbstractSet<Integer> { private Enumerator<Integer> enumerator() { final int[] bounds = {Integer.MAX_VALUE, Integer.MIN_VALUE}; visit( - s, - new Handler() { - public void range(int start, int end, boolean exclude) { - if (!exclude) { - bounds[0] = Math.min(bounds[0], start); - bounds[1] = Math.max(bounds[1], end); - } + s, (start, end, exclude) -> { + if (!exclude) { + bounds[0] = Math.min(bounds[0], start); + bounds[1] = Math.max(bounds[1], end); } }); return new Enumerator<Integer>() { @@ -136,12 +133,9 @@ public class IntegerIntervalSet extends AbstractSet<Integer> { public boolean contains(final int n) { final boolean[] bs = {false}; visit( - s, - new Handler() { - public void range(int start, int end, boolean exclude) { - if (start <= n && n <= end) { - bs[0] = !exclude; - } + s, (start, end, exclude) -> { + if (start <= n && n <= end) { + bs[0] = !exclude; } }); return bs[0]; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/NameSet.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/NameSet.java b/core/src/main/java/org/apache/calcite/util/NameSet.java index a51f949..22b7da0 100644 --- a/core/src/main/java/org/apache/calcite/util/NameSet.java +++ b/core/src/main/java/org/apache/calcite/util/NameSet.java @@ -34,16 +34,13 @@ public class NameSet { * collection sorted on this comparator, we can find case-insensitive matches * for a given string using a range scan between the upper-case string and * the lower-case string. */ - public static final Comparator<String> COMPARATOR = - new Comparator<String>() { - public int compare(String o1, String o2) { - int c = o1.compareToIgnoreCase(o2); - if (c == 0) { - c = o1.compareTo(o2); - } - return c; - } - }; + public static final Comparator<String> COMPARATOR = (o1, o2) -> { + int c = o1.compareToIgnoreCase(o2); + if (c == 0) { + c = o1.compareTo(o2); + } + return c; + }; private final NavigableSet<String> names; http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/Pair.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/Pair.java b/core/src/main/java/org/apache/calcite/util/Pair.java index bb2521e..fedaa2d 100644 --- a/core/src/main/java/org/apache/calcite/util/Pair.java +++ b/core/src/main/java/org/apache/calcite/util/Pair.java @@ -229,27 +229,11 @@ public class Pair<T1, T2> public static <K, V> Iterable<Pair<K, V>> zip( final Iterable<? extends K> ks, final Iterable<? extends V> vs) { - return new Iterable<Pair<K, V>>() { - public Iterator<Pair<K, V>> iterator() { - final Iterator<? extends K> kIterator = ks.iterator(); - final Iterator<? extends V> vIterator = vs.iterator(); - - return new Iterator<Pair<K, V>>() { - public boolean hasNext() { - return kIterator.hasNext() && vIterator.hasNext(); - } - - @SuppressWarnings("unchecked") - public Pair<K, V> next() { - return (Pair<K, V>) Pair.of(kIterator.next(), vIterator.next()); - } - - public void remove() { - kIterator.remove(); - vIterator.remove(); - } - }; - } + return () -> { + final Iterator<? extends K> kIterator = ks.iterator(); + final Iterator<? extends V> vIterator = vs.iterator(); + + return new ZipIterator<>(kIterator, vIterator); }; } @@ -288,25 +272,7 @@ public class Pair<T1, T2> */ public static <L, R> Iterable<L> left( final Iterable<? extends Map.Entry<L, R>> iterable) { - return new Iterable<L>() { - public Iterator<L> iterator() { - final Iterator<? extends Map.Entry<L, R>> iterator = - iterable.iterator(); - return new Iterator<L>() { - public boolean hasNext() { - return iterator.hasNext(); - } - - public L next() { - return iterator.next().getKey(); - } - - public void remove() { - iterator.remove(); - } - }; - } - }; + return () -> new LeftIterator<>(iterable.iterator()); } /** @@ -319,25 +285,7 @@ public class Pair<T1, T2> */ public static <L, R> Iterable<R> right( final Iterable<? extends Map.Entry<L, R>> iterable) { - return new Iterable<R>() { - public Iterator<R> iterator() { - final Iterator<? extends Map.Entry<L, R>> iterator = - iterable.iterator(); - return new Iterator<R>() { - public boolean hasNext() { - return iterator.hasNext(); - } - - public R next() { - return iterator.next().getValue(); - } - - public void remove() { - iterator.remove(); - } - }; - } - }; + return () -> new RightIterator<>(iterable.iterator()); } public static <K, V> List<K> left( @@ -376,32 +324,12 @@ public class Pair<T1, T2> * @return Iterable over adjacent element pairs */ public static <T> Iterable<Pair<T, T>> adjacents(final Iterable<T> iterable) { - return new Iterable<Pair<T, T>>() { - public Iterator<Pair<T, T>> iterator() { - final Iterator<T> iterator = iterable.iterator(); - if (!iterator.hasNext()) { - return Collections.emptyIterator(); - } - final T first = iterator.next(); - return new Iterator<Pair<T, T>>() { - T previous = first; - - public boolean hasNext() { - return iterator.hasNext(); - } - - public Pair<T, T> next() { - final T current = iterator.next(); - final Pair<T, T> pair = of(previous, current); - previous = current; - return pair; - } - - public void remove() { - throw new UnsupportedOperationException("remove"); - } - }; + return () -> { + final Iterator<T> iterator = iterable.iterator(); + if (!iterator.hasNext()) { + return Collections.emptyIterator(); } + return new AdjacentIterator<>(iterator); }; } @@ -416,29 +344,148 @@ public class Pair<T1, T2> * @return Iterable over pairs of the first element and all other elements */ public static <T> Iterable<Pair<T, T>> firstAnd(final Iterable<T> iterable) { - return new Iterable<Pair<T, T>>() { - public Iterator<Pair<T, T>> iterator() { - final Iterator<T> iterator = iterable.iterator(); - if (!iterator.hasNext()) { - return Collections.emptyIterator(); - } - final T first = iterator.next(); - return new Iterator<Pair<T, T>>() { - public boolean hasNext() { - return iterator.hasNext(); - } - - public Pair<T, T> next() { - return of(first, iterator.next()); - } - - public void remove() { - throw new UnsupportedOperationException("remove"); - } - }; + return () -> { + final Iterator<T> iterator = iterable.iterator(); + if (!iterator.hasNext()) { + return Collections.emptyIterator(); } + final T first = iterator.next(); + return new FirstAndIterator<>(iterator, first); }; } + + /** Iterator that returns the left field of each pair. + * + * @param <L> Left-hand type + * @param <R> Right-hand type */ + private static class LeftIterator<L, R> implements Iterator<L> { + private final Iterator<? extends Map.Entry<L, R>> iterator; + + LeftIterator(Iterator<? extends Map.Entry<L, R>> iterator) { + this.iterator = Objects.requireNonNull(iterator); + } + + public boolean hasNext() { + return iterator.hasNext(); + } + + public L next() { + return iterator.next().getKey(); + } + + public void remove() { + iterator.remove(); + } + } + + /** Iterator that returns the right field of each pair. + * + * @param <L> Left-hand type + * @param <R> Right-hand type */ + private static class RightIterator<L, R> implements Iterator<R> { + private final Iterator<? extends Map.Entry<L, R>> iterator; + + RightIterator(Iterator<? extends Map.Entry<L, R>> iterator) { + this.iterator = Objects.requireNonNull(iterator); + } + + public boolean hasNext() { + return iterator.hasNext(); + } + + public R next() { + return iterator.next().getValue(); + } + + public void remove() { + iterator.remove(); + } + } + + /** Iterator that returns the first element of a collection paired with every + * other element. + * + * @param <E> Element type */ + private static class FirstAndIterator<E> implements Iterator<Pair<E, E>> { + private final Iterator<E> iterator; + private final E first; + + FirstAndIterator(Iterator<E> iterator, E first) { + this.iterator = Objects.requireNonNull(iterator); + this.first = first; + } + + public boolean hasNext() { + return iterator.hasNext(); + } + + public Pair<E, E> next() { + return of(first, iterator.next()); + } + + public void remove() { + throw new UnsupportedOperationException("remove"); + } + } + + /** Iterator that pairs elements from two iterators. + * + * @param <L> Left-hand type + * @param <R> Right-hand type */ + private static class ZipIterator<L, R> implements Iterator<Pair<L, R>> { + private final Iterator<? extends L> leftIterator; + private final Iterator<? extends R> rightIterator; + + ZipIterator(Iterator<? extends L> leftIterator, + Iterator<? extends R> rightIterator) { + this.leftIterator = Objects.requireNonNull(leftIterator); + this.rightIterator = Objects.requireNonNull(rightIterator); + } + + public boolean hasNext() { + return leftIterator.hasNext() && rightIterator.hasNext(); + } + + public Pair<L, R> next() { + return Pair.of(leftIterator.next(), rightIterator.next()); + } + + public void remove() { + leftIterator.remove(); + rightIterator.remove(); + } + } + + /** Iterator that returns consecutive pairs of elements from an underlying + * iterator. + * + * @param <E> Element type */ + private static class AdjacentIterator<E> implements Iterator<Pair<E, E>> { + private final E first; + private final Iterator<E> iterator; + E previous; + + AdjacentIterator(Iterator<E> iterator) { + this.iterator = Objects.requireNonNull(iterator); + this.first = iterator.next(); + previous = first; + } + + public boolean hasNext() { + return iterator.hasNext(); + } + + public Pair<E, E> next() { + final E current = iterator.next(); + final Pair<E, E> pair = of(previous, current); + previous = current; + return pair; + } + + public void remove() { + throw new UnsupportedOperationException("remove"); + } + } } // End Pair.java http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/PartiallyOrderedSet.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/PartiallyOrderedSet.java b/core/src/main/java/org/apache/calcite/util/PartiallyOrderedSet.java index a3db6db..313b033 100644 --- a/core/src/main/java/org/apache/calcite/util/PartiallyOrderedSet.java +++ b/core/src/main/java/org/apache/calcite/util/PartiallyOrderedSet.java @@ -16,10 +16,7 @@ */ package org.apache.calcite.util; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import java.util.AbstractSet; import java.util.ArrayDeque; @@ -32,7 +29,9 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.function.Function; /** * Partially-ordered set. @@ -71,11 +70,7 @@ public class PartiallyOrderedSet<E> extends AbstractSet<E> { * 6 (0110). */ public static final Ordering<ImmutableBitSet> BIT_SET_INCLUSION_ORDERING = - new Ordering<ImmutableBitSet>() { - public boolean lessThan(ImmutableBitSet e1, ImmutableBitSet e2) { - return e1.contains(e2); - } - }; + ImmutableBitSet::contains; private final Map<E, Node<E>> map; private final Function<E, Iterable<E>> parentFunction; @@ -99,7 +94,7 @@ public class PartiallyOrderedSet<E> extends AbstractSet<E> { * @param ordering Ordering relation */ public PartiallyOrderedSet(Ordering<E> ordering) { - this(ordering, new HashMap<E, Node<E>>(), null, null); + this(ordering, new HashMap<>(), null, null); } /** @@ -111,7 +106,16 @@ public class PartiallyOrderedSet<E> extends AbstractSet<E> { public PartiallyOrderedSet(Ordering<E> ordering, Function<E, Iterable<E>> childFunction, Function<E, Iterable<E>> parentFunction) { - this(ordering, new HashMap<E, Node<E>>(), childFunction, parentFunction); + this(ordering, new HashMap<>(), childFunction, parentFunction); + } + + @SuppressWarnings("Guava") + @Deprecated // to be removed before 2.0 + public PartiallyOrderedSet(Ordering<E> ordering, + com.google.common.base.Function<E, Iterable<E>> childFunction, + com.google.common.base.Function<E, Iterable<E>> parentFunction) { + this(ordering, (Function<E, Iterable<E>>) childFunction::apply, + parentFunction::apply); } /** @@ -122,8 +126,7 @@ public class PartiallyOrderedSet<E> extends AbstractSet<E> { * @param collection Initial contents of partially-ordered set */ public PartiallyOrderedSet(Ordering<E> ordering, Collection<E> collection) { - this(ordering, new HashMap<E, Node<E>>(collection.size() * 3 / 2), null, - null); + this(ordering, new HashMap<>(collection.size() * 3 / 2), null, null); addAll(collection); } @@ -539,8 +542,7 @@ public class PartiallyOrderedSet<E> extends AbstractSet<E> { // breadth-first search, to iterate over every element once, printing // those nearest the top element first final Set<E> seen = new HashSet<>(); - final Deque<E> unseen = new ArrayDeque<>(); - unseen.addAll(getNonChildren()); + final Deque<E> unseen = new ArrayDeque<>(getNonChildren()); while (!unseen.isEmpty()) { E e = unseen.pop(); buf.append(" "); @@ -641,7 +643,7 @@ public class PartiallyOrderedSet<E> extends AbstractSet<E> { if (hypothetical) { if (parentFunction != null) { final List<E> list = new ArrayList<>(); - closure(parentFunction, e, list, new HashSet<E>()); + closure(parentFunction, e, list, new HashSet<>()); return list; } else { return ImmutableList.copyOf(strip(findParents(e))); @@ -656,7 +658,7 @@ public class PartiallyOrderedSet<E> extends AbstractSet<E> { private void closure(Function<E, Iterable<E>> generator, E e, List<E> list, Set<E> set) { - for (E p : Preconditions.checkNotNull(generator.apply(e))) { + for (E p : Objects.requireNonNull(generator.apply(e))) { if (set.add(e)) { if (map.containsKey(p)) { list.add(p); @@ -711,12 +713,7 @@ public class PartiallyOrderedSet<E> extends AbstractSet<E> { // Similarly child list and bottom element. return ImmutableList.of(); } - return Lists.transform(list, - new Function<Node<E>, E>() { - public E apply(Node<E> node) { - return node.e; - } - }); + return Util.transform(list, node -> node.e); } /** Converts an iterable of nodes into the list of the elements inside. http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/PrecedenceClimbingParser.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/PrecedenceClimbingParser.java b/core/src/main/java/org/apache/calcite/util/PrecedenceClimbingParser.java index 68b8be5..e25e459 100644 --- a/core/src/main/java/org/apache/calcite/util/PrecedenceClimbingParser.java +++ b/core/src/main/java/org/apache/calcite/util/PrecedenceClimbingParser.java @@ -18,13 +18,13 @@ package org.apache.calcite.util; import org.apache.calcite.linq4j.Ord; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import java.util.AbstractList; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.function.Predicate; /** * Parser that takes a collection of tokens (atoms and operators) @@ -107,7 +107,7 @@ public class PrecedenceClimbingParser { break; case SPECIAL: Result r = ((SpecialOp) op).special.apply(this, (SpecialOp) op); - Preconditions.checkNotNull(r); + Objects.requireNonNull(r); replace(r.replacement, r.first.previous, r.last.next); break; default: @@ -188,7 +188,7 @@ public class PrecedenceClimbingParser { public PrecedenceClimbingParser copy(int start, Predicate<Token> predicate) { final List<Token> tokens = new ArrayList<>(); for (Token token : Util.skip(all(), start)) { - if (predicate.apply(token)) { + if (predicate.test(token)) { break; } tokens.add(token.copy()); @@ -352,7 +352,7 @@ public class PrecedenceClimbingParser { public static class Builder { final List<Token> tokens = new ArrayList<>(); private final PrecedenceClimbingParser dummy = - new PrecedenceClimbingParser(ImmutableList.<Token>of()); + new PrecedenceClimbingParser(ImmutableList.of()); private Builder add(Token t) { tokens.add(t); http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/ReflectUtil.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/ReflectUtil.java b/core/src/main/java/org/apache/calcite/util/ReflectUtil.java index 8dc2f2e..17f80d6 100644 --- a/core/src/main/java/org/apache/calcite/util/ReflectUtil.java +++ b/core/src/main/java/org/apache/calcite/util/ReflectUtil.java @@ -286,7 +286,7 @@ public abstract class ReflectUtil { visitorClass, visiteeClass, visitMethodName, - Collections.<Class>emptyList()); + Collections.emptyList()); } /** @@ -426,7 +426,7 @@ public abstract class ReflectUtil { visitorClass, visiteeClass, visitMethodName, - Collections.<Class>emptyList()); + Collections.emptyList()); } public Method lookupVisitMethod( http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/Sources.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/Sources.java b/core/src/main/java/org/apache/calcite/util/Sources.java index 6f04b90..ae6e9da 100644 --- a/core/src/main/java/org/apache/calcite/util/Sources.java +++ b/core/src/main/java/org/apache/calcite/util/Sources.java @@ -16,8 +16,6 @@ */ package org.apache.calcite.util; -import com.google.common.base.Preconditions; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -27,6 +25,7 @@ import java.io.Reader; import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.util.Objects; import java.util.zip.GZIPInputStream; /** @@ -76,7 +75,7 @@ public abstract class Sources { private final URL url; private FileSource(URL url) { - this.url = Preconditions.checkNotNull(url); + this.url = Objects.requireNonNull(url); if (url.getProtocol().equals("file")) { this.file = new File(url.getFile()); } else { @@ -85,7 +84,7 @@ public abstract class Sources { } private FileSource(File file) { - this.file = Preconditions.checkNotNull(file); + this.file = Objects.requireNonNull(file); this.url = null; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/TryThreadLocal.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/TryThreadLocal.java b/core/src/main/java/org/apache/calcite/util/TryThreadLocal.java index b278174..2fd4f2a 100644 --- a/core/src/main/java/org/apache/calcite/util/TryThreadLocal.java +++ b/core/src/main/java/org/apache/calcite/util/TryThreadLocal.java @@ -50,13 +50,11 @@ public class TryThreadLocal<T> extends ThreadLocal<T> { public Memo push(T value) { final T previous = get(); set(value); - return new Memo() { - public void close() { - if (previous == initialValue) { - remove(); - } else { - set(previous); - } + return () -> { + if (previous == initialValue) { + remove(); + } else { + set(previous); } }; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/UnmodifiableArrayList.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/UnmodifiableArrayList.java b/core/src/main/java/org/apache/calcite/util/UnmodifiableArrayList.java index 3a27b02..d7a58fd 100644 --- a/core/src/main/java/org/apache/calcite/util/UnmodifiableArrayList.java +++ b/core/src/main/java/org/apache/calcite/util/UnmodifiableArrayList.java @@ -16,9 +16,8 @@ */ package org.apache.calcite.util; -import com.google.common.base.Preconditions; - import java.util.AbstractList; +import java.util.Objects; import java.util.RandomAccess; /** @@ -40,7 +39,7 @@ public class UnmodifiableArrayList<E> private final E[] elements; private UnmodifiableArrayList(E[] elements) { - this.elements = Preconditions.checkNotNull(elements); + this.elements = Objects.requireNonNull(elements); } public static <E> UnmodifiableArrayList<E> of(E... elements) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/Util.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/Util.java b/core/src/main/java/org/apache/calcite/util/Util.java index 307879c..b90bbbd 100644 --- a/core/src/main/java/org/apache/calcite/util/Util.java +++ b/core/src/main/java/org/apache/calcite/util/Util.java @@ -29,7 +29,6 @@ import org.apache.calcite.sql.SqlValuesOperator; import org.apache.calcite.sql.fun.SqlRowOperator; import org.apache.calcite.sql.util.SqlBasicVisitor; -import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import com.google.common.cache.CacheBuilder; @@ -91,16 +90,16 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Properties; +import java.util.RandomAccess; import java.util.Set; import java.util.StringTokenizer; import java.util.TimeZone; +import java.util.function.Function; import java.util.jar.JarFile; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collector; -import javax.annotation.Nullable; - -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nonnull; /** * Miscellaneous utility functions. @@ -147,16 +146,11 @@ public class Util { * Maps classes to the map of their enum values. Uses a weak map so that * classes are not prevented from being unloaded. */ + @SuppressWarnings("unchecked") private static final LoadingCache<Class, Map<String, Enum>> ENUM_CONSTANTS = CacheBuilder.newBuilder() .weakKeys() - .build( - new CacheLoader<Class, Map<String, Enum>>() { - @Override public Map<String, Enum> load(Class clazz) { - //noinspection unchecked - return enumConstants(clazz); - } - }); + .build(CacheLoader.from(Util::enumConstants)); //~ Methods ---------------------------------------------------------------- /** @@ -819,7 +813,7 @@ public class Util { * but we don't require Guava version 20 yet. */ public static void throwIfUnchecked(Throwable throwable) { Bug.upgrade("Remove when minimum Guava version is 20"); - checkNotNull(throwable); + Objects.requireNonNull(throwable); if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } @@ -868,7 +862,7 @@ public class Util { } /** @deprecated Use {@link Preconditions#checkArgument} - * or {@link Preconditions#checkNotNull(Object)} */ + * or {@link Objects#requireNonNull(Object)} */ @Deprecated // to be removed before 2.0 public static void pre(boolean b, String description) { if (!b) { @@ -877,7 +871,7 @@ public class Util { } /** @deprecated Use {@link Preconditions#checkArgument} - * or {@link Preconditions#checkNotNull(Object)} */ + * or {@link Objects#requireNonNull(Object)} */ @Deprecated // to be removed before 2.0 public static void post(boolean b, String description) { if (!b) { @@ -1603,11 +1597,7 @@ public class Util { public static <E> Iterable<E> cast( final Iterable<? super E> iterable, final Class<E> clazz) { - return new Iterable<E>() { - public Iterator<E> iterator() { - return cast(iterable.iterator(), clazz); - } - }; + return () -> cast(iterable.iterator(), clazz); } /** @@ -1631,11 +1621,7 @@ public class Util { public static <E> Iterable<E> filter( final Iterable<?> iterable, final Class<E> includeFilter) { - return new Iterable<E>() { - public Iterator<E> iterator() { - return new Filterator<>(iterable.iterator(), includeFilter); - } - }; + return () -> new Filterator<>(iterable.iterator(), includeFilter); } public static <E> Collection<E> filter( @@ -1898,7 +1884,7 @@ public class Util { } public static <T> Iterable<T> orEmpty(Iterable<T> v0) { - return v0 != null ? v0 : ImmutableList.<T>of(); + return v0 != null ? v0 : ImmutableList.of(); } /** Returns the last element of a list. @@ -2199,16 +2185,11 @@ public class Util { * @param <V> Value type * @return Map that is a view onto the values */ - public static <K, V> Map<K, V> asIndexMap( + public static <K, V> Map<K, V> asIndexMapJ( final Collection<V> values, final Function<V, K> function) { final Collection<Map.Entry<K, V>> entries = - Collections2.transform(values, - new Function<V, Map.Entry<K, V>>() { - public Map.Entry<K, V> apply(@Nullable V input) { - return Pair.of(function.apply(input), input); - } - }); + Collections2.transform(values, v -> Pair.of(function.apply(v), v)); final Set<Map.Entry<K, V>> entrySet = new AbstractSet<Map.Entry<K, V>>() { public Iterator<Map.Entry<K, V>> iterator() { @@ -2226,6 +2207,14 @@ public class Util { }; } + @SuppressWarnings("Guava") + @Deprecated + public static <K, V> Map<K, V> asIndexMap( + final Collection<V> values, + final com.google.common.base.Function<V, K> function) { + return asIndexMapJ(values, function::apply); + } + /** * Prints the given code with line numbering. */ @@ -2287,7 +2276,8 @@ public class Util { if (n == 0) { // Lists are already immutable. Furthermore, if the outer list is // immutable we will just return "lists" unchanged. - return ImmutableList.copyOf((Iterable) lists); + //noinspection unchecked + return ImmutableList.copyOf((Iterable<List<E>>) lists); } final ImmutableList.Builder<List<E>> builder = ImmutableList.builder(); @@ -2351,6 +2341,9 @@ public class Util { * Returns a {@code Collector} that accumulates the input elements into a * Guava {@link ImmutableList} via a {@link ImmutableList.Builder}. * + * <p>It will be obsolete when we move to {@link Bug#upgrade Guava 21.0}, + * which has {@code ImmutableList.toImmutableList()}. + * * @param <T> Type of the input elements * * @return a {@code Collector} that collects all the input elements into an @@ -2366,6 +2359,16 @@ public class Util { ImmutableList.Builder::build); } + /** Transforms a list, applying a function to each element. */ + public static <F, T> List<T> transform(List<F> list, + java.util.function.Function<F, T> function) { + if (list instanceof RandomAccess) { + return new RandomAccessTransformingList<>(list, function); + } else { + return new TransformingList<>(list, function); + } + } + //~ Inner Classes ---------------------------------------------------------- /** @@ -2401,6 +2404,49 @@ public class Util { return super.visit(call); } } + + /** List that returns the same number of elements as a backing list, + * applying a transformation function to each one. + * + * @param <F> Element type of backing list + * @param <T> Element type of this list + */ + private static class TransformingList<F, T> extends AbstractList<T> { + private final java.util.function.Function<F, T> function; + private final List<F> list; + + TransformingList(List<F> list, + java.util.function.Function<F, T> function) { + this.function = function; + this.list = list; + } + + public T get(int i) { + return function.apply(list.get(i)); + } + + public int size() { + return list.size(); + } + + @Override @Nonnull public Iterator<T> iterator() { + return listIterator(); + } + } + + /** Extension to {@link TransformingList} that implements + * {@link RandomAccess}. + * + * @param <F> Element type of backing list + * @param <T> Element type of this list + */ + private static class RandomAccessTransformingList<F, T> + extends TransformingList<F, T> implements RandomAccess { + RandomAccessTransformingList(List<F> list, + java.util.function.Function<F, T> function) { + super(list, function); + } + } } // End Util.java http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/XmlOutput.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/XmlOutput.java b/core/src/main/java/org/apache/calcite/util/XmlOutput.java index e58cae0..1a32205 100644 --- a/core/src/main/java/org/apache/calcite/util/XmlOutput.java +++ b/core/src/main/java/org/apache/calcite/util/XmlOutput.java @@ -558,7 +558,7 @@ public class XmlOutput { if (i >= translationVector.size()) { // Extend list by adding the requisite number of nulls. final int count = i + 1 - translationVector.size(); - translationVector.addAll(Collections.<String>nCopies(count, null)); + translationVector.addAll(Collections.nCopies(count, null)); } translationVector.set(i, to); } @@ -569,7 +569,7 @@ public class XmlOutput { */ public void makeImmutable() { translationTable = - translationVector.toArray(new String[translationVector.size()]); + translationVector.toArray(new String[0]); translationVector = null; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/graph/BreadthFirstIterator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/graph/BreadthFirstIterator.java b/core/src/main/java/org/apache/calcite/util/graph/BreadthFirstIterator.java index 21aed24..3a7260f 100644 --- a/core/src/main/java/org/apache/calcite/util/graph/BreadthFirstIterator.java +++ b/core/src/main/java/org/apache/calcite/util/graph/BreadthFirstIterator.java @@ -41,11 +41,7 @@ public class BreadthFirstIterator<V, E extends DefaultEdge> public static <V, E extends DefaultEdge> Iterable<V> of( final DirectedGraph<V, E> graph, final V root) { - return new Iterable<V>() { - public Iterator<V> iterator() { - return new BreadthFirstIterator<V, E>(graph, root); - } - }; + return () -> new BreadthFirstIterator<V, E>(graph, root); } /** Populates a set with the nodes reachable from a given node. */ http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java b/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java index f093393..77eef3e 100644 --- a/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java +++ b/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java @@ -45,7 +45,7 @@ public class DefaultDirectedGraph<V, E extends DefaultEdge> } public static <V> DefaultDirectedGraph<V, DefaultEdge> create() { - return create(DefaultEdge.<V>factory()); + return create(DefaultEdge.factory()); } public static <V, E extends DefaultEdge> DefaultDirectedGraph<V, E> create( http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/graph/DefaultEdge.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/graph/DefaultEdge.java b/core/src/main/java/org/apache/calcite/util/graph/DefaultEdge.java index 3f32bdf..d288d02 100644 --- a/core/src/main/java/org/apache/calcite/util/graph/DefaultEdge.java +++ b/core/src/main/java/org/apache/calcite/util/graph/DefaultEdge.java @@ -40,11 +40,7 @@ public class DefaultEdge { } public static <V> DirectedGraph.EdgeFactory<V, DefaultEdge> factory() { - return new DirectedGraph.EdgeFactory<V, DefaultEdge>() { - public DefaultEdge createEdge(V v0, V v1) { - return new DefaultEdge(v0, v1); - } - }; + return DefaultEdge::new; } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/graph/DepthFirstIterator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/graph/DepthFirstIterator.java b/core/src/main/java/org/apache/calcite/util/graph/DepthFirstIterator.java index 1631d38..50d6b95 100644 --- a/core/src/main/java/org/apache/calcite/util/graph/DepthFirstIterator.java +++ b/core/src/main/java/org/apache/calcite/util/graph/DepthFirstIterator.java @@ -16,9 +16,7 @@ */ package org.apache.calcite.util.graph; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -42,8 +40,8 @@ public class DepthFirstIterator<V, E extends DefaultEdge> private static <V, E extends DefaultEdge> List<V> buildList( DirectedGraph<V, E> graph, V start) { - final List<V> list = Lists.newArrayList(); - buildListRecurse(list, Sets.<V>newHashSet(), graph, start); + final List<V> list = new ArrayList<>(); + buildListRecurse(list, new HashSet<>(), graph, start); return list; } http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/graph/TopologicalOrderIterator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/graph/TopologicalOrderIterator.java b/core/src/main/java/org/apache/calcite/util/graph/TopologicalOrderIterator.java index db7154f..69a6fdf 100644 --- a/core/src/main/java/org/apache/calcite/util/graph/TopologicalOrderIterator.java +++ b/core/src/main/java/org/apache/calcite/util/graph/TopologicalOrderIterator.java @@ -42,11 +42,7 @@ public class TopologicalOrderIterator<V, E extends DefaultEdge> public static <V, E extends DefaultEdge> Iterable<V> of( final DirectedGraph<V, E> graph) { - return new Iterable<V>() { - public Iterator<V> iterator() { - return new TopologicalOrderIterator<V, E>(graph); - } - }; + return () -> new TopologicalOrderIterator<V, E>(graph); } private void populate(Map<V, int[]> countMap, List<V> empties) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/javac/JavaCompilerArgs.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/javac/JavaCompilerArgs.java b/core/src/main/java/org/apache/calcite/util/javac/JavaCompilerArgs.java index e687a25..e3b03d3 100644 --- a/core/src/main/java/org/apache/calcite/util/javac/JavaCompilerArgs.java +++ b/core/src/main/java/org/apache/calcite/util/javac/JavaCompilerArgs.java @@ -61,7 +61,7 @@ public class JavaCompilerArgs { while (tok.hasMoreTokens()) { list.add(tok.nextToken()); } - setStringArray(list.toArray(new String[list.size()])); + setStringArray(list.toArray(new String[0])); } /** @@ -90,7 +90,7 @@ public class JavaCompilerArgs { public String[] getStringArray() { argsList.addAll(fileNameList); - return argsList.toArray(new String[argsList.size()]); + return argsList.toArray(new String[0]); } public void addFile(String fileName) { @@ -98,7 +98,7 @@ public class JavaCompilerArgs { } public String[] getFileNames() { - return fileNameList.toArray(new String[fileNameList.size()]); + return fileNameList.toArray(new String[0]); } public void setVerbose(boolean verbose) { http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java b/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java index 79a7216..8381d1c 100644 --- a/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java +++ b/core/src/main/java/org/apache/calcite/util/mapping/Mappings.java @@ -21,7 +21,6 @@ import org.apache.calcite.util.ImmutableBitSet; import org.apache.calcite.util.Permutation; import org.apache.calcite.util.Util; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.primitives.Ints; @@ -33,6 +32,7 @@ import java.util.BitSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.function.IntFunction; /** * Utility functions related to mappings. @@ -219,12 +219,7 @@ public abstract class Mappings { public static ImmutableList<ImmutableBitSet> apply2(final Mapping mapping, Iterable<ImmutableBitSet> bitSets) { return ImmutableList.copyOf( - Iterables.transform(bitSets, - new Function<ImmutableBitSet, ImmutableBitSet>() { - public ImmutableBitSet apply(ImmutableBitSet input1) { - return Mappings.apply(mapping, input1); - } - })); + Iterables.transform(bitSets, input1 -> apply(mapping, input1))); } /** @@ -346,7 +341,7 @@ public abstract class Mappings { } public static TargetMapping target( - Function<Integer, Integer> function, + IntFunction<Integer> function, int sourceCount, int targetCount) { final PartialFunctionImpl mapping = @@ -606,13 +601,11 @@ public abstract class Mappings { throw new IllegalArgumentException("new source count too low"); } return target( - new Function<Integer, Integer>() { - public Integer apply(Integer source) { - int source2 = source - offset; - return source2 < 0 || source2 >= mapping.getSourceCount() - ? null - : mapping.getTargetOpt(source2); - } + (IntFunction<Integer>) source -> { + int source2 = source - offset; + return source2 < 0 || source2 >= mapping.getSourceCount() + ? null + : mapping.getTargetOpt(source2); }, sourceCount, mapping.getTargetCount()); @@ -652,12 +645,11 @@ public abstract class Mappings { throw new IllegalArgumentException("new target count too low"); } return target( - new Function<Integer, Integer>() { - public Integer apply(Integer source) { - int target = mapping.getTargetOpt(source); - return target < 0 ? null : target + offset; - } - }, mapping.getSourceCount(), targetCount); + (IntFunction<Integer>) source -> { + int target = mapping.getTargetOpt(source); + return target < 0 ? null : target + offset; + }, + mapping.getSourceCount(), targetCount); } /** @@ -681,18 +673,16 @@ public abstract class Mappings { throw new IllegalArgumentException("new source count too low"); } return target( - new Function<Integer, Integer>() { - public Integer apply(Integer source) { - final int source2 = source - offset; - if (source2 < 0 || source2 >= mapping.getSourceCount()) { - return null; - } - int target = mapping.getTargetOpt(source2); - if (target < 0) { - return null; - } - return target + offset; + (IntFunction<Integer>) source -> { + final int source2 = source - offset; + if (source2 < 0 || source2 >= mapping.getSourceCount()) { + return null; + } + int target = mapping.getTargetOpt(source2); + if (target < 0) { + return null; } + return target + offset; }, sourceCount, mapping.getTargetCount() + offset); @@ -716,11 +706,7 @@ public abstract class Mappings { /** Inverts an {@link java.lang.Iterable} over * {@link org.apache.calcite.util.mapping.IntPair}s. */ public static Iterable<IntPair> invert(final Iterable<IntPair> pairs) { - return new Iterable<IntPair>() { - public Iterator<IntPair> iterator() { - return invert(pairs.iterator()); - } - }; + return () -> invert(pairs.iterator()); } /** Inverts an {@link java.util.Iterator} over http://git-wip-us.apache.org/repos/asf/calcite/blob/d59b639d/core/src/main/java/org/apache/calcite/util/trace/CalciteTrace.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/util/trace/CalciteTrace.java b/core/src/main/java/org/apache/calcite/util/trace/CalciteTrace.java index 2e01742..70d77af 100644 --- a/core/src/main/java/org/apache/calcite/util/trace/CalciteTrace.java +++ b/core/src/main/java/org/apache/calcite/util/trace/CalciteTrace.java @@ -56,11 +56,7 @@ public abstract class CalciteTrace { public static final Logger PARSER_LOGGER = getParserTracer(); private static final ThreadLocal<Function2<Void, File, String>> DYNAMIC_HANDLER = - new ThreadLocal<Function2<Void, File, String>>() { - @Override protected Function2<Void, File, String> initialValue() { - return Functions.ignore2(); - } - }; + ThreadLocal.withInitial(Functions::ignore2); //~ Methods ----------------------------------------------------------------
