Use diamond operator
Issue: SWF-1718
This commit is contained in:
@@ -55,7 +55,7 @@ public abstract class AbstractCachingMapDecorator<K, V> implements Map<K, V>, Se
|
||||
* @param weak whether to use weak references for keys and values
|
||||
*/
|
||||
public AbstractCachingMapDecorator(boolean weak) {
|
||||
Map<K, Object> internalMap = (weak ? new WeakHashMap<K, Object>() : new HashMap<K, Object>());
|
||||
Map<K, Object> internalMap = (weak ? new WeakHashMap<>() : new HashMap<>());
|
||||
this.targetMap = Collections.synchronizedMap(internalMap);
|
||||
this.synchronize = true;
|
||||
this.weak = weak;
|
||||
@@ -68,7 +68,7 @@ public abstract class AbstractCachingMapDecorator<K, V> implements Map<K, V>, Se
|
||||
* @param size the initial cache size
|
||||
*/
|
||||
public AbstractCachingMapDecorator(boolean weak, int size) {
|
||||
Map<K, Object> internalMap = weak ? new WeakHashMap<K, Object> (size) : new HashMap<K, Object>(size);
|
||||
Map<K, Object> internalMap = weak ? new WeakHashMap<K, Object> (size) : new HashMap<>(size);
|
||||
this.targetMap = Collections.synchronizedMap(internalMap);
|
||||
this.synchronize = true;
|
||||
this.weak = weak;
|
||||
@@ -161,11 +161,11 @@ public abstract class AbstractCachingMapDecorator<K, V> implements Map<K, V>, Se
|
||||
public Set<K> keySet() {
|
||||
if (this.synchronize) {
|
||||
synchronized (this.targetMap) {
|
||||
return new LinkedHashSet<K>(this.targetMap.keySet());
|
||||
return new LinkedHashSet<>(this.targetMap.keySet());
|
||||
}
|
||||
}
|
||||
else {
|
||||
return new LinkedHashSet<K>(this.targetMap.keySet());
|
||||
return new LinkedHashSet<>(this.targetMap.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public abstract class AbstractCachingMapDecorator<K, V> implements Map<K, V>, Se
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<V> valuesCopy() {
|
||||
LinkedList<V> values = new LinkedList<V>();
|
||||
LinkedList<V> values = new LinkedList<>();
|
||||
for (Iterator<Object> it = this.targetMap.values().iterator(); it.hasNext();) {
|
||||
Object value = it.next();
|
||||
if (value instanceof Reference) {
|
||||
@@ -210,7 +210,7 @@ public abstract class AbstractCachingMapDecorator<K, V> implements Map<K, V>, Se
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Set<Map.Entry<K, V>> entryCopy() {
|
||||
Map<K,V> entries = new LinkedHashMap<K, V>();
|
||||
Map<K,V> entries = new LinkedHashMap<>();
|
||||
for (Iterator<Entry<K, Object>> it = this.targetMap.entrySet().iterator(); it.hasNext();) {
|
||||
Entry<K, Object> entry = it.next();
|
||||
Object value = entry.getValue();
|
||||
@@ -238,7 +238,7 @@ public abstract class AbstractCachingMapDecorator<K, V> implements Map<K, V>, Se
|
||||
newValue = NULL_VALUE;
|
||||
}
|
||||
else if (useWeakValue(key, value)) {
|
||||
newValue = new WeakReference<Object>(newValue);
|
||||
newValue = new WeakReference<>(newValue);
|
||||
}
|
||||
return unwrapReturnValue(this.targetMap.put(key, newValue));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class GenericConversionService implements ConversionService {
|
||||
* A map of custom converters. Custom converters are assigned a unique identifier that can be used to lookup the
|
||||
* converter. This allows multiple converters for the same source->target class to be registered.
|
||||
*/
|
||||
private final Map<String, Converter> customConverters = new HashMap<String, Converter>();
|
||||
private final Map<String, Converter> customConverters = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Indexes classes by well-known aliases.
|
||||
|
||||
@@ -190,7 +190,7 @@ public class ELExpressionParser implements ExpressionParser {
|
||||
}
|
||||
|
||||
private static class VariableMapperImpl extends VariableMapper {
|
||||
private Map<String, ValueExpression> variables = new HashMap<String, ValueExpression>();
|
||||
private Map<String, ValueExpression> variables = new HashMap<>();
|
||||
|
||||
public ValueExpression resolveVariable(String name) {
|
||||
return variables.get(name);
|
||||
|
||||
@@ -155,7 +155,7 @@ public class SpringELExpression implements Expression {
|
||||
if (expressionVariables == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, Object> variableValues = new HashMap<String, Object>(expressionVariables.size());
|
||||
Map<String, Object> variableValues = new HashMap<>(expressionVariables.size());
|
||||
for (Map.Entry<String, Expression> var : expressionVariables.entrySet()) {
|
||||
variableValues.put(var.getKey(), var.getValue().getValue(rootObject));
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SpringELExpressionParser implements ExpressionParser {
|
||||
|
||||
private final ConversionService conversionService;
|
||||
|
||||
private final List<PropertyAccessor> propertyAccessors = new ArrayList<PropertyAccessor>();
|
||||
private final List<PropertyAccessor> propertyAccessors = new ArrayList<>();
|
||||
|
||||
public SpringELExpressionParser(SpelExpressionParser expressionParser) {
|
||||
this(expressionParser, new DefaultConversionService());
|
||||
@@ -116,7 +116,7 @@ public class SpringELExpressionParser implements ExpressionParser {
|
||||
if (expressionVars == null || expressionVars.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Expression> result = new HashMap<String, Expression>(expressionVars.length);
|
||||
Map<String, Expression> result = new HashMap<>(expressionVars.length);
|
||||
for (ExpressionVariable var : expressionVars) {
|
||||
result.put(var.getName(), parseExpression(var.getValueExpression(), var.getParserContext()));
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
|
||||
* @throws ParserException when the expressions cannot be parsed
|
||||
*/
|
||||
private Expression[] parseExpressions(String expressionString, ParserContext context) throws ParserException {
|
||||
List<Expression> expressions = new LinkedList<Expression>();
|
||||
List<Expression> expressions = new LinkedList<>();
|
||||
int startIdx = 0;
|
||||
while (startIdx < expressionString.length()) {
|
||||
int prefixIndex = expressionString.indexOf(getExpressionPrefix(), startIdx);
|
||||
@@ -227,7 +227,7 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
|
||||
if (variables == null || variables.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Expression> variableExpressions = new HashMap<String, Expression>(variables.length, 1);
|
||||
Map<String, Expression> variableExpressions = new HashMap<>(variables.length, 1);
|
||||
for (ExpressionVariable var : variables) {
|
||||
variableExpressions.put(var.getName(), parseExpression(var.getValueExpression(), var.getParserContext()));
|
||||
}
|
||||
|
||||
@@ -114,6 +114,6 @@ public class FluentParserContext implements ParserContext {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
expressionVariables = new ArrayList<ExpressionVariable>();
|
||||
expressionVariables = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class DefaultMapper implements Mapper {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(DefaultMapper.class);
|
||||
|
||||
private List<DefaultMapping> mappings = new ArrayList<DefaultMapping>();
|
||||
private List<DefaultMapping> mappings = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Add a mapping to this mapper.
|
||||
|
||||
@@ -50,7 +50,7 @@ public class DefaultMappingContext {
|
||||
public DefaultMappingContext(Object source, Object target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.mappingResults = new ArrayList<MappingResult>();
|
||||
this.mappingResults = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,7 +69,7 @@ public class DefaultMappingResults implements MappingResults {
|
||||
}
|
||||
|
||||
public List<MappingResult> getErrorResults() {
|
||||
List<MappingResult> errorResults = new ArrayList<MappingResult>();
|
||||
List<MappingResult> errorResults = new ArrayList<>();
|
||||
for (MappingResult result : mappingResults) {
|
||||
if (result.isError()) {
|
||||
errorResults.add(result);
|
||||
@@ -79,7 +79,7 @@ public class DefaultMappingResults implements MappingResults {
|
||||
}
|
||||
|
||||
public List<MappingResult> getResults(MappingResultsCriteria criteria) {
|
||||
List<MappingResult> results = new ArrayList<MappingResult>();
|
||||
List<MappingResult> results = new ArrayList<>();
|
||||
for (MappingResult result : mappingResults) {
|
||||
if (criteria.test(result)) {
|
||||
results.add(result);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class DefaultMessageContext implements StateManageableMessageContext {
|
||||
new LinkedHashMap<Object, List<Message>>()) {
|
||||
|
||||
protected List<Message> create(Object source) {
|
||||
return new ArrayList<Message>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -75,7 +75,7 @@ public class DefaultMessageContext implements StateManageableMessageContext {
|
||||
// implementing message context
|
||||
|
||||
public Message[] getAllMessages() {
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
List<Message> messages = new ArrayList<>();
|
||||
for (List<Message> list : sourceMessages.values()) {
|
||||
messages.addAll(list);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class DefaultMessageContext implements StateManageableMessageContext {
|
||||
}
|
||||
|
||||
public Message[] getMessagesByCriteria(MessageCriteria criteria) {
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
List<Message> messages = new ArrayList<>();
|
||||
for (List<Message> sourceMessages : this.sourceMessages.values()) {
|
||||
for (Message message : sourceMessages) {
|
||||
if (criteria.test(message)) {
|
||||
|
||||
@@ -44,11 +44,11 @@ public class MessageBuilder {
|
||||
|
||||
private Object source;
|
||||
|
||||
private Set<String> codes = new LinkedHashSet<String>();
|
||||
private Set<String> codes = new LinkedHashSet<>();
|
||||
|
||||
private Severity severity;
|
||||
|
||||
private List<Object> args = new ArrayList<Object>();
|
||||
private List<Object> args = new ArrayList<>();
|
||||
|
||||
private String defaultText;
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ public class MessageContextErrors extends AbstractErrors {
|
||||
if (messages.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ObjectError> errors = new ArrayList<ObjectError>(messages.length);
|
||||
List<ObjectError> errors = new ArrayList<>(messages.length);
|
||||
for (Message message : messages) {
|
||||
errors.add(new ObjectError(objectName, message.getText()));
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public class MessageContextErrors extends AbstractErrors {
|
||||
if (messages.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<FieldError> errors = new ArrayList<FieldError>(messages.length);
|
||||
List<FieldError> errors = new ArrayList<>(messages.length);
|
||||
for (Message message : messages) {
|
||||
errors.add(new FieldError(objectName, (String) message.getSource(), message.getText()));
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class Parameters {
|
||||
* @param size the size
|
||||
*/
|
||||
public Parameters(int size) {
|
||||
this.parameters = new ArrayList<Parameter>(size);
|
||||
this.parameters = new ArrayList<>(size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ public class Parameters {
|
||||
* @param parameter the single parameter
|
||||
*/
|
||||
public Parameters(Parameter parameter) {
|
||||
this.parameters = new ArrayList<Parameter>(1);
|
||||
this.parameters = new ArrayList<>(1);
|
||||
add(parameter);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Parameters {
|
||||
* @param parameters the parameters
|
||||
*/
|
||||
public Parameters(Parameter... parameters) {
|
||||
this.parameters = new ArrayList<Parameter>(parameters.length);
|
||||
this.parameters = new ArrayList<>(parameters.length);
|
||||
addAll(parameters);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ public class MapAccessorTests extends TestCase {
|
||||
private MapAccessor<String, Object> accessor;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("string", "hello");
|
||||
map.put("integer", 9);
|
||||
map.put("null", null);
|
||||
this.accessor = new MapAccessor<String, Object>(map);
|
||||
this.accessor = new MapAccessor<>(map);
|
||||
}
|
||||
|
||||
public void testAccessNullAttribute() {
|
||||
|
||||
@@ -27,8 +27,8 @@ import junit.framework.TestCase;
|
||||
*/
|
||||
public class SharedMapDecoratorTests extends TestCase {
|
||||
|
||||
private SharedMapDecorator<String, String> map = new SharedMapDecorator<String, String>(
|
||||
new HashMap<String, String>());
|
||||
private SharedMapDecorator<String, String> map = new SharedMapDecorator<>(
|
||||
new HashMap<>());
|
||||
|
||||
public void testGetPutRemove() {
|
||||
assertTrue(map.size() == 0);
|
||||
@@ -48,7 +48,7 @@ public class SharedMapDecoratorTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testPutAll() {
|
||||
Map<String, String> all = new HashMap<String, String>();
|
||||
Map<String, String> all = new HashMap<>();
|
||||
all.put("foo", "bar");
|
||||
all.put("bar", "baz");
|
||||
map.putAll(all);
|
||||
|
||||
@@ -28,7 +28,7 @@ import junit.framework.TestCase;
|
||||
*/
|
||||
public class StringKeyedMapAdapterTests extends TestCase {
|
||||
|
||||
private Map<String, String> contents = new HashMap<String, String>();
|
||||
private Map<String, String> contents = new HashMap<>();
|
||||
|
||||
private StringKeyedMapAdapter<String> map = new StringKeyedMapAdapter<String>() {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class StringKeyedMapAdapterTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testPutAll() {
|
||||
Map<String, String> all = new HashMap<String, String>();
|
||||
Map<String, String> all = new HashMap<>();
|
||||
all.put("foo", "bar");
|
||||
all.put("bar", "baz");
|
||||
map.putAll(all);
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
|
||||
public void testConvertCompatibleTypes() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
List<Object> lst = new ArrayList<Object>();
|
||||
List<Object> lst = new ArrayList<>();
|
||||
assertSame(lst, service.getConversionExecutor(ArrayList.class, List.class).execute(lst));
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", List.class, Principal[].class);
|
||||
List<String> princyList = new ArrayList<String>();
|
||||
List<String> princyList = new ArrayList<>();
|
||||
princyList.add("princy1");
|
||||
princyList.add("princy2");
|
||||
Principal[] p = (Principal[]) executor.execute(princyList);
|
||||
@@ -272,7 +272,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
return "princy2";
|
||||
}
|
||||
};
|
||||
List<Principal> princyList = new ArrayList<Principal>();
|
||||
List<Principal> princyList = new ArrayList<>();
|
||||
princyList.add(princy1);
|
||||
princyList.add(princy2);
|
||||
String[] p = (String[]) executor.execute(princyList);
|
||||
@@ -373,7 +373,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", List.class, List.class);
|
||||
List<String> princyList = new ArrayList<String>();
|
||||
List<String> princyList = new ArrayList<>();
|
||||
princyList.add("princy1");
|
||||
princyList.add("princy2");
|
||||
List<Principal> list = (List<Principal>) executor.execute(princyList);
|
||||
@@ -396,7 +396,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
return "princy2";
|
||||
}
|
||||
};
|
||||
List<Principal> princyList = new ArrayList<Principal>();
|
||||
List<Principal> princyList = new ArrayList<>();
|
||||
princyList.add(princy1);
|
||||
princyList.add(princy2);
|
||||
List<String> list = (List<String>) executor.execute(princyList);
|
||||
@@ -408,7 +408,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", List.class, List.class);
|
||||
List<Integer> princyList = new ArrayList<Integer>();
|
||||
List<Integer> princyList = new ArrayList<>();
|
||||
princyList.add(1);
|
||||
try {
|
||||
executor.execute(princyList);
|
||||
@@ -456,7 +456,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
public void testListToArrayConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(Collection.class, String[].class);
|
||||
List<String> list = new ArrayList<String>();
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
@@ -470,7 +470,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
public void testSetToListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(Set.class, List.class);
|
||||
Set<String> set = new LinkedHashSet<String>();
|
||||
Set<String> set = new LinkedHashSet<>();
|
||||
set.add("1");
|
||||
set.add("2");
|
||||
set.add("3");
|
||||
@@ -599,7 +599,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
List<Principal> principals = new ArrayList<Principal>();
|
||||
List<Principal> principals = new ArrayList<>();
|
||||
StringTokenizer tokenizer = new StringTokenizer(string, ",");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
final String name = tokenizer.nextToken();
|
||||
|
||||
@@ -27,7 +27,7 @@ public class TestBean {
|
||||
|
||||
private Date date;
|
||||
|
||||
private List<Object> list = new ArrayList<Object>();
|
||||
private List<Object> list = new ArrayList<>();
|
||||
|
||||
public boolean isFlag() {
|
||||
return flag;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class MapAdaptableELResolverTests extends TestCase {
|
||||
}
|
||||
|
||||
private class TestMapAdaptable implements MapAdaptable<String, String> {
|
||||
private Map<String, String> map = new HashMap<String, String>();
|
||||
private Map<String, String> map = new HashMap<>();
|
||||
|
||||
public TestMapAdaptable() {
|
||||
map.put("bar", "bar");
|
||||
|
||||
@@ -23,7 +23,7 @@ public class TestBean {
|
||||
private String value = "foo";
|
||||
private int maximum = 2;
|
||||
private TestBean bean;
|
||||
private List<String> list = new ArrayList<String>();
|
||||
private List<String> list = new ArrayList<>();
|
||||
|
||||
public TestBean() {
|
||||
initList();
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DefaultMapperTests extends TestCase {
|
||||
DefaultMapping mapping1 = new DefaultMapping(parser.parseExpression("beep", null), parser.parseExpression(
|
||||
"beep", null));
|
||||
mapper.addMapping(mapping1);
|
||||
Map<String, String> bean1 = new HashMap<String, String>();
|
||||
Map<String, String> bean1 = new HashMap<>();
|
||||
bean1.put("beep", "en");
|
||||
TestBean2 bean2 = new TestBean2();
|
||||
MappingResults results = mapper.map(bean1, bean2);
|
||||
@@ -61,7 +61,7 @@ public class DefaultMapperTests extends TestCase {
|
||||
DefaultMapping mapping1 = new DefaultMapping(parser.parseExpression("boop", null), parser.parseExpression(
|
||||
"boop", null));
|
||||
mapper.addMapping(mapping1);
|
||||
Map<String, String> bean1 = new HashMap<String, String>();
|
||||
Map<String, String> bean1 = new HashMap<>();
|
||||
bean1.put("boop", "bogus");
|
||||
TestBean2 bean2 = new TestBean2();
|
||||
MappingResults results = mapper.map(bean1, bean2);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class MessageContextErrorsTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testAddAllErrors() {
|
||||
MapBindingResult result = new MapBindingResult(new HashMap<Object, Object>(), "object");
|
||||
MapBindingResult result = new MapBindingResult(new HashMap<>(), "object");
|
||||
result.reject("bar", new Object[] { "boop" }, null);
|
||||
result.rejectValue("field", "bar", new Object[] { "boop" }, null);
|
||||
errors.addAllErrors(result);
|
||||
|
||||
Reference in New Issue
Block a user