Code formatted according to checkstyle rules

pull/1923/head
Nikita Koksharov 6 years ago
parent 6b916fda98
commit a5bb755deb

@ -159,26 +159,35 @@
<!-- Checks for common coding problems --> <!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html --> <!-- See http://checkstyle.sf.net/config_coding.html -->
<!--module name="AvoidInlineConditionals"/--> <module name="ArrayTrailingComma"/>
<module name="AvoidInlineConditionals"/>
<module name="CovariantEquals"/>
<!-- MY FAVOURITE --> <!-- MY FAVOURITE -->
<module name="EmptyStatement"/> <module name="EmptyStatement"/>
<module name="EqualsHashCode"/> <module name="EqualsHashCode"/>
<module name="EqualsAvoidNull"/>
<!--module name="HiddenField"/--> <!--module name="HiddenField"/-->
<module name="IllegalInstantiation"/> <module name="IllegalInstantiation"/>
<module name="IllegalThrows"/>
<module name="InnerAssignment"/> <module name="InnerAssignment"/>
<module name="MultipleVariableDeclarations"/>
<!--module name="MagicNumber"/--> <!--module name="MagicNumber"/-->
<module name="SimplifyBooleanExpression"/> <module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/> <module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/> <module name="StringLiteralEquality"/>
<module name="NestedForDepth">
<property name="max" value="2"/>
</module>
<module name="NestedIfDepth"> <module name="NestedIfDepth">
<property name="max" value="3"/> <property name="max" value="3"/>
</module> </module>
<module name="NestedTryDepth"/> <module name="NestedTryDepth"/>
<module name="SuperClone"/> <module name="NoClone"/>
<module name="NoFinalizer"/>
<module name="OneStatementPerLine"/>
<module name="IllegalCatch"> <module name="IllegalCatch">
<property name="illegalClassNames" value=" java.lang.Throwable, java.lang.RuntimeException"/> <property name="illegalClassNames" value=" java.lang.Throwable, java.lang.RuntimeException"/>
</module> </module>
<!--module name="IllegalThrows"/-->
<module name="FallThrough"/> <module name="FallThrough"/>
<module name="UnnecessaryParentheses"/> <module name="UnnecessaryParentheses"/>
<!--module name="FinalLocalVariable"/--> <!--module name="FinalLocalVariable"/-->

@ -372,6 +372,7 @@
**/org/redisson/eviction/**/*.java, **/org/redisson/eviction/**/*.java,
**/org/redisson/executor/**/*.java, **/org/redisson/executor/**/*.java,
**/org/redisson/jcache/**/*.java, **/org/redisson/jcache/**/*.java,
**/org/redisson/liveobject/**/*.java,
</includes> </includes>
<consoleOutput>true</consoleOutput> <consoleOutput>true</consoleOutput>
<enableRSS>false</enableRSS> <enableRSS>false</enableRSS>

@ -206,13 +206,13 @@ public class CommandPubSubDecoder extends CommandDecoder {
return null; return null;
} }
return commandData.getCommand().getReplayMultiDecoder(); return commandData.getCommand().getReplayMultiDecoder();
} else if (command.equals("message")) { } else if ("message".equals(command)) {
byte[] channelName = (byte[]) parts.get(1); byte[] channelName = (byte[]) parts.get(1);
return entries.get(new ChannelName(channelName)).getDecoder(); return entries.get(new ChannelName(channelName)).getDecoder();
} else if (command.equals("pmessage")) { } else if ("pmessage".equals(command)) {
byte[] patternName = (byte[]) parts.get(1); byte[] patternName = (byte[]) parts.get(1);
return entries.get(new ChannelName(patternName)).getDecoder(); return entries.get(new ChannelName(patternName)).getDecoder();
} else if (command.equals("pong")) { } else if ("pong".equals(command)) {
return new ListObjectDecoder<Object>(0); return new ListObjectDecoder<Object>(0);
} }

@ -42,6 +42,7 @@ public class PubSubKey {
} }
@Override @Override
@SuppressWarnings("AvoidInlineConditionals")
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;

