refactoring

pull/3118/head
Nikita Koksharov
parent 48619623cd
commit 478e54e877

@ -39,6 +39,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.regex.Pattern;
/**
* This class is going to be instantiated and becomes a <b>static</b> field of
@ -50,6 +51,10 @@ import java.util.concurrent.Callable;
*/
public class AccessorInterceptor {
private static final Pattern GETTER_PATTERN = Pattern.compile("^(get|is)");
private static final Pattern SETTER_PATTERN = Pattern.compile("^(set)");
private static final Pattern FIELD_PATTERN = Pattern.compile("^(get|set|is)");
private final CommandAsyncExecutor commandExecutor;
private final ConnectionManager connectionManager;
@ -201,9 +206,9 @@ public class AccessorInterceptor {
ce.execute();
}
private RFuture<Boolean> removeAsync(CommandBatchService ce, String name, String mapName, Codec codec, Object value, String fieldName) {
private void removeAsync(CommandBatchService ce, String name, String mapName, Codec codec, Object value, String fieldName) {
ByteBuf valueState = ce.encodeMapValue(codec, value);
return ce.evalWriteAsync(name, codec, RedisCommands.EVAL_VOID,
ce.evalWriteAsync(name, codec, RedisCommands.EVAL_VOID,
"local oldArg = redis.call('hget', KEYS[2], ARGV[2]);" +
"if oldArg == false then " +
"return; " +
@ -250,32 +255,22 @@ public class AccessorInterceptor {
}
private String getFieldName(Class<?> clazz, Method method) {
String name = method.getName();
int i = 4;
if (name.startsWith("is")) {
i = 3;
}
String fieldName = FIELD_PATTERN.matcher(method.getName()).replaceFirst("");
String propName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);
try {
String fieldName = name.substring(i - 1, i).toLowerCase() + name.substring(i);
ClassUtils.getDeclaredField(clazz, fieldName);
return fieldName;
ClassUtils.getDeclaredField(clazz, propName);
return propName;
} catch (NoSuchFieldException e) {
return name.substring(i - 1);
return fieldName;
}
}
private boolean isGetter(Method method, String fieldName) {
return method.getName().equals("get" + getFieldNameSuffix(fieldName))
|| method.getName().equals("is" + getFieldNameSuffix(fieldName));
return GETTER_PATTERN.matcher(method.getName()).replaceFirst("").equalsIgnoreCase(fieldName);
}
private boolean isSetter(Method method, String fieldName) {
return method.getName().equals("set" + getFieldNameSuffix(fieldName));
}
private static String getFieldNameSuffix(String fieldName) {
return fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
return SETTER_PATTERN.matcher(method.getName()).replaceFirst("").equalsIgnoreCase(fieldName);
}
private static String getREntityIdFieldName(Object o) {

Loading…
Cancel
Save