Skip to content

Commit

Permalink
Merge pull request #1454 from kazuki43zoo/polish
Browse files Browse the repository at this point in the history
Change to use the diamond operator
  • Loading branch information
kazuki43zoo authored Jan 20, 2019
2 parents a7af8fb + f3d489f commit 090013d
Show file tree
Hide file tree
Showing 58 changed files with 183 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public <T> void addMapper(Class<T> type) {
}
boolean loadCompleted = false;
try {
knownMappers.put(type, new MapperProxyFactory<T>(type));
knownMappers.put(type, new MapperProxyFactory<>(type));
// It's important that the type is added before the parser is run
// otherwise the binding may automatically be attempted by the
// mapper parser. If the type is already known, it won't try.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -233,7 +233,7 @@ public Discriminator buildDiscriminator(
null,
null,
typeHandler,
new ArrayList<ResultFlag>(),
new ArrayList<>(),
null,
null,
false);
Expand Down Expand Up @@ -351,7 +351,7 @@ private List<ResultMap> getStatementResultMaps(
configuration,
statementId + "-Inline",
resultType,
new ArrayList<ResultMapping>(),
new ArrayList<>(),
null).build();
resultMaps.add(inlineResultMap);
}
Expand Down Expand Up @@ -382,7 +382,7 @@ public ResultMapping buildResultMapping(
.nestedResultMapId(applyCurrentNamespace(nestedResultMap, true))
.resultSet(resultSet)
.typeHandler(typeHandlerInstance)
.flags(flags == null ? new ArrayList<ResultFlag>() : flags)
.flags(flags == null ? new ArrayList<>() : flags)
.composites(composites)
.notNullColumns(parseMultipleColumnNames(notNullColumn))
.columnPrefix(columnPrefix)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -126,7 +126,7 @@ private SqlSource createSqlSource(Object parameterObject) {
+ " using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.");
}
Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
return sqlSourceParser.parse(replacePlaceholder(sql), parameterType, new HashMap<String, Object>());
return sqlSourceParser.parse(replacePlaceholder(sql), parameterType, new HashMap<>());
} catch (BuilderException e) {
throw e;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public RawSqlSource(Configuration configuration, SqlNode rootSqlNode, Class<?> p
public RawSqlSource(Configuration configuration, String sql, Class<?> parameterType) {
SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
Class<?> clazz = parameterType == null ? Object.class : parameterType;
sqlSource = sqlSourceParser.parse(sql, clazz, new HashMap<String, Object>());
sqlSource = sqlSourceParser.parse(sql, clazz, new HashMap<>());
}

private static String getSql(Configuration configuration, SqlNode rootSqlNode) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/apache/ibatis/binding/FlushTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,7 +56,7 @@ public void invokeFlushStatementsViaMapper() {

BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
Author author = new Author(-1, "cbegin", "******", "cbegin@nowhere.com", "N/A", Section.NEWS);
List<Integer> ids = new ArrayList<Integer>();
List<Integer> ids = new ArrayList<>();
mapper.insertAuthor(author);
ids.add(author.getId());
mapper.insertAuthor(author);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -61,7 +61,7 @@ public void parameterNameIsSizeAndTypeIsLong() {
@Test
public void parameterNameIsSizeUsingHashMap() {
try (SqlSession session = sqlSessionFactory.openSession()) {
HashMap<String, Object> params = new HashMap<String, Object>();
HashMap<String, Object> params = new HashMap<>();
params.put("id", "foo");
params.put("size", Long.MAX_VALUE);
Mapper mapper = session.getMapper(Mapper.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
assertThat(config.isSafeRowBoundsEnabled()).isFalse();
assertThat(config.getLocalCacheScope()).isEqualTo(LocalCacheScope.SESSION);
assertThat(config.getJdbcTypeForNull()).isEqualTo(JdbcType.OTHER);
assertThat(config.getLazyLoadTriggerMethods()).isEqualTo((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString")));
assertThat(config.getLazyLoadTriggerMethods()).isEqualTo(new HashSet<>(Arrays.asList("equals", "clone", "hashCode", "toString")));
assertThat(config.isSafeResultHandlerEnabled()).isTrue();
assertThat(config.getDefaultScriptingLanuageInstance()).isInstanceOf(XMLLanguageDriver.class);
assertThat(config.isCallSettersOnNulls()).isFalse();
Expand Down Expand Up @@ -184,7 +184,7 @@ public void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
assertThat(config.isSafeRowBoundsEnabled()).isTrue();
assertThat(config.getLocalCacheScope()).isEqualTo(LocalCacheScope.STATEMENT);
assertThat(config.getJdbcTypeForNull()).isEqualTo(JdbcType.NULL);
assertThat(config.getLazyLoadTriggerMethods()).isEqualTo((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx")));
assertThat(config.getLazyLoadTriggerMethods()).isEqualTo(new HashSet<>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx")));
assertThat(config.isSafeResultHandlerEnabled()).isFalse();
assertThat(config.getDefaultScriptingLanuageInstance()).isInstanceOf(RawLanguageDriver.class);
assertThat(config.isCallSettersOnNulls()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -356,10 +356,10 @@ public void shouldSkipForEachWhenCollectionIsEmpty() throws Exception {

@Test
public void shouldPerformStrictMatchOnForEachVariableSubstitution() throws Exception {
final Map<String, Object> param = new HashMap<String, Object>();
final Map<String, String> uuu = new HashMap<String, String>();
final Map<String, Object> param = new HashMap<>();
final Map<String, String> uuu = new HashMap<>();
uuu.put("u", "xyz");
List<Bean> uuuu = new ArrayList<Bean>();
List<Bean> uuuu = new ArrayList<>();
uuuu.add(new Bean("bean id"));
param.put("uuu", uuu);
param.put("uuuu", uuuu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
assertFalse(config.isSafeRowBoundsEnabled());
assertEquals(LocalCacheScope.SESSION, config.getLocalCacheScope());
assertEquals(JdbcType.OTHER, config.getJdbcTypeForNull());
assertEquals((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString")), config.getLazyLoadTriggerMethods());
assertEquals(new HashSet<>(Arrays.asList("equals", "clone", "hashCode", "toString")), config.getLazyLoadTriggerMethods());
assertTrue(config.isSafeResultHandlerEnabled());
assertTrue(config.getDefaultScriptingLanguageInstance() instanceof XMLLanguageDriver);
assertFalse(config.isCallSettersOnNulls());
Expand Down Expand Up @@ -114,7 +114,7 @@ public void shouldSuccessfullyLoadXMLConfigFitle() throws Exception {
assertTrue(config.isSafeRowBoundsEnabled());
assertEquals(LocalCacheScope.STATEMENT, config.getLocalCacheScope());
assertEquals(JdbcType.NULL, config.getJdbcTypeForNull());
assertEquals((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx")), config.getLazyLoadTriggerMethods());
assertEquals(new HashSet<>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx")), config.getLazyLoadTriggerMethods());
assertFalse(config.isSafeResultHandlerEnabled());
assertTrue(config.getDefaultScriptingLanguageInstance() instanceof RawLanguageDriver);
assertTrue(config.isCallSettersOnNulls());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/ibatis/cache/BaseCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void shouldDemonstrateEqualsAndHashCodeForVariousCacheTypes() {
assertEquals(cache.hashCode(), new LoggingCache(cache).hashCode());
assertEquals(cache.hashCode(), new ScheduledCache(cache).hashCode());

Set<Cache> caches = new HashSet<Cache>();
Set<Cache> caches = new HashSet<>();
caches.add(cache);
caches.add(new SynchronizedCache(cache));
caches.add(new SerializedCache(cache));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Context getInitialContext(Hashtable<?, ?> environment) throws NamingExcep
}

public static class MockContext extends InitialContext {
private static Map<String,Object> bindings = new HashMap<String,Object>();
private static Map<String,Object> bindings = new HashMap<>();

public MockContext(boolean lazy) throws NamingException {
super(lazy);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/apache/ibatis/domain/jpetstore/Cart.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,8 +23,8 @@ public class Cart implements Serializable {

private static final long serialVersionUID = 1L;

private final Map<String, CartItem> itemMap = Collections.synchronizedMap(new HashMap<String, CartItem>());
private final List<CartItem> itemList = new ArrayList<CartItem>();
private final Map<String, CartItem> itemMap = Collections.synchronizedMap(new HashMap<>());
private final List<CartItem> itemList = new ArrayList<>();

public Iterator<CartItem> getCartItems() {
return itemList.iterator();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/apache/ibatis/domain/jpetstore/Order.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,7 +52,7 @@ public class Order implements Serializable {
private String cardType;
private String locale;
private String status;
private List<LineItem> lineItems = new ArrayList<LineItem>();
private List<LineItem> lineItems = new ArrayList<>();

public int getOrderId() {
return orderId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static MappedStatement prepareSelectAuthorViaOutParams(final Configuratio
add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
}
}).build())
.resultMaps(new ArrayList<ResultMap>())
.resultMaps(new ArrayList<>())
.cache(authorCache).build();
return ms;
}
Expand Down Expand Up @@ -319,7 +319,7 @@ public static MappedStatement createInsertAuthorWithIDof99MappedStatement(final
MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (id,username,password,email,bio) values(99,'someone','******','someone@apache.org',null)"), SqlCommandType.INSERT)
.statementType(StatementType.STATEMENT)
.parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
new ArrayList<ParameterMapping>()).build())
new ArrayList<>()).build())
.cache(authorCache)
.build();
return ms;
Expand All @@ -329,7 +329,7 @@ public static MappedStatement createSelectAuthorWithIDof99MappedStatement(final
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config,"SELECT * FROM author WHERE id = 99"), SqlCommandType.SELECT)
.statementType(StatementType.STATEMENT)
.parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>()).build())
.parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<>()).build())
.resultMaps(new ArrayList<ResultMap>() {
{
add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() {
Expand Down Expand Up @@ -638,7 +638,7 @@ public static MappedStatement prepareSelectPostWithBlogByAuthorMappedStatement(f

public static MappedStatement prepareInsertAuthorMappedStatementWithBeforeAutoKey(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
final ResultMap rm = new ResultMap.Builder(config, "keyResultMap", Integer.class, new ArrayList<ResultMapping>())
final ResultMap rm = new ResultMap.Builder(config, "keyResultMap", Integer.class, new ArrayList<>())
.build();

MappedStatement kms = new MappedStatement.Builder(config, "insertAuthor!selectKey", new StaticSqlSource(config,"SELECT 123456 as id FROM SYSIBM.SYSDUMMY1"), SqlCommandType.SELECT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,31 +43,31 @@ public CglibProxyTest() {
public void shouldCreateAProxyForAPartiallyLoadedBean() throws Exception {
ResultLoaderMap loader = new ResultLoaderMap();
loader.addLoader("id", null, null);
Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
Author author2 = (Author) deserialize(serialize((Serializable) proxy));
assertTrue(author2 instanceof Factory);
}

@Test
public void shouldFailCallingAnUnloadedProperty() throws Exception {
// yes, it must go in uppercase
HashMap<String, ResultLoaderMap.LoadPair> unloadedProperties = new HashMap<String, ResultLoaderMap.LoadPair>();
HashMap<String, ResultLoaderMap.LoadPair> unloadedProperties = new HashMap<>();
unloadedProperties.put("ID", null);
Author author2 = (Author) ((CglibProxyFactory)proxyFactory).createDeserializationProxy(author, unloadedProperties, new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Author author2 = (Author) ((CglibProxyFactory)proxyFactory).createDeserializationProxy(author, unloadedProperties, new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
Assertions.assertThrows(ExecutorException.class, () -> {
author2.getId();
});
}

@Test
public void shouldLetCallALoadedProperty() throws Exception {
Author author2 = (Author) ((CglibProxyFactory)proxyFactory).createDeserializationProxy(author, new HashMap<String, ResultLoaderMap.LoadPair>(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Author author2 = (Author) ((CglibProxyFactory)proxyFactory).createDeserializationProxy(author, new HashMap<>(), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
assertEquals(999, author2.getId());
}

@Test
public void shouldSerizalizeADeserlizaliedProxy() throws Exception {
Object proxy = ((CglibProxyFactory)proxyFactory).createDeserializationProxy(author, new HashMap<String, ResultLoaderMap.LoadPair>(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Object proxy = ((CglibProxyFactory)proxyFactory).createDeserializationProxy(author, new HashMap<>(), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
Author author2 = (Author) deserialize(serialize((Serializable) proxy));
assertEquals(author, author2);
assertFalse(author.getClass().equals(author2.getClass()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,31 +43,31 @@ public JavassistProxyTest() {
public void shouldCreateAProxyForAPartiallyLoadedBean() throws Exception {
ResultLoaderMap loader = new ResultLoaderMap();
loader.addLoader("id", null, null);
Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
Author author2 = (Author) deserialize(serialize((Serializable) proxy));
assertTrue(author2 instanceof Proxy);
}

@Test
public void shouldFailCallingAnUnloadedProperty() throws Exception {
// yes, it must go in uppercase
HashMap<String, ResultLoaderMap.LoadPair> unloadedProperties = new HashMap<String, ResultLoaderMap.LoadPair> ();
HashMap<String, ResultLoaderMap.LoadPair> unloadedProperties = new HashMap<> ();
unloadedProperties.put("ID", null);
Author author2 = (Author) ((JavassistProxyFactory)proxyFactory).createDeserializationProxy(author, unloadedProperties, new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Author author2 = (Author) ((JavassistProxyFactory)proxyFactory).createDeserializationProxy(author, unloadedProperties, new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
Assertions.assertThrows(ExecutorException.class, () -> {
author2.getId();
});
}

@Test
public void shouldLetCallALoadedProperty() throws Exception {
Author author2 = (Author) ((JavassistProxyFactory)proxyFactory).createDeserializationProxy(author, new HashMap<String, ResultLoaderMap.LoadPair>(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Author author2 = (Author) ((JavassistProxyFactory)proxyFactory).createDeserializationProxy(author, new HashMap<>(), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
assertEquals(999, author2.getId());
}

@Test
public void shouldSerizalizeADeserlizaliedProxy() throws Exception {
Object proxy = ((JavassistProxyFactory)proxyFactory).createDeserializationProxy(author, new HashMap<String, ResultLoaderMap.LoadPair> (), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Object proxy = ((JavassistProxyFactory)proxyFactory).createDeserializationProxy(author, new HashMap<> (), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
Author author2 = (Author) deserialize(serialize((Serializable) proxy));
assertEquals(author, author2);
assertFalse(author.getClass().equals(author2.getClass()));
Expand Down
Loading

0 comments on commit 090013d

Please sign in to comment.