Skip to content

Commit

Permalink
Minor changes (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvgaba authored Sep 23, 2022
1 parent 385128c commit d5d029f
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 34 deletions.
2 changes: 1 addition & 1 deletion easy-random-bean-validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.dvgaba</groupId>
<artifactId>easy-random</artifactId>
<version>6.1.0</version>
<version>6.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>easy-random-bean-validation</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion easy-random-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.dvgaba</groupId>
<artifactId>easy-random</artifactId>
<version>6.1.0</version>
<version>6.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>easy-random-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
package org.jeasy.random;

import static java.util.stream.Collectors.toList;

import java.lang.reflect.Field;
import java.util.*;
import org.jeasy.random.api.RandomizerContext;
Expand Down Expand Up @@ -108,7 +106,7 @@ private List<String> getStackedFieldNames() {
}

private List<String> toLowerCase(final List<String> strings) {
return strings.stream().map(String::toLowerCase).collect(toList());
return strings.stream().map(String::toLowerCase).toList();
}

void setRandomizedObject(Object randomizedObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import static java.lang.String.format;
import static java.util.Arrays.asList;
import static java.util.Locale.ENGLISH;
import static java.util.stream.Collectors.toList;
import static org.jeasy.random.util.ConversionUtils.convertArguments;

import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -203,7 +202,7 @@ public static boolean isPrimitiveFieldWithDefaultValue(final Object object, fina
if (fieldValue == null) {
return false;
}
if (fieldType.equals(boolean.class) && (boolean) fieldValue == false) {
if (fieldType.equals(boolean.class) && !((boolean) fieldValue)) {
return true;
}
if (fieldType.equals(byte.class) && (byte) fieldValue == (byte) 0) {
Expand Down Expand Up @@ -374,11 +373,7 @@ public static boolean isJdkBuiltIn(final Class<?> type) {
* @return true if the type is parameterized, false otherwise
*/
public static boolean isParameterizedType(final Type type) {
return (
type != null &&
type instanceof ParameterizedType &&
((ParameterizedType) type).getActualTypeArguments().length > 0
);
return (type instanceof ParameterizedType && ((ParameterizedType) type).getActualTypeArguments().length > 0);
}

/**
Expand Down Expand Up @@ -420,8 +415,8 @@ public static <T> List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type
* @return a list of types having the same parameterized types as the given type
*/
public static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type) {
if (type instanceof ParameterizedType) {
Type[] fieldArugmentTypes = ((ParameterizedType) type).getActualTypeArguments();
if (type instanceof ParameterizedType parameterizedType) {
Type[] fieldArugmentTypes = parameterizedType.getActualTypeArguments();
List<Class<?>> typesWithSameParameterizedTypes = new ArrayList<>();
for (Class<?> currentConcreteType : types) {
List<Type[]> actualTypeArguments = getActualTypeArgumentsOfGenericInterfaces(currentConcreteType);
Expand All @@ -430,7 +425,7 @@ public static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> t
.stream()
.filter(currentTypeArguments -> Arrays.equals(fieldArugmentTypes, currentTypeArguments))
.map(currentTypeArguments -> currentConcreteType)
.collect(toList())
.toList()
);
}
return typesWithSameParameterizedTypes;
Expand Down Expand Up @@ -598,8 +593,8 @@ private static List<Type[]> getActualTypeArgumentsOfGenericInterfaces(final Clas
List<Type[]> actualTypeArguments = new ArrayList<>();
Type[] genericInterfaceTypes = type.getGenericInterfaces();
for (Type currentGenericInterfaceType : genericInterfaceTypes) {
if (currentGenericInterfaceType instanceof ParameterizedType) {
actualTypeArguments.add(((ParameterizedType) currentGenericInterfaceType).getActualTypeArguments());
if (currentGenericInterfaceType instanceof ParameterizedType parameterizedType) {
actualTypeArguments.add((parameterizedType).getActualTypeArguments());
}
}
return actualTypeArguments;
Expand Down
2 changes: 1 addition & 1 deletion easy-random-protobuf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.dvgaba</groupId>
<artifactId>easy-random</artifactId>
<version>6.1.0</version>
<version>6.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>easy-random-protobuf</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class ProtobufExclusionPolicy extends DefaultExclusionPolicy {

@Override
public boolean shouldBeExcluded(final Field field, final RandomizerContext context, Object object) {
if (!(object instanceof FieldDescriptor)) {
throw new IllegalArgumentException("3rd parameter must be of FieldDescriptor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
public class ProtobufMessageBuilderRandomizer implements ContextAwareRandomizer<Builder> {

private final ProtobufMessageRandomizer protobufMessageRandomizer;
private RandomizerContext context;

public ProtobufMessageBuilderRandomizer(
Class<Message.Builder> messageBuilderClass,
Expand Down Expand Up @@ -65,7 +64,6 @@ public String toString() {

@Override
public void setRandomizerContext(RandomizerContext context) {
this.context = context;
protobufMessageRandomizer.setRandomizerContext(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.EnumMap;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import org.jeasy.random.EasyRandom;
import org.jeasy.random.EasyRandomParameters;
import org.jeasy.random.api.ContextAwareRandomizer;
Expand Down Expand Up @@ -117,7 +116,7 @@ public Message getRandomValue() {
.getFields()
.stream()
.filter(field -> field.getContainingOneof() == null)
.collect(Collectors.toList());
.toList();
for (FieldDescriptor fieldDescriptor : plainFields) {
populateField(fieldDescriptor, builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class ProtobufPredicates {

private static EnumMap protoToJavaTypeMap = new EnumMap(FieldDescriptor.Type.class);
private static EnumMap<Type, Class<?>> protoToJavaTypeMap = new EnumMap<>(FieldDescriptor.Type.class);

static {
protoToJavaTypeMap.put(Type.INT32, Int32Value.class);
Expand All @@ -37,11 +37,8 @@ public class ProtobufPredicates {
}

public static BiPredicate<Field, Object> named(final String name) {
System.out.println(name);
final Pattern pattern = Pattern.compile(name + "_");
return (field, fieldDescriptor) -> {
return pattern.matcher(field.getName()).matches();
};
return (field, fieldDescriptor) -> pattern.matcher(field.getName()).matches();
}

public static BiPredicate<Field, Object> ofProtobufType(Class<?> type) {
Expand All @@ -58,8 +55,6 @@ public static BiPredicate<Field, Object> ofProtobufType(Class<?> type) {
}

public static Predicate<Class<?>> ofType(Class<?> type) {
return clz -> {
return clz.equals(type);
};
return clz -> clz.equals(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void shouldGenerateTheSameValueForTheSameSeed() {
assertThat(embeddedMessage.getEnumField()).isEqualTo(Proto2Enum.THIRD_VALUE);
});
assertThat(protoBuilderInstance.getOneofFieldCase().getNumber())
.isNotEqualTo(Proto2Message.OneofFieldCase.ONEOFFIELD_NOT_SET);
.isNotEqualTo(Proto2Message.OneofFieldCase.ONEOFFIELD_NOT_SET.getNumber());
assertThat(protoBuilderInstance.getMapFieldMap())
.hasSize(4)
.containsEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void shouldGenerateTheSameValueForTheSameSeed() {
assertThat(embeddedMessage.getEnumField()).isEqualTo(Proto2Enum.THIRD_VALUE);
});
assertThat(protoInstance.getOneofFieldCase().getNumber())
.isNotEqualTo(Proto2Message.OneofFieldCase.ONEOFFIELD_NOT_SET);
.isNotEqualTo(Proto2Message.OneofFieldCase.ONEOFFIELD_NOT_SET.getNumber());
assertThat(protoInstance.getMapFieldMap())
.hasSize(4)
.containsEntry(
Expand Down
2 changes: 1 addition & 1 deletion easy-random-randomizers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.dvgaba</groupId>
<artifactId>easy-random</artifactId>
<version>6.1.0</version>
<version>6.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>easy-random-randomizers</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.dvgaba</groupId>
<artifactId>easy-random</artifactId>
<version>6.1.0</version>
<version>6.1.1</version>
<packaging>pom</packaging>

<build>
Expand Down

0 comments on commit d5d029f

Please sign in to comment.