Skip to content

Commit 9e5d9fb

Browse files
reugnroimenashe
andauthored
Code cleanup (#92)
* code cleanup * Fix typo (Zohar E.). Co-authored-by: roimenashe <[email protected]>
1 parent f3722cf commit 9e5d9fb

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

src/main/java/com/aerospike/mapper/tools/GenericTypeMapper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.aerospike.mapper.tools.utils.TypeUtils;
1010

1111
public class GenericTypeMapper extends TypeMapper {
12-
private Class<?> mappedClass;
12+
private final Class<?> mappedClass;
1313
private final Object converter;
1414
private Method toAerospike;
1515
private Method fromAerospike;
@@ -18,13 +18,15 @@ public GenericTypeMapper(Object converter) {
1818
for (Method method : converter.getClass().getMethods()) {
1919
if (method.isAnnotationPresent(ToAerospike.class)) {
2020
if (toAerospike != null) {
21-
throw new AerospikeException(String.format("Multiple methods annotated with @ToAerospike: %s, %s", toAerospike.toGenericString(), method.toGenericString()));
21+
throw new AerospikeException(String.format("Multiple methods annotated with @ToAerospike: %s, %s",
22+
toAerospike.toGenericString(), method.toGenericString()));
2223
}
2324
toAerospike = method;
2425
}
2526
if (method.isAnnotationPresent(FromAerospike.class)) {
2627
if (fromAerospike != null) {
27-
throw new AerospikeException(String.format("Multiple methods annotated with @FromAerospike: %s, %s", fromAerospike.toGenericString(), method.toGenericString()));
28+
throw new AerospikeException(String.format("Multiple methods annotated with @FromAerospike: %s, %s",
29+
fromAerospike.toGenericString(), method.toGenericString()));
2830
}
2931
fromAerospike = method;
3032
}

src/main/java/com/aerospike/mapper/tools/PropertyDefinition.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.aerospike.mapper.tools;
22

3-
import java.lang.annotation.Annotation;
4-
import java.lang.reflect.Method;
5-
import java.lang.reflect.Parameter;
6-
import java.lang.reflect.Type;
7-
83
import com.aerospike.client.AerospikeException;
94
import com.aerospike.client.Key;
105
import com.aerospike.client.Value;
6+
import com.aerospike.mapper.tools.configuration.ClassConfig;
117
import com.aerospike.mapper.tools.utils.TypeUtils;
128
import com.aerospike.mapper.tools.utils.TypeUtils.AnnotatedType;
13-
import com.aerospike.mapper.tools.configuration.ClassConfig;
9+
10+
import java.lang.annotation.Annotation;
11+
import java.lang.reflect.Method;
12+
import java.lang.reflect.Parameter;
13+
import java.lang.reflect.Type;
1414

1515
public class PropertyDefinition {
1616

@@ -20,12 +20,12 @@ public enum SetterParamType {
2020
VALUE
2121
}
2222

23+
private final String name;
24+
private final IBaseAeroMapper mapper;
2325
private Method getter;
2426
private Method setter;
25-
private String name;
2627
private Class<?> clazz;
2728
private TypeMapper typeMapper;
28-
private final IBaseAeroMapper mapper;
2929
private SetterParamType setterParamType = SetterParamType.NONE;
3030

3131
public PropertyDefinition(String name, IBaseAeroMapper mapper) {
@@ -94,27 +94,28 @@ public void validate(String className, ClassConfig config, boolean allowNoSetter
9494
if (this.setter == null) {
9595
throw new AerospikeException(String.format("Property %s on class %s must have a setter", this.name, className));
9696
}
97-
// if (!TypeUtils.isVoidType(setter.getReturnType())) {
98-
// throw new AerospikeException(String.format("Setter for property %s on class %s must return void", this.name, className));
99-
// }
97+
10098
if (setter.getParameterCount() == 2) {
10199
Parameter param = setter.getParameters()[1];
102100
if (param.getType().isAssignableFrom(Key.class)) {
103101
this.setterParamType = SetterParamType.KEY;
104102
} else if (param.getType().isAssignableFrom(Value.class)) {
105103
this.setterParamType = SetterParamType.VALUE;
106104
} else {
107-
throw new AerospikeException(String.format("Property %s on class %s has a setter with 2 arguments, but the second one is neither a Key or a Value", this.name, className));
105+
throw new AerospikeException(String.format("Property %s on class %s has a setter with 2 arguments," +
106+
" but the second one is neither a Key nor a Value", this.name, className));
108107
}
109-
} else if (setter.getParameterCount() != 1 && setter.getParameterCount() != 2) {
110-
throw new AerospikeException(String.format("Setter for property %s on class %s must take 1 or 2 arguments", this.name, className));
108+
} else if (setter.getParameterCount() != 1) {
109+
throw new AerospikeException(String.format("Setter for property %s on class %s must take 1 or 2 arguments",
110+
this.name, className));
111111
}
112112
setterClazz = setter.getParameterTypes()[0];
113113
this.setter.setAccessible(true);
114114
}
115115

116116
if (setterClazz != null && !getterClazz.equals(setterClazz)) {
117-
throw new AerospikeException(String.format("Getter (%s) and setter (%s) for property %s on class %s differ in type", getterClazz.getName(), setterClazz.getName(), this.name, className));
117+
throw new AerospikeException(String.format("Getter (%s) and setter (%s) for property %s on class %s differ in type",
118+
getterClazz.getName(), setterClazz.getName(), this.name, className));
118119
}
119120
this.clazz = getterClazz;
120121

src/main/java/com/aerospike/mapper/tools/virtuallist/VirtualListInteractors.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -875,20 +875,24 @@ public Value getValue(Object javaObject, boolean isKey) {
875875
}
876876
}
877877

878+
@SuppressWarnings("unchecked")
878879
public Operation getAppendOperation(Object aerospikeObject) {
879880
if (aerospikeObject instanceof Map.Entry) {
880-
Map.Entry<Object, Object> entry = (Map.Entry) aerospikeObject;
881-
return MapOperation.put(new MapPolicy(MapOrder.KEY_ORDERED, 0), binName, Value.get(entry.getKey()), Value.get(entry.getValue()));
881+
Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) aerospikeObject;
882+
return MapOperation.put(new MapPolicy(MapOrder.KEY_ORDERED, 0), binName,
883+
Value.get(entry.getKey()), Value.get(entry.getValue()));
882884
} else {
883885
return ListOperation.append(binName, Value.get(aerospikeObject));
884886
}
885887
}
886888

887889
public Interactor getByIndexInteractor(int index) {
888890
if (listType == AerospikeEmbed.EmbedType.LIST) {
889-
return new Interactor(ListOperation.getByIndex(binName, index, ListReturnType.VALUE), new ResultsUnpacker.ElementUnpacker(instanceMapper));
891+
return new Interactor(ListOperation.getByIndex(binName, index, ListReturnType.VALUE),
892+
new ResultsUnpacker.ElementUnpacker(instanceMapper));
890893
} else {
891-
return new Interactor(MapOperation.getByIndex(binName, index, MapReturnType.KEY_VALUE), ResultsUnpacker.ListUnpacker.instance, new ResultsUnpacker.ElementUnpacker(instanceMapper));
894+
return new Interactor(MapOperation.getByIndex(binName, index, MapReturnType.KEY_VALUE),
895+
ResultsUnpacker.ListUnpacker.instance, new ResultsUnpacker.ElementUnpacker(instanceMapper));
892896
}
893897
}
894898

0 commit comments

Comments
 (0)