Apply "type inference for generic instance creation" Java 7 feature

Since GWT 2.6.0 support for Java 7 is added. Simplify creation of
classes in GWT's client code.

Change-Id: I08ff2c189d2874a6b957072912912e4a6089cdd1
This commit is contained in:
David Ostrovsky
2014-01-19 17:39:10 +01:00
parent dd34a05fdf
commit 6ee971b373
74 changed files with 194 additions and 214 deletions

View File

@@ -25,9 +25,8 @@ import java.util.Map;
import java.util.Set;
public class ProjectAccessUtil {
public static List<AccessSection> mergeSections(final List<AccessSection> src) {
final Map<String, AccessSection> map =
new LinkedHashMap<String, AccessSection>();
public static List<AccessSection> mergeSections(List<AccessSection> src) {
Map<String, AccessSection> map = new LinkedHashMap<>();
for (final AccessSection section : src) {
if (section.getPermissions().isEmpty()) {
continue;
@@ -40,14 +39,14 @@ public class ProjectAccessUtil {
map.put(section.getName(), section);
}
}
return new ArrayList<AccessSection>(map.values());
return new ArrayList<>(map.values());
}
public static List<AccessSection> removeEmptyPermissionsAndSections(
final List<AccessSection> src) {
final Set<AccessSection> sectionsToRemove = new HashSet<AccessSection>();
final Set<AccessSection> sectionsToRemove = new HashSet<>();
for (final AccessSection section : src) {
final Set<Permission> permissionsToRemove = new HashSet<Permission>();
final Set<Permission> permissionsToRemove = new HashSet<>();
for (final Permission permission : section.getPermissions()) {
if (permission.getRules().isEmpty()) {
permissionsToRemove.add(permission);

View File

@@ -39,13 +39,13 @@ public class AccessSection extends RefConfigSection implements
public List<Permission> getPermissions() {
if (permissions == null) {
permissions = new ArrayList<Permission>();
permissions = new ArrayList<>();
}
return permissions;
}
public void setPermissions(List<Permission> list) {
Set<String> names = new HashSet<String>();
Set<String> names = new HashSet<>();
for (Permission p : list) {
if (!names.add(p.getName().toLowerCase())) {
throw new IllegalArgumentException();
@@ -124,7 +124,7 @@ public class AccessSection extends RefConfigSection implements
if (!super.equals(obj) || !(obj instanceof AccessSection)) {
return false;
}
return new HashSet<Permission>(getPermissions()).equals(new HashSet<Permission>(
return new HashSet<Permission>(getPermissions()).equals(new HashSet<>(
((AccessSection) obj).getPermissions()));
}
}

View File

@@ -39,7 +39,7 @@ public class AccountInfoCache {
}
public AccountInfoCache(final Iterable<AccountInfo> list) {
accounts = new HashMap<Account.Id, AccountInfo>();
accounts = new HashMap<>();
for (final AccountInfo ai : list) {
accounts.put(ai.getId(), ai);
}

View File

@@ -30,7 +30,7 @@ import java.util.Set;
public class ApprovalDetail {
public static List<ApprovalDetail> sort(Collection<ApprovalDetail> ads,
final int owner) {
List<ApprovalDetail> sorted = new ArrayList<ApprovalDetail>(ads);
List<ApprovalDetail> sorted = new ArrayList<>(ads);
Collections.sort(sorted, new Comparator<ApprovalDetail>() {
public int compare(ApprovalDetail o1, ApprovalDetail o2) {
int byOwner = (o2.account.get() == owner ? 1 : 0)
@@ -56,7 +56,7 @@ public class ApprovalDetail {
public ApprovalDetail(final Account.Id id) {
account = id;
approvals = new ArrayList<PatchSetApproval>();
approvals = new ArrayList<>();
}
public Account.Id getAccount() {
@@ -73,7 +73,7 @@ public class ApprovalDetail {
public void approved(String label) {
if (approved == null) {
approved = new HashSet<String>();
approved = new HashSet<>();
}
approved.add(label);
hasNonZero = 1;
@@ -81,7 +81,7 @@ public class ApprovalDetail {
public void rejected(String label) {
if (rejected == null) {
rejected = new HashSet<String>();
rejected = new HashSet<>();
}
rejected.add(label);
hasNonZero = 1;
@@ -89,14 +89,14 @@ public class ApprovalDetail {
public void votable(String label) {
if (votable == null) {
votable = new HashSet<String>();
votable = new HashSet<>();
}
votable.add(label);
}
public void value(String label, int value) {
if (values == null) {
values = new HashMap<String, Integer>();
values = new HashMap<>();
}
values.put(label, value);
if (value != 0) {

View File

@@ -33,9 +33,9 @@ public class CommentDetail {
private transient Map<Integer, List<PatchLineComment>> forA;
private transient Map<Integer, List<PatchLineComment>> forB;
public CommentDetail(final PatchSet.Id idA, final PatchSet.Id idB) {
this.a = new ArrayList<PatchLineComment>();
this.b = new ArrayList<PatchLineComment>();
public CommentDetail(PatchSet.Id idA, PatchSet.Id idB) {
this.a = new ArrayList<>();
this.b = new ArrayList<>();
this.idA = idA;
this.idB = idB;
}
@@ -121,18 +121,18 @@ public class CommentDetail {
// possible for several comments to have the same parent (this can happen if two reviewers
// click Reply on the same comment at the same time). Such comments will be displayed under
// their correct parent in chronological order.
Map<String, List<PatchLineComment>> parentMap = new HashMap<String, List<PatchLineComment>>();
Map<String, List<PatchLineComment>> parentMap = new HashMap<>();
// It's possible to have more than one root comment if two reviewers create a comment on the
// same line at the same time
List<PatchLineComment> rootComments = new ArrayList<PatchLineComment>();
List<PatchLineComment> rootComments = new ArrayList<>();
// Store all the comments in parentMap, keyed by their parent
for (PatchLineComment c : comments) {
String parentUuid = c.getParentUuid();
List<PatchLineComment> l = parentMap.get(parentUuid);
if (l == null) {
l = new ArrayList<PatchLineComment>();
l = new ArrayList<>();
parentMap.put(parentUuid, l);
}
l.add(c);
@@ -141,7 +141,7 @@ public class CommentDetail {
// Add the comments in the list, starting with the head and then going through all the
// comments that have it as a parent, and so on
List<PatchLineComment> result = new ArrayList<PatchLineComment>();
List<PatchLineComment> result = new ArrayList<>();
addChildren(parentMap, rootComments, result);
return result;
@@ -161,14 +161,12 @@ public class CommentDetail {
}
private Map<Integer, List<PatchLineComment>> index(
final List<PatchLineComment> in) {
final HashMap<Integer, List<PatchLineComment>> r;
r = new HashMap<Integer, List<PatchLineComment>>();
List<PatchLineComment> in) {
HashMap<Integer, List<PatchLineComment>> r = new HashMap<>();
for (final PatchLineComment p : in) {
List<PatchLineComment> l = r.get(p.getLine());
if (l == null) {
l = new ArrayList<PatchLineComment>();
l = new ArrayList<>();
r.put(p.getLine(), l);
}
l.add(p);

View File

@@ -54,7 +54,7 @@ public class ContributorAgreement implements Comparable<ContributorAgreement> {
public List<PermissionRule> getAccepted() {
if (accepted == null) {
accepted = new ArrayList<PermissionRule>();
accepted = new ArrayList<>();
}
return accepted;
}

View File

@@ -23,7 +23,7 @@ public class GarbageCollectionResult {
protected List<Error> errors;
public GarbageCollectionResult() {
errors = new ArrayList<Error>();
errors = new ArrayList<>();
}
public void addError(Error e) {

View File

@@ -92,7 +92,7 @@ public class GlobalCapability {
private static final List<String> NAMES_LC;
static {
NAMES_ALL = new ArrayList<String>();
NAMES_ALL = new ArrayList<>();
NAMES_ALL.add(ACCESS_DATABASE);
NAMES_ALL.add(ADMINISTRATE_SERVER);
NAMES_ALL.add(CREATE_ACCOUNT);
@@ -110,7 +110,7 @@ public class GlobalCapability {
NAMES_ALL.add(VIEW_CONNECTIONS);
NAMES_ALL.add(VIEW_QUEUE);
NAMES_LC = new ArrayList<String>(NAMES_ALL.size());
NAMES_LC = new ArrayList<>(NAMES_ALL.size());
for (String name : NAMES_ALL) {
NAMES_LC.add(name.toLowerCase());
}

View File

@@ -39,7 +39,7 @@ public class GroupInfoCache {
}
public GroupInfoCache(final Iterable<GroupInfo> list) {
groups = new HashMap<AccountGroup.UUID, GroupInfo>();
groups = new HashMap<>();
for (final GroupInfo gi : list) {
groups.put(gi.getId(), gi);
}

View File

@@ -27,7 +27,7 @@ import java.util.Map;
public class LabelType {
public static LabelType withDefaultValues(String name) {
checkName(name);
List<LabelValue> values = new ArrayList<LabelValue>(2);
List<LabelValue> values = new ArrayList<>(2);
values.add(new LabelValue((short) 0, "Rejected"));
values.add(new LabelValue((short) 1, "Approved"));
return new LabelType(name, values);
@@ -75,7 +75,7 @@ public class LabelType {
}
private static List<LabelValue> sortValues(List<LabelValue> values) {
values = new ArrayList<LabelValue>(values);
values = new ArrayList<>(values);
if (values.size() <= 1) {
return Collections.unmodifiableList(values);
}
@@ -88,7 +88,7 @@ public class LabelType {
short max = values.get(values.size() - 1).getValue();
short v = min;
short i = 0;
List<LabelValue> result = new ArrayList<LabelValue>(max - min + 1);
List<LabelValue> result = new ArrayList<>(max - min + 1);
// Fill in any missing values with empty text.
while (i < values.size()) {
while (v < values.get(i).getValue()) {
@@ -252,7 +252,7 @@ public class LabelType {
private void initByValue() {
if (byValue == null) {
byValue = new HashMap<Short, LabelValue>();
byValue = new HashMap<>();
for (final LabelValue v : values) {
byValue.put(v.getValue(), v);
}
@@ -261,7 +261,7 @@ public class LabelType {
public List<Integer> getValuesAsList() {
if (intList == null) {
intList = new ArrayList<Integer>(values.size());
intList = new ArrayList<>(values.size());
for (LabelValue v : values) {
intList.add(Integer.valueOf(v.getValue()));
}

View File

@@ -52,7 +52,7 @@ public class LabelTypes {
if (byLabel == null) {
synchronized (this) {
if (byLabel == null) {
Map<String, LabelType> l = new HashMap<String, LabelType>();
Map<String, LabelType> l = new HashMap<>();
if (labelTypes != null) {
for (LabelType t : labelTypes) {
l.put(t.getName().toLowerCase(), t);
@@ -95,7 +95,7 @@ public class LabelTypes {
if (positions == null) {
synchronized (this) {
if (positions == null) {
Map<String, Integer> p = new HashMap<String, Integer>();
Map<String, Integer> p = new HashMap<>();
if (labelTypes != null) {
int i = 0;
for (LabelType t : labelTypes) {

View File

@@ -46,8 +46,8 @@ public class ParameterizedString {
public ParameterizedString(final String pattern) {
final StringBuilder raw = new StringBuilder();
final List<Parameter> prs = new ArrayList<Parameter>(4);
final List<Format> ops = new ArrayList<Format>(4);
final List<Parameter> prs = new ArrayList<>(4);
final List<Format> ops = new ArrayList<>(4);
int i = 0;
while (i < pattern.length()) {
@@ -95,7 +95,7 @@ public class ParameterizedString {
/** Get the list of parameter names, ordered by appearance in the pattern. */
public List<String> getParameterNames() {
final ArrayList<String> r = new ArrayList<String>(parameters.size());
final ArrayList<String> r = new ArrayList<>(parameters.size());
for (Parameter p : parameters) {
r.add(p.name);
}
@@ -132,7 +132,7 @@ public class ParameterizedString {
}
public final class Builder {
private final Map<String, String> params = new HashMap<String, String>();
private final Map<String, String> params = new HashMap<>();
public Builder replace(final String name, final String value) {
params.put(name, value);
@@ -169,7 +169,7 @@ public class ParameterizedString {
Parameter(final String parameter) {
// "parameter[.functions...]" -> (parameter, functions...)
final List<String> names = Arrays.asList(parameter.split("\\."));
final List<Function> functs = new ArrayList<Function>(names.size());
final List<Function> functs = new ArrayList<>(names.size());
if (names.isEmpty()) {
name = "";
@@ -207,7 +207,7 @@ public class ParameterizedString {
private static final Map<String, Function> FUNCTIONS = initFunctions();
private static Map<String, Function> initFunctions() {
final HashMap<String, Function> m = new HashMap<String, Function>();
HashMap<String, Function> m = new HashMap<>();
m.put("toLowerCase", new Function() {
@Override
String apply(String a) {

View File

@@ -45,7 +45,7 @@ public class PermissionRange implements Comparable<PermissionRange> {
/** @return all values between {@link #getMin()} and {@link #getMax()} */
public List<Integer> getValuesAsList() {
ArrayList<Integer> r = new ArrayList<Integer>(getRangeSize());
ArrayList<Integer> r = new ArrayList<>(getRangeSize());
for (int i = min; i <= max; i++) {
r.add(i);
}

View File

@@ -27,7 +27,7 @@ public class ReviewResult {
protected Change.Id changeId;
public ReviewResult() {
errors = new ArrayList<Error>();
errors = new ArrayList<>();
}
public void addError(final Error e) {

View File

@@ -28,7 +28,7 @@ public class ReviewerResult {
protected boolean askForConfirmation;
public ReviewerResult() {
errors = new ArrayList<Error>();
errors = new ArrayList<>();
}
public void addError(final Error e) {

View File

@@ -31,7 +31,7 @@ public class ParameterizedStringTest {
assertEquals("", p.getRawPattern());
assertTrue(p.getParameterNames().isEmpty());
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
assertNotNull(p.bind(a));
assertEquals(0, p.bind(a).length);
assertEquals("", p.replace(a));
@@ -44,7 +44,7 @@ public class ParameterizedStringTest {
assertEquals("${bar}c", p.getRawPattern());
assertTrue(p.getParameterNames().isEmpty());
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("bar", "frobinator");
assertNotNull(p.bind(a));
assertEquals(0, p.bind(a).length);
@@ -59,7 +59,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("bar"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("bar", "frobinator");
assertNotNull(p.bind(a));
assertEquals(1, p.bind(a).length);
@@ -75,7 +75,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("bar"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("bar", "frobinator");
assertNotNull(p.bind(a));
assertEquals(1, p.bind(a).length);
@@ -91,7 +91,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("bar"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("bar", "frobinator");
assertNotNull(p.bind(a));
assertEquals(1, p.bind(a).length);
@@ -107,7 +107,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("bar"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
assertNotNull(p.bind(a));
assertEquals(1, p.bind(a).length);
assertEquals("", p.bind(a)[0]);
@@ -120,7 +120,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "foo");
assertNotNull(p.bind(a));
@@ -141,7 +141,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "foo");
assertNotNull(p.bind(a));
@@ -162,7 +162,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "foo@example.com");
assertNotNull(p.bind(a));
@@ -186,7 +186,7 @@ public class ParameterizedStringTest {
assertTrue(p.getParameterNames().contains("userName"));
assertTrue(p.getParameterNames().contains("email"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("userName", "firstName lastName");
a.put("email", "FIRSTNAME.LASTNAME@EXAMPLE.COM");
assertNotNull(p.bind(a));
@@ -204,7 +204,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "FOO@EXAMPLE.COM");
assertNotNull(p.bind(a));
@@ -226,7 +226,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "foo@example.com");
assertNotNull(p.bind(a));
@@ -248,7 +248,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "foo@example.com");
assertNotNull(p.bind(a));
@@ -270,7 +270,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "foo@example.com");
assertNotNull(p.bind(a));
@@ -292,7 +292,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "FOO@EXAMPLE.COM");
assertNotNull(p.bind(a));
@@ -314,7 +314,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "FOO@EXAMPLE.COM");
assertNotNull(p.bind(a));
@@ -336,7 +336,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "FOO@EXAMPLE.COM");
assertNotNull(p.bind(a));
@@ -358,7 +358,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "FOO@EXAMPLE.COM");
assertNotNull(p.bind(a));
@@ -380,7 +380,7 @@ public class ParameterizedStringTest {
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
final Map<String, String> a = new HashMap<String, String>();
final Map<String, String> a = new HashMap<>();
a.put("a", "foo@example.com");
assertNotNull(p.bind(a));