Apply "type inference for generic instance creation" Java 7 feature
Change-Id: Ia14802c903ca67b9d94dc6038d70b0e9644bc621
This commit is contained in:
@@ -33,7 +33,7 @@ public class AndPredicate<T> extends Predicate<T> {
|
||||
}
|
||||
|
||||
protected AndPredicate(final Collection<? extends Predicate<T>> that) {
|
||||
final ArrayList<Predicate<T>> t = new ArrayList<Predicate<T>>(that.size());
|
||||
List<Predicate<T>> t = new ArrayList<>(that.size());
|
||||
int c = 0;
|
||||
for (Predicate<T> p : that) {
|
||||
if (getClass() == p.getClass()) {
|
||||
@@ -67,7 +67,7 @@ public class AndPredicate<T> extends Predicate<T> {
|
||||
|
||||
@Override
|
||||
public Predicate<T> copy(final Collection<? extends Predicate<T>> children) {
|
||||
return new AndPredicate<T>(children);
|
||||
return new AndPredicate<>(children);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,7 +54,7 @@ public class NotPredicate<T> extends Predicate<T> {
|
||||
if (children.size() != 1) {
|
||||
throw new IllegalArgumentException("Expected exactly one child");
|
||||
}
|
||||
return new NotPredicate<T>(children.iterator().next());
|
||||
return new NotPredicate<>(children.iterator().next());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ public class OrPredicate<T> extends Predicate<T> {
|
||||
}
|
||||
|
||||
protected OrPredicate(final Collection<? extends Predicate<T>> that) {
|
||||
final ArrayList<Predicate<T>> t = new ArrayList<Predicate<T>>(that.size());
|
||||
List<Predicate<T>> t = new ArrayList<>(that.size());
|
||||
int c = 0;
|
||||
for (Predicate<T> p : that) {
|
||||
if (getClass() == p.getClass()) {
|
||||
@@ -67,7 +67,7 @@ public class OrPredicate<T> extends Predicate<T> {
|
||||
|
||||
@Override
|
||||
public Predicate<T> copy(final Collection<? extends Predicate<T>> children) {
|
||||
return new OrPredicate<T>(children);
|
||||
return new OrPredicate<>(children);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class Predicate<T> {
|
||||
if (that.length == 1) {
|
||||
return that[0];
|
||||
}
|
||||
return new AndPredicate<T>(that);
|
||||
return new AndPredicate<>(that);
|
||||
}
|
||||
|
||||
/** Combine the passed predicates into a single AND node. */
|
||||
@@ -64,7 +64,7 @@ public abstract class Predicate<T> {
|
||||
if (that.size() == 1) {
|
||||
return Iterables.getOnlyElement(that);
|
||||
}
|
||||
return new AndPredicate<T>(that);
|
||||
return new AndPredicate<>(that);
|
||||
}
|
||||
|
||||
/** Combine the passed predicates into a single OR node. */
|
||||
@@ -73,7 +73,7 @@ public abstract class Predicate<T> {
|
||||
if (that.length == 1) {
|
||||
return that[0];
|
||||
}
|
||||
return new OrPredicate<T>(that);
|
||||
return new OrPredicate<>(that);
|
||||
}
|
||||
|
||||
/** Combine the passed predicates into a single OR node. */
|
||||
@@ -82,7 +82,7 @@ public abstract class Predicate<T> {
|
||||
if (that.size() == 1) {
|
||||
return Iterables.getOnlyElement(that);
|
||||
}
|
||||
return new OrPredicate<T>(that);
|
||||
return new OrPredicate<>(that);
|
||||
}
|
||||
|
||||
/** Invert the passed node. */
|
||||
@@ -130,7 +130,7 @@ public abstract class Predicate<T> {
|
||||
public abstract boolean equals(Object other);
|
||||
|
||||
private static class Any<T> extends Predicate<T> {
|
||||
private static final Any<Object> INSTANCE = new Any<Object>();
|
||||
private static final Any<Object> INSTANCE = new Any<>();
|
||||
|
||||
private Any() {
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public abstract class QueryBuilder<T> {
|
||||
*/
|
||||
public static class Definition<T, Q extends QueryBuilder<T>> {
|
||||
private final Map<String, OperatorFactory<T, Q>> opFactories =
|
||||
new HashMap<String, OperatorFactory<T, Q>>();
|
||||
new HashMap<>();
|
||||
|
||||
public Definition(Class<Q> clazz) {
|
||||
// Guess at the supported operators by scanning methods.
|
||||
@@ -204,11 +204,11 @@ public abstract class QueryBuilder<T> {
|
||||
final Tree val = onlyChildOf(opTree);
|
||||
if (val.getType() == SINGLE_WORD && "*".equals(val.getText())) {
|
||||
final String op = opTree.getText();
|
||||
final WildPatternPredicate<T> pat = new WildPatternPredicate<T>(op);
|
||||
return new VariablePredicate<T>(var, pat);
|
||||
final WildPatternPredicate<T> pat = new WildPatternPredicate<>(op);
|
||||
return new VariablePredicate<>(var, pat);
|
||||
}
|
||||
}
|
||||
return new VariablePredicate<T>(var, toPredicate(opTree));
|
||||
return new VariablePredicate<>(var, toPredicate(opTree));
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -224,7 +224,7 @@ public abstract class QueryBuilder<T> {
|
||||
//
|
||||
case AND:
|
||||
case OR: {
|
||||
List<Predicate<T>> p = new ArrayList<Predicate<T>>(val.getChildCount());
|
||||
List<Predicate<T>> p = new ArrayList<>(val.getChildCount());
|
||||
for (int i = 0; i < val.getChildCount(); i++) {
|
||||
final Tree c = val.getChild(i);
|
||||
if (c.getType() != DEFAULT_FIELD) {
|
||||
|
||||
@@ -76,7 +76,7 @@ public abstract class QueryRewriter<T> {
|
||||
if ((m.getModifiers() & Modifier.ABSTRACT) != Modifier.ABSTRACT
|
||||
&& (m.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC
|
||||
&& rp != null) {
|
||||
rewriteRules.add(new MethodRewrite<T>(qb, rp.value(), m));
|
||||
rewriteRules.add(new MethodRewrite<>(qb, rp.value(), m));
|
||||
}
|
||||
}
|
||||
c = c.getSuperclass();
|
||||
@@ -138,7 +138,7 @@ public abstract class QueryRewriter<T> {
|
||||
in = rewriteOne(in);
|
||||
|
||||
if (old.equals(in) && in.getChildCount() > 0) {
|
||||
List<Predicate<T>> n = new ArrayList<Predicate<T>>(in.getChildCount());
|
||||
List<Predicate<T>> n = new ArrayList<>(in.getChildCount());
|
||||
for (Predicate<T> p : in.getChildren()) {
|
||||
n.add(rewriteImpl(p));
|
||||
}
|
||||
@@ -159,14 +159,14 @@ public abstract class QueryRewriter<T> {
|
||||
return not(replaceGenericNodes(in.getChild(0)));
|
||||
|
||||
} else if (in instanceof AndPredicate) {
|
||||
List<Predicate<T>> n = new ArrayList<Predicate<T>>(in.getChildCount());
|
||||
List<Predicate<T>> n = new ArrayList<>(in.getChildCount());
|
||||
for (Predicate<T> c : in.getChildren()) {
|
||||
n.add(replaceGenericNodes(c));
|
||||
}
|
||||
return and(n);
|
||||
|
||||
} else if (in instanceof OrPredicate) {
|
||||
List<Predicate<T>> n = new ArrayList<Predicate<T>>(in.getChildCount());
|
||||
List<Predicate<T>> n = new ArrayList<>(in.getChildCount());
|
||||
for (Predicate<T> c : in.getChildren()) {
|
||||
n.add(replaceGenericNodes(c));
|
||||
}
|
||||
@@ -198,8 +198,8 @@ public abstract class QueryRewriter<T> {
|
||||
}
|
||||
|
||||
private static class MatchResult<T> {
|
||||
private static final MatchResult<?> FAIL = new MatchResult<Object>(null);
|
||||
private static final MatchResult<?> OK = new MatchResult<Object>(null);
|
||||
private static final MatchResult<?> FAIL = new MatchResult<>(null);
|
||||
private static final MatchResult<?> OK = new MatchResult<>(null);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> MatchResult<T> fail() {
|
||||
@@ -251,7 +251,7 @@ public abstract class QueryRewriter<T> {
|
||||
// but in any order.
|
||||
//
|
||||
final LinkedList<Predicate<T>> have = dup(actual);
|
||||
final LinkedList<Predicate<T>> extra = new LinkedList<Predicate<T>>();
|
||||
final LinkedList<Predicate<T>> extra = new LinkedList<>();
|
||||
for (final Predicate<T> pat : pattern.getChildren()) {
|
||||
boolean found = false;
|
||||
for (final Iterator<Predicate<T>> i = have.iterator(); i.hasNext();) {
|
||||
@@ -275,11 +275,11 @@ public abstract class QueryRewriter<T> {
|
||||
return MatchResult.ok();
|
||||
case 1:
|
||||
if (isNOT(actual)) {
|
||||
return new MatchResult<T>(actual.copy(have));
|
||||
return new MatchResult<>(actual.copy(have));
|
||||
}
|
||||
return new MatchResult<T>(have.get(0));
|
||||
return new MatchResult<>(have.get(0));
|
||||
default:
|
||||
return new MatchResult<T>(actual.copy(have));
|
||||
return new MatchResult<>(actual.copy(have));
|
||||
}
|
||||
|
||||
} else if (pattern.equals(actual)) {
|
||||
@@ -297,7 +297,7 @@ public abstract class QueryRewriter<T> {
|
||||
}
|
||||
|
||||
private static <T> LinkedList<Predicate<T>> dup(final Predicate<T> actual) {
|
||||
return new LinkedList<Predicate<T>>(actual.getChildren());
|
||||
return new LinkedList<>(actual.getChildren());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -412,8 +412,7 @@ public abstract class QueryRewriter<T> {
|
||||
@Override
|
||||
public Predicate<T> rewrite(QueryRewriter<T> rewriter,
|
||||
final Predicate<T> input) {
|
||||
final HashMap<String, Predicate<T>> args =
|
||||
new HashMap<String, Predicate<T>>();
|
||||
final HashMap<String, Predicate<T>> args = new HashMap<>();
|
||||
final MatchResult<T> res = rewriter.match(args, pattern, input);
|
||||
if (!res.success()) {
|
||||
return null;
|
||||
@@ -483,7 +482,7 @@ public abstract class QueryRewriter<T> {
|
||||
}
|
||||
|
||||
private static <T> List<Predicate<T>> removeDuplicates(List<Predicate<T>> n) {
|
||||
List<Predicate<T>> r = new ArrayList<Predicate<T>>();
|
||||
List<Predicate<T>> r = new ArrayList<>();
|
||||
for (Predicate<T> p : n) {
|
||||
if (!r.contains(p)) {
|
||||
r.add(p);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class VariablePredicate<T> extends Predicate<T> {
|
||||
if (children.size() != 1) {
|
||||
throw new IllegalArgumentException("Expected exactly one child");
|
||||
}
|
||||
return new VariablePredicate<T>(getName(), children.iterator().next());
|
||||
return new VariablePredicate<>(getName(), children.iterator().next());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
abstract class AbstractResultSet<T> implements ResultSet<T> {
|
||||
@Override
|
||||
public List<T> toList() {
|
||||
ArrayList<T> r = new ArrayList<T>();
|
||||
ArrayList<T> r = new ArrayList<>();
|
||||
for (T t : this) {
|
||||
r.add(t);
|
||||
}
|
||||
|
||||
@@ -68,8 +68,7 @@ public class AndSource extends AndPredicate<ChangeData>
|
||||
|
||||
private static List<Predicate<ChangeData>> sort(
|
||||
Collection<? extends Predicate<ChangeData>> that) {
|
||||
ArrayList<Predicate<ChangeData>> r =
|
||||
new ArrayList<Predicate<ChangeData>>(that);
|
||||
List<Predicate<ChangeData>> r = new ArrayList<>(that);
|
||||
Collections.sort(r, CMP);
|
||||
return r;
|
||||
}
|
||||
@@ -158,7 +157,7 @@ public class AndSource extends AndPredicate<ChangeData>
|
||||
} else if (start > 0) {
|
||||
r = ImmutableList.copyOf(r.subList(start, r.size()));
|
||||
}
|
||||
return new ListResultSet<ChangeData>(r);
|
||||
return new ListResultSet<>(r);
|
||||
}
|
||||
|
||||
private Iterable<ChangeData> buffer(
|
||||
|
||||
@@ -281,7 +281,7 @@ public class ChangeData {
|
||||
return currentFiles;
|
||||
}
|
||||
|
||||
List<String> r = new ArrayList<String>(p.getPatches().size());
|
||||
List<String> r = new ArrayList<>(p.getPatches().size());
|
||||
for (PatchListEntry e : p.getPatches()) {
|
||||
if (Patch.COMMIT_MSG.equals(e.getNewName())) {
|
||||
continue;
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.google.inject.Provider;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
abstract class ChangeDataResultSet<T> extends AbstractResultSet<ChangeData> {
|
||||
static ResultSet<ChangeData> change(final ChangeData.Factory factory,
|
||||
@@ -78,7 +79,7 @@ abstract class ChangeDataResultSet<T> extends AbstractResultSet<ChangeData> {
|
||||
} else {
|
||||
return new Iterator<ChangeData>() {
|
||||
private final Iterator<T> itr = source.iterator();
|
||||
private final HashSet<Change.Id> seen = new HashSet<Change.Id>();
|
||||
private final Set<Change.Id> seen = new HashSet<>();
|
||||
private ChangeData next;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -548,7 +548,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
//
|
||||
Collection<GroupReference> suggestions = args.groupBackend.suggest(who, null);
|
||||
if (!suggestions.isEmpty()) {
|
||||
HashSet<AccountGroup.UUID> ids = new HashSet<AccountGroup.UUID>();
|
||||
HashSet<AccountGroup.UUID> ids = new HashSet<>();
|
||||
for (GroupReference ref : suggestions) {
|
||||
ids.add(ref.getUUID());
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class ChangeStatusPredicate extends IndexPredicate<ChangeData> {
|
||||
}
|
||||
|
||||
public static Predicate<ChangeData> open(Provider<ReviewDb> dbProvider) {
|
||||
List<Predicate<ChangeData>> r = new ArrayList<Predicate<ChangeData>>(4);
|
||||
List<Predicate<ChangeData>> r = new ArrayList<>(4);
|
||||
for (final Change.Status e : Change.Status.values()) {
|
||||
if (e.isOpen()) {
|
||||
r.add(new ChangeStatusPredicate(e));
|
||||
@@ -59,7 +59,7 @@ public final class ChangeStatusPredicate extends IndexPredicate<ChangeData> {
|
||||
}
|
||||
|
||||
public static Predicate<ChangeData> closed(Provider<ReviewDb> dbProvider) {
|
||||
List<Predicate<ChangeData>> r = new ArrayList<Predicate<ChangeData>>(4);
|
||||
List<Predicate<ChangeData>> r = new ArrayList<>(4);
|
||||
for (final Change.Status e : Change.Status.values()) {
|
||||
if (e.isClosed()) {
|
||||
r.add(new ChangeStatusPredicate(e));
|
||||
|
||||
@@ -25,6 +25,8 @@ import com.google.gwtorm.server.ResultSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
class HasDraftByPredicate extends OperatorPredicate<ChangeData> implements
|
||||
ChangeDataSource {
|
||||
@@ -50,17 +52,17 @@ class HasDraftByPredicate extends OperatorPredicate<ChangeData> implements
|
||||
|
||||
@Override
|
||||
public ResultSet<ChangeData> read() throws OrmException {
|
||||
HashSet<Change.Id> ids = new HashSet<Change.Id>();
|
||||
Set<Change.Id> ids = new HashSet<>();
|
||||
for (PatchLineComment sc : args.db.get().patchComments()
|
||||
.draftByAuthor(accountId)) {
|
||||
ids.add(sc.getKey().getParentKey().getParentKey().getParentKey());
|
||||
}
|
||||
|
||||
ArrayList<ChangeData> r = new ArrayList<ChangeData>(ids.size());
|
||||
List<ChangeData> r = new ArrayList<>(ids.size());
|
||||
for (Change.Id id : ids) {
|
||||
r.add(args.changeDataFactory.create(args.db.get(), id));
|
||||
}
|
||||
return new ListResultSet<ChangeData>(r);
|
||||
return new ListResultSet<>(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,10 +44,10 @@ class LegacyChangeIdPredicate extends IndexPredicate<ChangeData> implements
|
||||
public ResultSet<ChangeData> read() throws OrmException {
|
||||
Change c = args.db.get().changes().get(id);
|
||||
if (c != null) {
|
||||
return new ListResultSet<ChangeData>(Collections.singletonList(
|
||||
return new ListResultSet<>(Collections.singletonList(
|
||||
args.changeDataFactory.create(args.db.get(), c)));
|
||||
} else {
|
||||
return new ListResultSet<ChangeData>(Collections.<ChangeData> emptyList());
|
||||
return new ListResultSet<>(Collections.<ChangeData> emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ import com.google.gwtorm.server.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class OrSource extends OrPredicate<ChangeData> implements ChangeDataSource {
|
||||
private int cardinality = -1;
|
||||
@@ -36,8 +38,8 @@ public class OrSource extends OrPredicate<ChangeData> implements ChangeDataSourc
|
||||
public ResultSet<ChangeData> read() throws OrmException {
|
||||
// TODO(spearce) This probably should be more lazy.
|
||||
//
|
||||
ArrayList<ChangeData> r = new ArrayList<ChangeData>();
|
||||
HashSet<Change.Id> have = new HashSet<Change.Id>();
|
||||
List<ChangeData> r = new ArrayList<>();
|
||||
Set<Change.Id> have = new HashSet<>();
|
||||
for (Predicate<ChangeData> p : getChildren()) {
|
||||
if (p instanceof ChangeDataSource) {
|
||||
for (ChangeData cd : ((ChangeDataSource) p).read()) {
|
||||
@@ -49,7 +51,7 @@ public class OrSource extends OrPredicate<ChangeData> implements ChangeDataSourc
|
||||
throw new OrmException("No ChangeDataSource: " + p);
|
||||
}
|
||||
}
|
||||
return new ListResultSet<ChangeData>(r);
|
||||
return new ListResultSet<>(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -551,7 +551,7 @@ public class QueryProcessor {
|
||||
}
|
||||
|
||||
private List<Field> fieldsOf(Class<?> type) {
|
||||
List<Field> r = new ArrayList<Field>();
|
||||
List<Field> r = new ArrayList<>();
|
||||
if (type.getSuperclass() != null) {
|
||||
r.addAll(fieldsOf(type.getSuperclass()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user