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

Change-Id: Ia14802c903ca67b9d94dc6038d70b0e9644bc621
This commit is contained in:
David Ostrovsky
2014-04-26 15:27:57 +02:00
parent 40a179b8ca
commit e73ae61339
224 changed files with 557 additions and 633 deletions

View File

@@ -57,7 +57,7 @@ public abstract class PrologTestCase {
protected void load(String pkg, String prologResource, Module... modules)
throws CompileException, IOException {
ArrayList<Module> moduleList = new ArrayList<Module>();
ArrayList<Module> moduleList = new ArrayList<>();
moduleList.add(new PrologModule.EnvironmentModule());
moduleList.addAll(Arrays.asList(modules));
@@ -74,7 +74,7 @@ public abstract class PrologTestCase {
SymbolTerm.intern(pkg),
new StructureTerm(test_1, new VariableTerm()));
tests = new ArrayList<Term>();
tests = new ArrayList<>();
for (Term[] pair : env.all(Prolog.BUILTIN, "clause", head, new VariableTerm())) {
tests.add(pair[0]);
}

View File

@@ -158,7 +158,7 @@ public class CommentsTest {
return new IAnswer<ResultSet<PatchLineComment>>() {
@Override
public ResultSet<PatchLineComment> answer() throws Throwable {
return new ListResultSet<PatchLineComment>(Lists.newArrayList(comments));
return new ListResultSet<>(Lists.newArrayList(comments));
}};
}

View File

@@ -58,8 +58,8 @@ public class IncludedInResolverTest extends RepositoryTestCase {
private RevCommit commit_v1_3;
private RevCommit commit_v2_5;
private List<String> expTags = new ArrayList<String>();
private List<String> expBranches = new ArrayList<String>();
private List<String> expTags = new ArrayList<>();
private List<String> expBranches = new ArrayList<>();
private RevWalk revWalk;

View File

@@ -65,7 +65,7 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
public void setUp() throws Exception {
super.setUp();
db = createBareRepository();
util = new TestRepository<Repository>(db);
util = new TestRepository<>(db);
}
@Test

View File

@@ -127,7 +127,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
expect(schema.submoduleSubscriptions()).andReturn(subscriptions);
final ResultSet<SubmoduleSubscription> emptySubscriptions =
new ListResultSet<SubmoduleSubscription>(new ArrayList<SubmoduleSubscription>());
new ListResultSet<>(new ArrayList<SubmoduleSubscription>());
expect(subscriptions.bySubmodule(branchNameKey)).andReturn(
emptySubscriptions);
@@ -293,8 +293,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
new Branch.NameKey(new Project.NameKey("dest-project"),
"refs/heads/master");
final List<SubmoduleSubscription> subscriptionsToInsert =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> subscriptionsToInsert = new ArrayList<>();
subscriptionsToInsert
.add(new SubmoduleSubscription(mergedBranch, new Branch.NameKey(
new Project.NameKey("source-a"), "refs/heads/master"), "source-a"));
@@ -351,8 +350,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
new Branch.NameKey(new Project.NameKey("dest-project"),
"refs/heads/master");
final List<SubmoduleSubscription> subscriptionsToInsert =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> subscriptionsToInsert = new ArrayList<>();
subscriptionsToInsert
.add(new SubmoduleSubscription(mergedBranch, new Branch.NameKey(
new Project.NameKey("source-a"), "refs/heads/master"), "source-a"));
@@ -409,8 +407,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
new Branch.NameKey(new Project.NameKey("dest-project"),
"refs/heads/master");
final List<SubmoduleSubscription> subscriptionsToInsert =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> subscriptionsToInsert = new ArrayList<>();
subscriptionsToInsert
.add(new SubmoduleSubscription(mergedBranch, new Branch.NameKey(
new Project.NameKey("source-a"), "refs/heads/test-a"), "source-a"));
@@ -464,14 +461,12 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
new Branch.NameKey(new Project.NameKey("dest-project"),
"refs/heads/master");
final List<SubmoduleSubscription> subscriptionsToInsert =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> subscriptionsToInsert = new ArrayList<>();
subscriptionsToInsert.add(new SubmoduleSubscription(mergedBranch,
new Branch.NameKey(new Project.NameKey("source"), "refs/heads/master"),
"source"));
final List<SubmoduleSubscription> oldOnesToMergedBranch =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> oldOnesToMergedBranch = new ArrayList<>();
oldOnesToMergedBranch.add(new SubmoduleSubscription(mergedBranch,
new Branch.NameKey(new Project.NameKey("old-source"),
"refs/heads/master"), "old-source"));
@@ -531,15 +526,13 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
new SubmoduleSubscription(mergedBranch, new Branch.NameKey(new Project.NameKey(
"old"), "refs/heads/master"), "old");
final List<SubmoduleSubscription> extractedsubscriptions =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> extractedsubscriptions = new ArrayList<>();
extractedsubscriptions.add(new SubmoduleSubscription(mergedBranch,
new Branch.NameKey(new Project.NameKey("new"), "refs/heads/master"),
"new"));
extractedsubscriptions.add(old);
final List<SubmoduleSubscription> oldOnesToMergedBranch =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> oldOnesToMergedBranch = new ArrayList<>();
oldOnesToMergedBranch.add(old);
doOnlySubscriptionTableOperations(sb.toString(), mergedBranch,
@@ -564,11 +557,8 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
new Branch.NameKey(new Project.NameKey("dest-project"),
"refs/heads/master");
final List<SubmoduleSubscription> extractedsubscriptions =
new ArrayList<SubmoduleSubscription>();
final List<SubmoduleSubscription> oldOnesToMergedBranch =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> extractedsubscriptions = new ArrayList<>();
List<SubmoduleSubscription> oldOnesToMergedBranch = new ArrayList<>();
oldOnesToMergedBranch
.add(new SubmoduleSubscription(mergedBranch, new Branch.NameKey(
new Project.NameKey("source-a"), "refs/heads/master"), "source-a"));
@@ -613,11 +603,10 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
new Change.Key(sourceMergeTip.toObjectId().getName()), new Change.Id(1),
new Account.Id(1), sourceBranchNameKey, TimeUtil.nowTs());
final Map<Change.Id, CodeReviewCommit> mergedCommits =
new HashMap<Change.Id, CodeReviewCommit>();
final Map<Change.Id, CodeReviewCommit> mergedCommits = new HashMap<>();
mergedCommits.put(submittedChange.getId(), codeReviewCommit);
final List<Change> submitted = new ArrayList<Change>();
final List<Change> submitted = new ArrayList<>();
submitted.add(submittedChange);
final Repository targetRepository = createWorkRepository();
@@ -635,7 +624,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
expect(schema.submoduleSubscriptions()).andReturn(subscriptions);
final ResultSet<SubmoduleSubscription> subscribers =
new ListResultSet<SubmoduleSubscription>(Collections
new ListResultSet<>(Collections
.singletonList(new SubmoduleSubscription(targetBranchNameKey,
sourceBranchNameKey, "source-project")));
expect(subscriptions.bySubmodule(sourceBranchNameKey)).andReturn(
@@ -644,13 +633,13 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
expect(repoManager.openRepository(targetBranchNameKey.getParentKey()))
.andReturn(targetRepository).anyTimes();
Capture<RefUpdate> ruCapture = new Capture<RefUpdate>();
Capture<RefUpdate> ruCapture = new Capture<>();
gitRefUpdated.fire(eq(targetBranchNameKey.getParentKey()),
capture(ruCapture));
expect(schema.submoduleSubscriptions()).andReturn(subscriptions);
final ResultSet<SubmoduleSubscription> emptySubscriptions =
new ListResultSet<SubmoduleSubscription>(new ArrayList<SubmoduleSubscription>());
new ListResultSet<>(new ArrayList<SubmoduleSubscription>());
expect(subscriptions.bySubmodule(targetBranchNameKey)).andReturn(
emptySubscriptions);
@@ -716,11 +705,10 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
new Change.Key(sourceMergeTip.toObjectId().getName()), new Change.Id(1),
new Account.Id(1), sourceBranchNameKey, TimeUtil.nowTs());
final Map<Change.Id, CodeReviewCommit> mergedCommits =
new HashMap<Change.Id, CodeReviewCommit>();
final Map<Change.Id, CodeReviewCommit> mergedCommits = new HashMap<>();
mergedCommits.put(submittedChange.getId(), codeReviewCommit);
final List<Change> submitted = new ArrayList<Change>();
final List<Change> submitted = new ArrayList<>();
submitted.add(submittedChange);
final Repository targetRepository = createWorkRepository();
@@ -738,7 +726,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
expect(schema.submoduleSubscriptions()).andReturn(subscriptions);
final ResultSet<SubmoduleSubscription> subscribers =
new ListResultSet<SubmoduleSubscription>(Collections
new ListResultSet<>(Collections
.singletonList(new SubmoduleSubscription(targetBranchNameKey,
sourceBranchNameKey, "source-project")));
expect(subscriptions.bySubmodule(sourceBranchNameKey)).andReturn(
@@ -747,7 +735,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
expect(repoManager.openRepository(targetBranchNameKey.getParentKey()))
.andReturn(targetRepository).anyTimes();
Capture<RefUpdate> ruCapture = new Capture<RefUpdate>();
Capture<RefUpdate> ruCapture = new Capture<>();
gitRefUpdated.fire(eq(targetBranchNameKey.getParentKey()),
capture(ruCapture));
@@ -803,8 +791,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
new Branch.NameKey(new Project.NameKey("dest-project"),
"refs/heads/master");
final List<SubmoduleSubscription> subscriptionsToInsert =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> subscriptionsToInsert = new ArrayList<>();
subscriptionsToInsert.add(new SubmoduleSubscription(mergedBranch,
new Branch.NameKey(new Project.NameKey("source"), sourceBranchName),
"source"));
@@ -878,10 +865,9 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
expect(schema.submoduleSubscriptions()).andReturn(subscriptions);
expect(subscriptions.bySuperProject(mergedBranch)).andReturn(
new ListResultSet<SubmoduleSubscription>(previousSubscriptions));
new ListResultSet<>(previousSubscriptions));
SortedSet<Project.NameKey> existingProjects =
new TreeSet<Project.NameKey>();
SortedSet<Project.NameKey> existingProjects = new TreeSet<>();
for (SubmoduleSubscription extracted : extractedSubscriptions) {
existingProjects.add(extracted.getSubmodule().getParentKey());
@@ -891,8 +877,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
expect(repoManager.list()).andReturn(existingProjects);
}
final Set<SubmoduleSubscription> alreadySubscribeds =
new HashSet<SubmoduleSubscription>();
final Set<SubmoduleSubscription> alreadySubscribeds = new HashSet<>();
for (SubmoduleSubscription s : extractedSubscriptions) {
if (previousSubscriptions.contains(s)) {
alreadySubscribeds.add(s);
@@ -900,9 +885,9 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
}
final Set<SubmoduleSubscription> subscriptionsToRemove =
new HashSet<SubmoduleSubscription>(previousSubscriptions);
new HashSet<>(previousSubscriptions);
final List<SubmoduleSubscription> subscriptionsToInsert =
new ArrayList<SubmoduleSubscription>(extractedSubscriptions);
new ArrayList<>(extractedSubscriptions);
subscriptionsToRemove.removeAll(subscriptionsToInsert);
subscriptionsToInsert.removeAll(alreadySubscribeds);
@@ -917,7 +902,7 @@ public class SubmoduleOpTest extends LocalDiskRepositoryTestCase {
expect(schema.submoduleSubscriptions()).andReturn(subscriptions);
expect(subscriptions.bySubmodule(mergedBranch)).andReturn(
new ListResultSet<SubmoduleSubscription>(new ArrayList<SubmoduleSubscription>()));
new ListResultSet<>(new ArrayList<SubmoduleSubscription>()));
schema.close();

View File

@@ -23,11 +23,11 @@ import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.ResultSet;
class FakeIndex implements ChangeIndex {
static Schema<ChangeData> V1 = new Schema<ChangeData>(1, false,
static Schema<ChangeData> V1 = new Schema<>(1, false,
ImmutableList.<FieldDef<ChangeData, ?>> of(
ChangeField.STATUS));
static Schema<ChangeData> V2 = new Schema<ChangeData>(2, false,
static Schema<ChangeData> V2 = new Schema<>(2, false,
ImmutableList.of(
ChangeField.STATUS,
ChangeField.PATH,

View File

@@ -23,7 +23,7 @@ import com.google.gwtorm.server.OrmException;
public class FakeQueryBuilder extends ChangeQueryBuilder {
FakeQueryBuilder(IndexCollection indexes) {
super(
new FakeQueryBuilder.Definition<ChangeData, FakeQueryBuilder>(
new FakeQueryBuilder.Definition<>(
FakeQueryBuilder.class),
new ChangeQueryBuilder.Arguments(null, null, null, null, null, null,
null, null, null, null, null, null, null, null, indexes, null, null,

View File

@@ -140,7 +140,7 @@ public class Util {
private final ProjectConfig parent = new ProjectConfig(allProjectsName);
public Util() {
all = new HashMap<Project.NameKey, ProjectState>();
all = new HashMap<>();
repoManager = new InMemoryRepositoryManager();
try {
Repository repo = repoManager.createRepository(allProjectsName);

View File

@@ -24,7 +24,7 @@ import static org.junit.Assert.assertTrue;
public class IdGeneratorTest {
@Test
public void test1234() {
final HashSet<Integer> seen = new HashSet<Integer>();
final HashSet<Integer> seen = new HashSet<>();
for (int i = 0; i < 1 << 16; i++) {
final int e = IdGenerator.mix(i);
assertTrue("no duplicates", seen.add(e));

View File

@@ -64,8 +64,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
@Test
public void testSubmodulesParseWithCorrectSections() throws Exception {
final Map<String, SubmoduleSection> sectionsToReturn =
new TreeMap<String, SubmoduleSection>();
final Map<String, SubmoduleSection> sectionsToReturn = new TreeMap<>();
sectionsToReturn.put("a", new SubmoduleSection("ssh://localhost/a", "a",
"."));
sectionsToReturn.put("b", new SubmoduleSection("ssh://localhost/b", "b",
@@ -77,7 +76,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
sectionsToReturn.put("e", new SubmoduleSection("ssh://localhost/e.git", "e",
"."));
final Map<String, String> reposToBeFound = new HashMap<String, String>();
Map<String, String> reposToBeFound = new HashMap<>();
reposToBeFound.put("a", "a");
reposToBeFound.put("b", "b");
reposToBeFound.put("c", "test/c");
@@ -88,8 +87,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
new Branch.NameKey(new Project.NameKey("super-project"),
"refs/heads/master");
final List<SubmoduleSubscription> expectedSubscriptions =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> expectedSubscriptions = new ArrayList<>();
expectedSubscriptions
.add(new SubmoduleSubscription(superBranchNameKey, new Branch.NameKey(
new Project.NameKey("a"), "refs/heads/master"), "a"));
@@ -112,8 +110,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
@Test
public void testSubmodulesParseWithAnInvalidSection() throws Exception {
final Map<String, SubmoduleSection> sectionsToReturn =
new TreeMap<String, SubmoduleSection>();
final Map<String, SubmoduleSection> sectionsToReturn = new TreeMap<>();
sectionsToReturn.put("a", new SubmoduleSection("ssh://localhost/a", "a",
"."));
// This one is invalid since "b" is not a recognized project
@@ -127,7 +124,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
"."));
// "b" will not be in this list
final Map<String, String> reposToBeFound = new HashMap<String, String>();
Map<String, String> reposToBeFound = new HashMap<>();
reposToBeFound.put("a", "a");
reposToBeFound.put("c", "test/c");
reposToBeFound.put("d", "d");
@@ -137,8 +134,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
new Branch.NameKey(new Project.NameKey("super-project"),
"refs/heads/master");
final List<SubmoduleSubscription> expectedSubscriptions =
new ArrayList<SubmoduleSubscription>();
List<SubmoduleSubscription> expectedSubscriptions = new ArrayList<>();
expectedSubscriptions
.add(new SubmoduleSubscription(superBranchNameKey, new Branch.NameKey(
new Project.NameKey("a"), "refs/heads/master"), "a"));
@@ -158,8 +154,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
@Test
public void testSubmoduleSectionToOtherServer() throws Exception {
Map<String, SubmoduleSection> sectionsToReturn =
new HashMap<String, SubmoduleSection>();
Map<String, SubmoduleSection> sectionsToReturn = new HashMap<>();
// The url is not to this server.
sectionsToReturn.put("a", new SubmoduleSection("ssh://review.source.com/a",
"a", "."));
@@ -171,8 +166,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
@Test
public void testProjectNotFound() throws Exception {
Map<String, SubmoduleSection> sectionsToReturn =
new HashMap<String, SubmoduleSection>();
Map<String, SubmoduleSection> sectionsToReturn = new HashMap<>();
sectionsToReturn.put("a", new SubmoduleSection("ssh://localhost/a", "a",
"."));
@@ -183,8 +177,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
@Test
public void testProjectWithSlashesNotFound() throws Exception {
Map<String, SubmoduleSection> sectionsToReturn =
new HashMap<String, SubmoduleSection>();
Map<String, SubmoduleSection> sectionsToReturn = new HashMap<>();
sectionsToReturn.put("project", new SubmoduleSection(
"ssh://localhost/company/tools/project", "project", "."));
@@ -222,12 +215,12 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
}
if (projectNameCandidate.equals(reposToBeFound.get(id))) {
expect(repoManager.list()).andReturn(
new TreeSet<Project.NameKey>(Collections
.singletonList(new Project.NameKey(projectNameCandidate))));
new TreeSet<>(Collections.singletonList(
new Project.NameKey(projectNameCandidate))));
break;
} else {
expect(repoManager.list()).andReturn(
new TreeSet<Project.NameKey>(Collections.<Project.NameKey> emptyList()));
new TreeSet<>(Collections.<Project.NameKey> emptyList()));
}
}
}

View File

@@ -91,7 +91,7 @@ public class InMemoryDatabase implements SchemaFactory<ReviewDb> {
// Build the access layer around the connection factory.
//
database = new Database<ReviewDb>(dataSource, ReviewDb.class);
database = new Database<>(dataSource, ReviewDb.class);
} catch (SQLException e) {
throw new OrmException(e);

View File

@@ -138,8 +138,8 @@ public abstract class MockingTestCase extends TestCase {
usePowerMock = PowerMockRunner.class.isAssignableFrom(runWith.value());
}
mocks = new ArrayList<Object>();
mockControls = new ArrayList<IMocksControl>();
mocks = new ArrayList<>();
mockControls = new ArrayList<>();
mocksReplayed = false;
}

View File

@@ -29,7 +29,7 @@ import java.util.Set;
*/
public class SetMatcher<T> implements IArgumentMatcher {
public static <S extends Iterable<T>,T> S setEq(S expected) {
EasyMock.reportMatcher(new SetMatcher<T>(expected));
EasyMock.reportMatcher(new SetMatcher<>(expected));
return null;
}

View File

@@ -29,7 +29,7 @@ public class CollectionAppender extends AppenderSkeleton {
private Collection<LoggingEvent> events;
public CollectionAppender() {
events = new LinkedList<LoggingEvent>();
events = new LinkedList<>();
}
public CollectionAppender(Collection<LoggingEvent> events) {

View File

@@ -59,7 +59,7 @@ public class LogUtil {
this.additive = logger.getAdditivity();
Enumeration<?> appenders = logger.getAllAppenders();
this.appenders = new ArrayList<Appender>();
this.appenders = new ArrayList<>();
while (appenders.hasMoreElements()) {
Object appender = appenders.nextElement();
if (appender instanceof Appender) {