@ -145,9 +145,14 @@ public class RedisCommand<R> {
return outParamType; return outParamType;
} }
@Override
public String toString() { public String toString() {
return "(" + name + (subName != null ? " " + subName : "") + ")"; StringBuilder str = new StringBuilder();
str.append("(").append(name);
if (subName != null) {
str.append(" ").append(subName);
}
str.append(")");
return str.toString();
} }
} }

@ -41,6 +41,7 @@ public class ScoredEntry<V> {
} }
@Override @Override
@SuppressWarnings("AvoidInlineConditionals")
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;

@ -134,6 +134,7 @@ public class ClusterPartition {
} }
@Override @Override
@SuppressWarnings("AvoidInlineConditionals")
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;

@ -85,6 +85,7 @@ public class CompositeCodec implements Codec {
} }
@Override @Override
@SuppressWarnings("AvoidInlineConditionals")
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;

@ -119,6 +119,7 @@ public class MapCacheEventCodec implements Codec {
} }
@Override @Override
@SuppressWarnings("AvoidInlineConditionals")
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;

@ -394,9 +394,10 @@ public class CommandAsyncService implements CommandAsyncExecutor {
} }
public <V> RedisException convertException(RFuture<V> future) { public <V> RedisException convertException(RFuture<V> future) {
return future.cause() instanceof RedisException if (future.cause() instanceof RedisException) {
? (RedisException) future.cause() return (RedisException) future.cause();
: new RedisException("Unexpected exception while processing command", future.cause()); }
return new RedisException("Unexpected exception while processing command", future.cause());
} }
private NodeSource getNodeSource(String key) { private NodeSource getNodeSource(String key) {
@ -1112,12 +1113,13 @@ public class CommandAsyncService implements CommandAsyncExecutor {
} }
return o; return o;
} else if (o instanceof Set) { } else if (o instanceof Set) {
Set set, r = (Set) o; Set<Object> set = (Set<Object>) o;
Set<Object> r = (Set<Object>) o;
boolean useNewSet = o instanceof LinkedHashSet; boolean useNewSet = o instanceof LinkedHashSet;
try { try {
set = (Set) o.getClass().getConstructor().newInstance(); set = (Set<Object>) o.getClass().getConstructor().newInstance();
} catch (Exception exception) { } catch (Exception exception) {
set = new LinkedHashSet(); set = new LinkedHashSet<Object>();
} }
for (Object i : r) { for (Object i : r) {
Object ref = tryHandleReference0(i); Object ref = tryHandleReference0(i);
@ -1202,12 +1204,11 @@ public class CommandAsyncService implements CommandAsyncExecutor {
Map.Entry old = (Map.Entry) o; Map.Entry old = (Map.Entry) o;
Object key = tryHandleReference0(old.getKey()); Object key = tryHandleReference0(old.getKey());
Object value = tryHandleReference0(old.getValue()); Object value = tryHandleReference0(old.getValue());
return value != old.getValue() || key != old.getKey() if (value != old.getValue() || key != old.getKey()) {
? new AbstractMap.SimpleEntry(key, value) return new AbstractMap.SimpleEntry(key, value);
: o; }
} else {
return o;
} }
return o;
} }
private Object fromReference(Object res) { private Object fromReference(Object res) {

@ -82,6 +82,7 @@ public class RedisClientEntry implements ClusterNode {
} }
@Override @Override
@SuppressWarnings("AvoidInlineConditionals")
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;

@ -352,7 +352,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
slaveDown(ip, port); slaveDown(ip, port);
continue; continue;
} }
if (masterHost.equals("?") || !isUseSameMaster(ip, port, masterHost, masterPort)) { if ("?".equals(masterHost) || !isUseSameMaster(ip, port, masterHost, masterPort)) {
continue; continue;
} }

