Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Oct 10, 2018
1 parent 6bf9cac commit 0d5167c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ public Strategy getStrategy(MethodInterceptorContext context) {
@AllArgsConstructor
public static class CacheKey {

private Class target;
private Class<?> target;

private Method method;

@Override
public boolean equals(Object obj) {
if (!(obj instanceof CacheKey)) {
public boolean equals(Object targetObject) {
if (!(targetObject instanceof CacheKey)) {
return false;
}
CacheKey target = ((CacheKey) obj);
return target.target.getName().equals(this.target.getName())
&& target.method.getName().equals(method.getName())
&& target.method.getParameterCount() == method.getParameterCount();
CacheKey targetCacheKey = ((CacheKey) targetObject);
return targetCacheKey.target.isAssignableFrom(this.target)
&& targetCacheKey.method.getName().equals(method.getName())
&& targetCacheKey.method.getParameterCount() == method.getParameterCount();
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ public void testChangeSwitcher2() {
assertEquals(switcher.currentDataSourceId(), "test");
}

@SneakyThrows
public static void main(String[] args) {
Method method = Test2.class.getMethod("test");

System.out.println(method);
System.out.println(method.getDeclaringClass());
}

public class Test2 extends TestClass {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ static AtomikosDataSourceConfig convert(InDBDynamicDataSourceConfig entity) {
public int hashCode() {
return entity.hashCode();
}

@Override
public boolean equals(Object o) {
return o instanceof AtomikosDataSourceConfig && hashCode() == o.hashCode();
}
});
target.setId(entity.getId());
target.setName(entity.getName());
Expand Down

0 comments on commit 0d5167c

Please sign in to comment.