Skip to content

Commit

Permalink
= cold cleanup
Browse files Browse the repository at this point in the history
  * using lambda if possible (we are already building in Java8)
  * using diamond when new generic instance
  * remove used improt
  • Loading branch information
zavakid committed Sep 17, 2020
1 parent df60eda commit e765887
Show file tree
Hide file tree
Showing 133 changed files with 985 additions and 1,553 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class Threads {
pool,
0L,
TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<Runnable>(pool * 20),
new ArrayBlockingQueue<>(pool * 20),
DaemonThreadFactory.daemonThreadFactory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Pager<T> implements Serializable {
private static final long serialVersionUID = -986577815091763517L;

private Long count = 0L;
private List<T> items = new ArrayList<T>();
private List<T> items = new ArrayList<>();
private Integer page = 1;
private Integer size = 20;
private Long offset = 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static <T> T bindYmlToObj(String prefix, String content, Class<T> clazz,
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(propertySource);

PropertiesConfigurationFactory<Object> factory = new PropertiesConfigurationFactory<Object>(target);
PropertiesConfigurationFactory<Object> factory = new PropertiesConfigurationFactory<>(target);
factory.setPropertySources(propertySources);
factory.setIgnoreInvalidFields(true);
factory.setIgnoreUnknownFields(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected DefaultPropertyNamePatternsMatcher(char[] delimiters, String... names)
}

protected DefaultPropertyNamePatternsMatcher(char[] delimiters, boolean ignoreCase, String... names){
this(delimiters, ignoreCase, new HashSet<String>(Arrays.asList(names)));
this(delimiters, ignoreCase, new HashSet<>(Arrays.asList(names)));
}

DefaultPropertyNamePatternsMatcher(char[] delimiters, boolean ignoreCase, Set<String> names){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private Iterable<String> getRelaxedTargetNames() {
}

private Set<String> getNames(Iterable<String> prefixes) {
Set<String> names = new LinkedHashSet<String>();
Set<String> names = new LinkedHashSet<>();
if (this.target != null) {
PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(this.target.getClass());
for (PropertyDescriptor descriptor : descriptors) {
Expand Down Expand Up @@ -318,7 +318,7 @@ private PropertyNamePatternsMatcher getPropertyNamePatternsMatcher(Set<String> n
// We can filter properties to those starting with the target name, but
// we can't do a complete filter since we need to trigger the
// unknown fields check
Set<String> relaxedNames = new HashSet<String>();
Set<String> relaxedNames = new HashSet<>();
for (String relaxedTargetName : relaxedTargetNames) {
relaxedNames.add(relaxedTargetName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,9 @@
*/
interface PropertyNamePatternsMatcher {

PropertyNamePatternsMatcher ALL = new PropertyNamePatternsMatcher() {
PropertyNamePatternsMatcher ALL = propertyName -> true;

@Override
public boolean matches(String propertyName) {
return true;
}

};

PropertyNamePatternsMatcher NONE = new PropertyNamePatternsMatcher() {

@Override
public boolean matches(String propertyName) {
return false;
}

};
PropertyNamePatternsMatcher NONE = propertyName -> false;

/**
* Return {@code true} of the property name matches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class PropertySourcesPropertyValues implements PropertyValues {

private final PropertyNamePatternsMatcher includes;

private final Map<String, PropertyValue> propertyValues = new LinkedHashMap<String, PropertyValue>();
private final Map<String, PropertyValue> propertyValues = new LinkedHashMap<>();

private final ConcurrentHashMap<String, PropertySource<?>> collectionOwners = new ConcurrentHashMap<String, PropertySource<?>>();
private final ConcurrentHashMap<String, PropertySource<?>> collectionOwners = new ConcurrentHashMap<>();

private final boolean resolvePlaceholders;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class RelaxedDataBinder extends DataBinder {
private static final Set<Class<?>> EXCLUDED_EDITORS;

static {
Set<Class<?>> excluded = new HashSet<Class<?>>();
Set<Class<?>> excluded = new HashSet<>();
excluded.add(FileEditor.class);
EXCLUDED_EDITORS = Collections.unmodifiableSet(excluded);
}
Expand All @@ -43,7 +43,7 @@ public class RelaxedDataBinder extends DataBinder {

private boolean ignoreNestedProperties;

private MultiValueMap<String, String> nameAliases = new LinkedMultiValueMap<String, String>();
private MultiValueMap<String, String> nameAliases = new LinkedMultiValueMap<>();

/**
* Create a new {@link RelaxedDataBinder} instance.
Expand Down Expand Up @@ -89,7 +89,7 @@ public void setIgnoreNestedProperties(boolean ignoreNestedProperties) {
* @param aliases a map of property name to aliases
*/
public void setNameAliases(Map<String, List<String>> aliases) {
this.nameAliases = new LinkedMultiValueMap<String, String>(aliases);
this.nameAliases = new LinkedMultiValueMap<>(aliases);
}

/**
Expand Down Expand Up @@ -129,8 +129,8 @@ private MutablePropertyValues modifyProperties(MutablePropertyValues propertyVal
BeanWrapper wrapper = new BeanWrapperImpl(target);
wrapper.setConversionService(new RelaxedConversionService(getConversionService()));
wrapper.setAutoGrowNestedPaths(true);
List<PropertyValue> sortedValues = new ArrayList<PropertyValue>();
Set<String> modifiedNames = new HashSet<String>();
List<PropertyValue> sortedValues = new ArrayList<>();
Set<String> modifiedNames = new HashSet<>();
List<String> sortedNames = getSortedPropertyNames(propertyValues);
for (String name : sortedNames) {
PropertyValue propertyValue = propertyValues.getPropertyValue(name);
Expand All @@ -143,7 +143,7 @@ private MutablePropertyValues modifyProperties(MutablePropertyValues propertyVal
}

private List<String> getSortedPropertyNames(MutablePropertyValues propertyValues) {
List<String> names = new LinkedList<String>();
List<String> names = new LinkedList<>();
for (PropertyValue propertyValue : propertyValues.getPropertyValueList()) {
names.add(propertyValue.getName());
}
Expand All @@ -161,7 +161,7 @@ private List<String> getSortedPropertyNames(MutablePropertyValues propertyValues
* @param names the names to sort
*/
private void sortPropertyNames(List<String> names) {
for (String name : new ArrayList<String>(names)) {
for (String name : new ArrayList<>(names)) {
int propertyIndex = names.indexOf(name);
RelaxedDataBinder.BeanPath path = new RelaxedDataBinder.BeanPath(name);
for (String prefix : path.prefixes()) {
Expand Down Expand Up @@ -319,7 +319,7 @@ private void extendCollectionIfNecessary(BeanWrapper wrapper, RelaxedDataBinder.
}
Object extend = new LinkedHashMap<String, Object>();
if (!elementDescriptor.isMap() && path.isArrayIndex(index)) {
extend = new ArrayList<Object>();
extend = new ArrayList<>();
}
wrapper.setPropertyValue(path.prefix(index + 1), extend);
}
Expand Down Expand Up @@ -347,7 +347,7 @@ private void extendMapIfNecessary(BeanWrapper wrapper, RelaxedDataBinder.BeanPat
}
Object extend = new LinkedHashMap<String, Object>();
if (descriptor.isCollection()) {
extend = new ArrayList<Object>();
extend = new ArrayList<>();
}
if (descriptor.getType().equals(Object.class) && path.isLastNode(index)) {
extend = BLANK;
Expand Down Expand Up @@ -411,7 +411,7 @@ private Iterable<String> getNameAndAliases(String name) {
if (aliases == null) {
return Collections.singleton(name);
}
List<String> nameAndAliases = new ArrayList<String>(aliases.size() + 1);
List<String> nameAndAliases = new ArrayList<>(aliases.size() + 1);
nameAndAliases.add(name);
nameAndAliases.addAll(aliases);
return nameAndAliases;
Expand Down Expand Up @@ -473,7 +473,7 @@ private static class BeanPath {
}

public List<String> prefixes() {
List<String> prefixes = new ArrayList<String>();
List<String> prefixes = new ArrayList<>();
for (int index = 1; index < this.nodes.size(); index++) {
prefixes.add(prefix(index));
}
Expand All @@ -485,7 +485,7 @@ public boolean isLastNode(int index) {
}

private List<PathNode> splitPath(String path) {
List<PathNode> nodes = new ArrayList<PathNode>();
List<PathNode> nodes = new ArrayList<>();
String current = extractIndexedPaths(path, nodes);
for (String name : StringUtils.delimitedListToStringArray(current, ".")) {
if (StringUtils.hasText(name)) {
Expand Down Expand Up @@ -518,7 +518,7 @@ private String extractIndexedPaths(String path, List<PathNode> nodes) {
}

public void collapseKeys(int index) {
List<PathNode> revised = new ArrayList<PathNode>();
List<PathNode> revised = new ArrayList<>();
for (int i = 0; i < index; i++) {
revised.add(this.nodes.get(i));
}
Expand Down Expand Up @@ -668,7 +668,7 @@ private static class RelaxedBeanWrapper extends BeanWrapperImpl {
private static final Set<String> BENIGN_PROPERTY_SOURCE_NAMES;

static {
Set<String> names = new HashSet<String>();
Set<String> names = new HashSet<>();
names.add(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
names.add(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
BENIGN_PROPERTY_SOURCE_NAMES = Collections.unmodifiableSet(names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class RelaxedNames implements Iterable<String> {

private final String name;

private final Set<String> values = new LinkedHashSet<String>();
private final Set<String> values = new LinkedHashSet<>();

/**
* Create a new {@link RelaxedNames} instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class CompositePropertySource extends EnumerablePropertySource<Object> {

private final Set<PropertySource<?>> propertySources = new LinkedHashSet<PropertySource<?>>();
private final Set<PropertySource<?>> propertySources = new LinkedHashSet<>();

/**
* Create a new {@code CompositePropertySource}.
Expand Down Expand Up @@ -56,7 +56,7 @@ public boolean containsProperty(String name) {

@Override
public String[] getPropertyNames() {
Set<String> names = new LinkedHashSet<String>();
Set<String> names = new LinkedHashSet<>();
for (PropertySource<?> propertySource : this.propertySources) {
if (!(propertySource instanceof EnumerablePropertySource)) {
throw new IllegalStateException(
Expand All @@ -83,7 +83,7 @@ public void addPropertySource(PropertySource<?> propertySource) {
* @since 4.1
*/
public void addFirstPropertySource(PropertySource<?> propertySource) {
List<PropertySource<?>> existing = new ArrayList<PropertySource<?>>(this.propertySources);
List<PropertySource<?>> existing = new ArrayList<>(this.propertySources);
this.propertySources.clear();
this.propertySources.add(propertySource);
this.propertySources.addAll(existing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MutablePropertySources implements PropertySources {

private final Log logger;

private final List<PropertySource<?>> propertySourceList = new CopyOnWriteArrayList<PropertySource<?>>();
private final List<PropertySource<?>> propertySourceList = new CopyOnWriteArrayList<>();

/**
* Create a new {@link MutablePropertySources}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public SpringProfileDocumentMatcher(String... profiles){
}

public void addActiveProfiles(String... profiles) {
LinkedHashSet<String> set = new LinkedHashSet<String>(Arrays.asList(this.activeProfiles));
LinkedHashSet<String> set = new LinkedHashSet<>(Arrays.asList(this.activeProfiles));
Collections.addAll(set, profiles);
this.activeProfiles = set.toArray(new String[set.size()]);
}
Expand Down Expand Up @@ -67,14 +67,14 @@ private List<String> extractSpringProfiles(Properties properties) {

private ProfilesMatcher getProfilesMatcher() {
return (this.activeProfiles.length != 0 ? new ActiveProfilesMatcher(
new HashSet<String>(Arrays.asList(this.activeProfiles))) : new EmptyProfilesMatcher());
new HashSet<>(Arrays.asList(this.activeProfiles))) : new EmptyProfilesMatcher());
}

private Set<String> extractProfiles(List<String> profiles, ProfileType type) {
if (CollectionUtils.isEmpty(profiles)) {
return null;
}
Set<String> extractedProfiles = new HashSet<String>();
Set<String> extractedProfiles = new HashSet<>();
for (String candidate : profiles) {
ProfileType candidateType = ProfileType.POSITIVE;
if (candidate.startsWith("!")) {
Expand Down Expand Up @@ -167,7 +167,7 @@ public YamlProcessor.MatchStatus doMatches(Set<String> springProfiles) {
*/
static class SpringProperties {

private List<String> profiles = new ArrayList<String>();
private List<String> profiles = new ArrayList<>();

public List<String> getProfiles() {
return this.profiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void handleProcessError(Resource resource, IOException ex) {
@SuppressWarnings("unchecked")
private Map<String, Object> asMap(Object object) {
// YAML can have numbers as keys
Map<String, Object> result = new LinkedHashMap<String, Object>();
Map<String, Object> result = new LinkedHashMap<>();
if (!(object instanceof Map)) {
// A document can be a text literal
result.put("document", object);
Expand Down Expand Up @@ -249,7 +249,7 @@ public String getProperty(String key) {
* @since 4.1.3
*/
protected final Map<String, Object> getFlattenedMap(Map<String, Object> source) {
Map<String, Object> result = new LinkedHashMap<String, Object>();
Map<String, Object> result = new LinkedHashMap<>();
buildFlattenedMap(result, source, null);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,8 @@ public void addImplicitResolver(Tag tag, Pattern regexp, String first) {
}

public Map<String, Object> process() {
final Map<String, Object> result = new LinkedHashMap<String, Object>();
process(new MatchCallback() {

@Override
public void process(Properties properties, Map<String, Object> map) {
result.putAll(getFlattenedMap(map));
}
});
final Map<String, Object> result = new LinkedHashMap<>();
process((properties, map) -> result.putAll(getFlattenedMap(map)));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private Map<String, Class<?>> loadExtensionClasses() {
}
}

Map<String, Class<?>> extensionClasses = new HashMap<String, Class<?>>();
Map<String, Class<?>> extensionClasses = new HashMap<>();

// 1. plugin folder,customized extension classLoader (jar_dir/plugin)
String dir = File.separator + this.getJarDirectoryPath() + File.separator + "plugin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import com.alibaba.otter.canal.connector.core.consumer.CommonMessage;
import com.alibaba.otter.canal.protocol.CanalEntry;
import com.alibaba.otter.canal.protocol.FlatMessage;
import com.alibaba.otter.canal.protocol.Message;

/**
Expand All @@ -20,7 +19,7 @@ public static List<Dml> parse4Dml(String destination, String groupId, Message me
return null;
}
List<CanalEntry.Entry> entries = message.getEntries();
List<Dml> dmls = new ArrayList<Dml>(entries.size());
List<Dml> dmls = new ArrayList<>(entries.size());
for (CanalEntry.Entry entry : entries) {
if (entry.getEntryType() == CanalEntry.EntryType.TRANSACTIONBEGIN
|| entry.getEntryType() == CanalEntry.EntryType.TRANSACTIONEND) {
Expand Down Expand Up @@ -136,7 +135,7 @@ public static List<Dml> flatMessage2Dml(String destination, String groupId, List
if (commonMessages == null) {
return new ArrayList<>();
}
List<Dml> dmls = new ArrayList<Dml>(commonMessages.size());
List<Dml> dmls = new ArrayList<>(commonMessages.size());
for (CommonMessage commonMessage : commonMessages) {
Dml dml = flatMessage2Dml(destination, groupId, commonMessage);
if (dml != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
package com.alibaba.otter.canal.client.adapter.support;

import static org.mockito.AdditionalMatchers.or;
import static org.mockito.Matchers.isA;
import static org.mockito.Matchers.isNull;
import static org.powermock.api.mockito.PowerMockito.mockStatic;

import com.alibaba.otter.canal.client.adapter.support.JdbcTypeUtil;
import com.alibaba.otter.canal.client.adapter.support.Util;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.lang.reflect.Array;

@RunWith(PowerMockRunner.class)
public class JdbcTypeUtilTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import static org.mockito.AdditionalMatchers.or;
import static org.mockito.Matchers.isA;
import static org.mockito.Matchers.isNull;
import static org.powermock.api.mockito.PowerMockito.mockStatic;

import com.alibaba.otter.canal.client.adapter.support.Util;
import com.diffblue.deeptestutils.mock.DTUMemberMatcher;
import org.apache.commons.lang.StringUtils;
import org.junit.Assert;
Expand Down
Loading

0 comments on commit e765887

Please sign in to comment.