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 -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<!--module name="AvoidInlineConditionals"/-->
<module name="ArrayTrailingComma"/>
<module name="AvoidInlineConditionals"/>
<module name="CovariantEquals"/>
<!-- MY FAVOURITE -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="EqualsAvoidNull"/>
<!--module name="HiddenField"/-->
<module name="IllegalInstantiation"/>
<module name="IllegalThrows"/>
<module name="InnerAssignment"/>
<module name="MultipleVariableDeclarations"/>
<!--module name="MagicNumber"/-->
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>
<module name="NestedForDepth">
<property name="max" value="2"/>
</module>
<module name="NestedIfDepth">
<property name="max" value="3"/>
</module>
<module name="NestedTryDepth"/>
<module name="SuperClone"/>
<module name="NoClone"/>
<module name="NoFinalizer"/>
<module name="OneStatementPerLine"/>
<module name="IllegalCatch">
<property name="illegalClassNames" value=" java.lang.Throwable, java.lang.RuntimeException"/>
</module>
<!--module name="IllegalThrows"/-->
<module name="FallThrough"/>
<module name="UnnecessaryParentheses"/>
<!--module name="FinalLocalVariable"/-->

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

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

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

@ -145,9 +145,14 @@ public class RedisCommand<R> {
return outParamType;
}
@Override
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
@SuppressWarnings("AvoidInlineConditionals")
public int hashCode() {
final int prime = 31;
int result = 1;

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

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

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

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

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

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

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

@ -88,7 +88,7 @@ public class AccessorInterceptor {
if (result != null && fieldType.isEnum()) {
if (result instanceof String) {
return Enum.valueOf((Class)fieldType, (String)result);
return Enum.valueOf((Class) fieldType, (String) result);
}
return result;
}
@ -139,7 +139,7 @@ public class AccessorInterceptor {
}
if (arg instanceof RObject) {
objectBuilder.store((RObject)arg, fieldName, liveMap);
objectBuilder.store((RObject) arg, fieldName, liveMap);
return me;
}
@ -176,7 +176,10 @@ public class AccessorInterceptor {
private String getFieldName(Method method) {
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);
}

@ -69,18 +69,18 @@ import org.redisson.liveobject.resolver.NamingScheme;
*/
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 {
supportedClassMapping.put(SortedSet.class, RedissonSortedSet.class);
supportedClassMapping.put(Set.class, RedissonSet.class);
supportedClassMapping.put(ConcurrentMap.class, RedissonMap.class);
supportedClassMapping.put(Map.class, RedissonMap.class);
supportedClassMapping.put(BlockingDeque.class, RedissonBlockingDeque.class);
supportedClassMapping.put(Deque.class, RedissonDeque.class);
supportedClassMapping.put(BlockingQueue.class, RedissonBlockingQueue.class);
supportedClassMapping.put(Queue.class, RedissonQueue.class);
supportedClassMapping.put(List.class, RedissonList.class);
SUPPORTED_CLASS_MAPPING.put(SortedSet.class, RedissonSortedSet.class);
SUPPORTED_CLASS_MAPPING.put(Set.class, RedissonSet.class);
SUPPORTED_CLASS_MAPPING.put(ConcurrentMap.class, RedissonMap.class);
SUPPORTED_CLASS_MAPPING.put(Map.class, RedissonMap.class);
SUPPORTED_CLASS_MAPPING.put(BlockingDeque.class, RedissonBlockingDeque.class);
SUPPORTED_CLASS_MAPPING.put(Deque.class, RedissonDeque.class);
SUPPORTED_CLASS_MAPPING.put(BlockingQueue.class, RedissonBlockingQueue.class);
SUPPORTED_CLASS_MAPPING.put(Queue.class, RedissonQueue.class);
SUPPORTED_CLASS_MAPPING.put(List.class, RedissonList.class);
}
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();
public RedissonObjectBuilder(Config config) {
super();
this.config = config;
fillCodecMethods(references, RedissonClient.class, RObject.class);
fillCodecMethods(references, RedissonReactiveClient.class, RObjectReactive.class);
fillCodecMethods(references, RedissonRxClient.class, RObjectRx.class);
fillCodecMethods(REFERENCES, RedissonClient.class, RObject.class);
fillCodecMethods(REFERENCES, RedissonReactiveClient.class, RObjectReactive.class);
fillCodecMethods(REFERENCES, RedissonRxClient.class, RObjectRx.class);
}
public ReferenceCodecProvider getReferenceCodecProvider() {
@ -169,7 +169,7 @@ public class RedissonObjectBuilder {
}
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)) {
return entrySet.getValue();
}
@ -216,16 +216,17 @@ public class RedissonObjectBuilder {
ReferenceCodecProvider codecProvider)
throws IllegalAccessException, InvocationTargetException, Exception, ClassNotFoundException {
if (type != null) {
CodecMethodRef b = references.get(type);
CodecMethodRef b = REFERENCES.get(type);
if (b == null && type.getInterfaces().length > 0) {
type = type.getInterfaces()[0];
}
b = references.get(type);
b = REFERENCES.get(type);
if (b != null) {
Method builder = b.get(isDefaultCodec(rr));
return (isDefaultCodec(rr)
? builder.invoke(redisson, rr.getKeyName())
: builder.invoke(redisson, rr.getKeyName(), codecProvider.getCodec(rr.getCodecType())));
if (isDefaultCodec(rr)) {
return builder.invoke(redisson, rr.getKeyName());
}
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());
@ -259,7 +260,7 @@ public class RedissonObjectBuilder {
if (object instanceof RObject && !(object instanceof RLiveObject)) {
Class<?> clazz = object.getClass().getInterfaces()[0];
RObject rObject = ((RObject) object);
RObject rObject = (RObject) object;
if (rObject.getCodec() != null) {
codecProvider.registerCodec((Class) rObject.getCodec().getClass(), rObject.getCodec());
}
@ -268,7 +269,7 @@ public class RedissonObjectBuilder {
if (object instanceof RObjectReactive && !(object instanceof RLiveObject)) {
Class<?> clazz = object.getClass().getInterfaces()[0];
RObjectReactive rObject = ((RObjectReactive) object);
RObjectReactive rObject = (RObjectReactive) object;
if (rObject.getCodec() != null) {
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 {
List<Class<?>> interfaces = Arrays.asList(expectedType.getInterfaces());
for (Class<?> iType : interfaces) {
if (references.containsKey(iType)) {// user cache to speed up things a little.
Method builder = references.get(iType).get(codec != null);
return (T) (codec != null
? builder.invoke(redisson, name)
: builder.invoke(redisson, name, codec));
if (REFERENCES.containsKey(iType)) {// user cache to speed up things a little.
Method builder = REFERENCES.get(iType).get(codec != null);
if (codec != null) {
return (T) builder.invoke(redisson, name);
}
return (T) builder.invoke(redisson, name, codec);
}
}
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 " + (expectedType != null ? expectedType.getName() : "null") + " with codec type of " + (codec != null ? codec.getClass().getName() : "null"));
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);
}
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) {
if (clazz.getName().startsWith("java.")) {
return false;
}
Boolean isAnnotated = annotatedClasses.get(clazz);
Boolean isAnnotated = ANNOTATED_CLASSES.get(clazz);
if (isAnnotated == null) {
for (Class<?> c : getClassHierarchy(clazz)) {
if (c.isAnnotationPresent(annotation)) {
annotatedClasses.put(clazz, true);
ANNOTATED_CLASSES.put(clazz, true);
return true;
}
}
annotatedClasses.put(clazz, false);
ANNOTATED_CLASSES.put(clazz, false);
return false;
}
return isAnnotated;

@ -35,6 +35,7 @@ public interface RIdResolver<A extends RId, V> extends Resolver<Class<?>, A, V>{
* @param redisson instance
* @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
* @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