Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/dvgaba/easy-random
Browse files Browse the repository at this point in the history
  • Loading branch information
dvgaba committed Aug 4, 2022
2 parents 8488e84 + bf63598 commit 52158a2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.function.Predicate;

import static java.lang.String.format;
import static java.time.ZonedDateTime.of;

/**
* Parameters of an {@link EasyRandom} instance.
Expand Down Expand Up @@ -82,7 +81,7 @@ public class EasyRandomParameters {
/**
* Reference date around which random dates will be generated.
*/
private static final ZonedDateTime REFERENCE_DATE = of(2020, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
private static final ZonedDateTime REFERENCE_DATE = ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));

/**
* Default dates range.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class RandomizationContext implements RandomizerContext {

private final EasyRandomParameters parameters;

private final Map<Class<?>, List<Object>> populatedBeans;
private final IdentityHashMap<Class<?>, List<Object>> populatedBeans;

private final Stack<RandomizationContextStackItem> stack;
private final Deque<RandomizationContextStackItem> stack;

private final Class<?> type;

Expand All @@ -53,7 +53,7 @@ class RandomizationContext implements RandomizerContext {
RandomizationContext(final Class<?> type, final EasyRandomParameters parameters) {
this.type = type;
populatedBeans = new IdentityHashMap<>();
stack = new Stack<>();
stack = new ArrayDeque<>();
this.parameters = parameters;
this.random = new Random(parameters.getSeed());
}
Expand Down Expand Up @@ -100,7 +100,13 @@ boolean hasExceededRandomizationDepth() {
}

private List<String> getStackedFieldNames() {
return stack.stream().map(i -> i.getField().getName()).collect(toList());

List<String> collect = new ArrayList<>();
Iterator<RandomizationContextStackItem> it = stack.descendingIterator();
while(it.hasNext()) {
collect.add(it.next().getField().getName());
}
return collect;
}

private List<String> toLowerCase(final List<String> strings) {
Expand All @@ -120,11 +126,11 @@ public Class<?> getTargetType() {

@Override
public Object getCurrentObject() {
if (stack.empty()) {
if (stack.isEmpty()) {
return rootObject;
}
else {
return stack.lastElement().getObject();
return stack.peek().getObject();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static List<Character> filterLetters(List<Character> characters) {

private static boolean isPrintable(char character) {
Character.UnicodeBlock block = Character.UnicodeBlock.of(character);
return (!Character.isISOControl(character)) && block != null && block != Character.UnicodeBlock.SPECIALS;
return !Character.isISOControl(character) && !Character.UnicodeBlock.SPECIALS.equals(block);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ enum PrimitiveEnum {
BOOLEAN(Boolean.TYPE, Boolean.class),
CHARACTER(Character.TYPE, Character.class);

private Class<?> type;
private Class<?> clazz;
private final Class<?> type;
private final Class<?> clazz;

PrimitiveEnum(Class<?> type, Class<?> clazz) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public static <T extends Annotation> T getAnnotation(Field field, Class<T> annot
*/
public static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType) {
final Optional<Method> readMethod = getReadMethod(field);
return field.isAnnotationPresent(annotationType) || readMethod.isPresent() && readMethod.get().isAnnotationPresent(annotationType);
return field.isAnnotationPresent(annotationType) || (readMethod.isPresent() && readMethod.get().isAnnotationPresent(annotationType));
}

/**
Expand Down

0 comments on commit 52158a2

Please sign in to comment.