@ -52,7 +52,8 @@ import java.util.TreeSet;
*/ */
@SuppressWarnings({"EmptyStatement", "InnerAssignment", "ConstantName", @SuppressWarnings({"EmptyStatement", "InnerAssignment", "ConstantName",
"BooleanExpressionComplexity", "NestedIfDepth", "ParenPad", "BooleanExpressionComplexity", "NestedIfDepth", "ParenPad",
"MethodLength", "WhitespaceAfter", "SuperClone", "UnnecessaryParentheses"}) "MethodLength", "WhitespaceAfter", "NoClone", "UnnecessaryParentheses", "AvoidInlineConditionals",
"EqualsAvoidNull", "OneStatementPerLine"})
public final class CronExpression implements Serializable, Cloneable { public final class CronExpression implements Serializable, Cloneable {
private static final long serialVersionUID = 12423409423L; private static final long serialVersionUID = 12423409423L;

@ -88,7 +88,7 @@ public class AccessorInterceptor {
if (result != null && fieldType.isEnum()) { if (result != null && fieldType.isEnum()) {
if (result instanceof String) { if (result instanceof String) {
return Enum.valueOf((Class)fieldType, (String)result); return Enum.valueOf((Class) fieldType, (String) result);
} }
return result; return result;
} }
@ -139,7 +139,7 @@ public class AccessorInterceptor {
} }
if (arg instanceof RObject) { if (arg instanceof RObject) {
objectBuilder.store((RObject)arg, fieldName, liveMap); objectBuilder.store((RObject) arg, fieldName, liveMap);
return me; return me;
} }
@ -176,7 +176,10 @@ public class AccessorInterceptor {
private String getFieldName(Method method) { private String getFieldName(Method method) {
String name = method.getName(); String name = method.getName();
int i = name.startsWith("is") ? 3 : 4; int i = 4;
if (name.startsWith("is")) {
i = 3;
}
return name.substring(i - 1, i).toLowerCase() + name.substring(i); return name.substring(i - 1, i).toLowerCase() + name.substring(i);
} }

@ -69,18 +69,18 @@ import org.redisson.liveobject.resolver.NamingScheme;
*/ */
public class RedissonObjectBuilder { public class RedissonObjectBuilder {
private static final Map<Class<?>, Class<? extends RObject>> supportedClassMapping = new LinkedHashMap<Class<?>, Class<? extends RObject>>(); private static final Map<Class<?>, Class<? extends RObject>> SUPPORTED_CLASS_MAPPING = new LinkedHashMap<>();
static { static {
supportedClassMapping.put(SortedSet.class, RedissonSortedSet.class); SUPPORTED_CLASS_MAPPING.put(SortedSet.class, RedissonSortedSet.class);
supportedClassMapping.put(Set.class, RedissonSet.class); SUPPORTED_CLASS_MAPPING.put(Set.class, RedissonSet.class);
supportedClassMapping.put(ConcurrentMap.class, RedissonMap.class); SUPPORTED_CLASS_MAPPING.put(ConcurrentMap.class, RedissonMap.class);
supportedClassMapping.put(Map.class, RedissonMap.class); SUPPORTED_CLASS_MAPPING.put(Map.class, RedissonMap.class);
supportedClassMapping.put(BlockingDeque.class, RedissonBlockingDeque.class); SUPPORTED_CLASS_MAPPING.put(BlockingDeque.class, RedissonBlockingDeque.class);
supportedClassMapping.put(Deque.class, RedissonDeque.class); SUPPORTED_CLASS_MAPPING.put(Deque.class, RedissonDeque.class);
supportedClassMapping.put(BlockingQueue.class, RedissonBlockingQueue.class); SUPPORTED_CLASS_MAPPING.put(BlockingQueue.class, RedissonBlockingQueue.class);
supportedClassMapping.put(Queue.class, RedissonQueue.class); SUPPORTED_CLASS_MAPPING.put(Queue.class, RedissonQueue.class);
supportedClassMapping.put(List.class, RedissonList.class); SUPPORTED_CLASS_MAPPING.put(List.class, RedissonList.class);
} }
private final Config config; private final Config config;
@ -98,16 +98,16 @@ public class RedissonObjectBuilder {
} }
} }
private static final Map<Class<?>, CodecMethodRef> references = new HashMap<Class<?>, CodecMethodRef>(); private static final Map<Class<?>, CodecMethodRef> REFERENCES = new HashMap<>();
private final ReferenceCodecProvider codecProvider = new DefaultReferenceCodecProvider(); private final ReferenceCodecProvider codecProvider = new DefaultReferenceCodecProvider();
public RedissonObjectBuilder(Config config) { public RedissonObjectBuilder(Config config) {
super(); super();
this.config = config; this.config = config;
fillCodecMethods(references, RedissonClient.class, RObject.class); fillCodecMethods(REFERENCES, RedissonClient.class, RObject.class);
fillCodecMethods(references, RedissonReactiveClient.class, RObjectReactive.class); fillCodecMethods(REFERENCES, RedissonReactiveClient.class, RObjectReactive.class);
fillCodecMethods(references, RedissonRxClient.class, RObjectRx.class); fillCodecMethods(REFERENCES, RedissonRxClient.class, RObjectRx.class);
} }
public ReferenceCodecProvider getReferenceCodecProvider() { public ReferenceCodecProvider getReferenceCodecProvider() {
@ -169,7 +169,7 @@ public class RedissonObjectBuilder {
} }
private Class<? extends RObject> getMappedClass(Class<?> cls) { private Class<? extends RObject> getMappedClass(Class<?> cls) {
for (Entry<Class<?>, Class<? extends RObject>> entrySet : supportedClassMapping.entrySet()) { for (Entry<Class<?>, Class<? extends RObject>> entrySet : SUPPORTED_CLASS_MAPPING.entrySet()) {
if (entrySet.getKey().isAssignableFrom(cls)) { if (entrySet.getKey().isAssignableFrom(cls)) {
return entrySet.getValue(); return entrySet.getValue();
} }
@ -216,16 +216,17 @@ public class RedissonObjectBuilder {
ReferenceCodecProvider codecProvider) ReferenceCodecProvider codecProvider)
throws IllegalAccessException, InvocationTargetException, Exception, ClassNotFoundException { throws IllegalAccessException, InvocationTargetException, Exception, ClassNotFoundException {
if (type != null) { if (type != null) {
CodecMethodRef b = references.get(type); CodecMethodRef b = REFERENCES.get(type);
if (b == null && type.getInterfaces().length > 0) { if (b == null && type.getInterfaces().length > 0) {
type = type.getInterfaces()[0]; type = type.getInterfaces()[0];
} }
b = references.get(type); b = REFERENCES.get(type);
if (b != null) { if (b != null) {
Method builder = b.get(isDefaultCodec(rr)); Method builder = b.get(isDefaultCodec(rr));
return (isDefaultCodec(rr) if (isDefaultCodec(rr)) {
? builder.invoke(redisson, rr.getKeyName()) return builder.invoke(redisson, rr.getKeyName());
: builder.invoke(redisson, rr.getKeyName(), codecProvider.getCodec(rr.getCodecType()))); }
return builder.invoke(redisson, rr.getKeyName(), codecProvider.getCodec(rr.getCodecType()));
} }
} }
throw new ClassNotFoundException("No RObject is found to match class type of " + rr.getTypeName() + " with codec type of " + rr.getCodecName()); throw new ClassNotFoundException("No RObject is found to match class type of " + rr.getTypeName() + " with codec type of " + rr.getCodecName());
@ -259,7 +260,7 @@ public class RedissonObjectBuilder {
if (object instanceof RObject && !(object instanceof RLiveObject)) { if (object instanceof RObject && !(object instanceof RLiveObject)) {
Class<?> clazz = object.getClass().getInterfaces()[0]; Class<?> clazz = object.getClass().getInterfaces()[0];
RObject rObject = ((RObject) object); RObject rObject = (RObject) object;
if (rObject.getCodec() != null) { if (rObject.getCodec() != null) {
codecProvider.registerCodec((Class) rObject.getCodec().getClass(), rObject.getCodec()); codecProvider.registerCodec((Class) rObject.getCodec().getClass(), rObject.getCodec());
} }
@ -268,7 +269,7 @@ public class RedissonObjectBuilder {
if (object instanceof RObjectReactive && !(object instanceof RLiveObject)) { if (object instanceof RObjectReactive && !(object instanceof RLiveObject)) {
Class<?> clazz = object.getClass().getInterfaces()[0]; Class<?> clazz = object.getClass().getInterfaces()[0];
RObjectReactive rObject = ((RObjectReactive) object); RObjectReactive rObject = (RObjectReactive) object;
if (rObject.getCodec() != null) { if (rObject.getCodec() != null) {
codecProvider.registerCodec((Class) rObject.getCodec().getClass(), rObject.getCodec()); codecProvider.registerCodec((Class) rObject.getCodec().getClass(), rObject.getCodec());
} }
@ -296,14 +297,24 @@ public class RedissonObjectBuilder {
public <T extends RObject, K extends Codec> T createRObject(RedissonClient redisson, Class<T> expectedType, String name, K codec) throws Exception { public <T extends RObject, K extends Codec> T createRObject(RedissonClient redisson, Class<T> expectedType, String name, K codec) throws Exception {
List<Class<?>> interfaces = Arrays.asList(expectedType.getInterfaces()); List<Class<?>> interfaces = Arrays.asList(expectedType.getInterfaces());
for (Class<?> iType : interfaces) { for (Class<?> iType : interfaces) {
if (references.containsKey(iType)) {// user cache to speed up things a little. if (REFERENCES.containsKey(iType)) {// user cache to speed up things a little.
Method builder = references.get(iType).get(codec != null); Method builder = REFERENCES.get(iType).get(codec != null);
return (T) (codec != null if (codec != null) {
? builder.invoke(redisson, name) return (T) builder.invoke(redisson, name);
: builder.invoke(redisson, name, codec)); }
return (T) builder.invoke(redisson, name, codec);
} }
} }
throw new ClassNotFoundException("No RObject is found to match class type of " + (expectedType != null ? expectedType.getName() : "null") + " with codec type of " + (codec != null ? codec.getClass().getName() : "null"));
String type = null;
if (expectedType != null) {
type = expectedType.getName();
}
String codecName = null;
if (codec != null) {
codecName = codec.getClass().getName();
}
throw new ClassNotFoundException("No RObject is found to match class type of " + type + " with codec type of " + codecName);
} }
} }

@ -119,22 +119,22 @@ public class ClassUtils {
throw new NoSuchFieldException("No such field: " + fieldName); throw new NoSuchFieldException("No such field: " + fieldName);
} }
private static final Map<Class<?>, Boolean> annotatedClasses = new LRUCacheMap<Class<?>, Boolean>(500, 0, 0); private static final Map<Class<?>, Boolean> ANNOTATED_CLASSES = new LRUCacheMap<Class<?>, Boolean>(500, 0, 0);
public static boolean isAnnotationPresent(Class<?> clazz, Class<? extends Annotation> annotation) { public static boolean isAnnotationPresent(Class<?> clazz, Class<? extends Annotation> annotation) {
if (clazz.getName().startsWith("java.")) { if (clazz.getName().startsWith("java.")) {
return false; return false;
} }
Boolean isAnnotated = annotatedClasses.get(clazz); Boolean isAnnotated = ANNOTATED_CLASSES.get(clazz);
if (isAnnotated == null) { if (isAnnotated == null) {
for (Class<?> c : getClassHierarchy(clazz)) { for (Class<?> c : getClassHierarchy(clazz)) {
if (c.isAnnotationPresent(annotation)) { if (c.isAnnotationPresent(annotation)) {
annotatedClasses.put(clazz, true); ANNOTATED_CLASSES.put(clazz, true);
return true; return true;
} }
} }
annotatedClasses.put(clazz, false); ANNOTATED_CLASSES.put(clazz, false);
return false; return false;
} }
return isAnnotated; return isAnnotated;

@ -35,6 +35,7 @@ public interface RIdResolver<A extends RId, V> extends Resolver<Class<?>, A, V>{
* @param redisson instance * @param redisson instance
* @return resolved RId field value. * @return resolved RId field value.
*/ */
public V resolve(Class<?> cls, A annotation, String idFieldName, RedissonClient redisson); @Override
V resolve(Class<?> cls, A annotation, String idFieldName, RedissonClient redisson);
} }

@ -40,6 +40,6 @@ public interface Resolver<T, A extends Annotation, V> {
* @param redisson instance * @param redisson instance
* @return resolved value * @return resolved value
*/ */
public V resolve(T value, A annotation, String idFieldName, RedissonClient redisson); V resolve(T value, A annotation, String idFieldName, RedissonClient redisson);
} }

Loading…
Cancel
Save