Skip to content

Commit

Permalink
Some reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pholser committed Oct 8, 2019
1 parent 19974e4 commit 826932f
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ public Fields(Class<T> type) {
instantiate(type);
}

@Override public T generate(SourceOfRandomness random, GenerationStatus status) {
@Override public T generate(
SourceOfRandomness random,
GenerationStatus status) {

Class<T> type = types().get(0);
Object generated = instantiate(type);

for (int i = 0; i < fields.size(); i++) {
Field each = fields.get(i);
setField(
each,
fields.get(i),
generated,
fieldGenerators.get(i).generate(random, status),
true);
Expand All @@ -101,8 +103,10 @@ public Fields(Class<T> type) {
@Override public void configure(AnnotatedType annotatedType) {
super.configure(annotatedType);

for (int i = 0; i < fields.size(); ++i)
fieldGenerators.get(i).configure(fields.get(i).getAnnotatedType());
for (int i = 0; i < fields.size(); ++i) {
fieldGenerators.get(i).configure(
fields.get(i).getAnnotatedType());
}
}

@Override public Generator<T> copy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ private boolean evaluate(Object value) {
else
++discards;

if (tooManyDiscards())
throw new DiscardRatioExceededException(parameter, discards, successfulEvaluations);
if (tooManyDiscards()) {
throw new DiscardRatioExceededException(
parameter,
discards,
successfulEvaluations);
}

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ a copy of this software and associated documentation files (the
* Produces values of type {@link Locale}.
*/
public class LocaleGenerator extends Generator<Locale> {
private final static Locale[] availableLocales = getAvailableLocales();
private static final Locale[] AVAILABLE_LOCALES = getAvailableLocales();

public LocaleGenerator() {
super(Locale.class);
}

@Override public Locale generate(SourceOfRandomness random, GenerationStatus status) {
return random.choose(availableLocales);
@Override public Locale generate(
SourceOfRandomness random,
GenerationStatus status) {

return random.choose(AVAILABLE_LOCALES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public OptionalGenerator() {
double trial = random.nextDouble();
return trial < 0.25
? Optional.empty()
: Optional.of(componentGenerators().get(0).generate(random, status));
: Optional.of(
componentGenerators().get(0).generate(random, status));
}

@Override public List<Optional> doShrink(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ a copy of this software and associated documentation files (the
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -54,7 +53,9 @@ private RFC4122() {
throw new UnsupportedOperationException();
}

private abstract static class AbstractUUIDGenerator extends Generator<UUID> {
private abstract static class AbstractUUIDGenerator
extends Generator<UUID> {

protected AbstractUUIDGenerator() {
super(UUID.class);
}
Expand All @@ -75,21 +76,33 @@ protected final UUID newUUID(byte[] bytes) {
}
}

private abstract static class NameBasedUUIDGenerator extends AbstractUUIDGenerator {
private abstract static class NameBasedUUIDGenerator
extends AbstractUUIDGenerator {

private final StringGenerator stringGenerator = new StringGenerator();
private final int versionMask;
private final MessageDigest digest;
private Namespace namespace;

protected NameBasedUUIDGenerator(String hashAlgorithmName, int versionMask) {
protected NameBasedUUIDGenerator(
String hashAlgorithmName,
int versionMask) {

this.versionMask = versionMask;
digest = MessageDigests.get(hashAlgorithmName);
}

@Override public UUID generate(SourceOfRandomness random, GenerationStatus status) {
@Override public UUID generate(
SourceOfRandomness random,
GenerationStatus status) {

digest.reset();
digest.update((namespace == null ? Namespaces.URL : namespace.value()).bytes);
digest.update(stringGenerator.generate(random, status).getBytes(StandardCharsets.UTF_8));

Namespaces namespaces = namespace == null ? URL : namespace.value();
digest.update(namespaces.bytes);
digest.update(
stringGenerator.generate(random, status)
.getBytes(StandardCharsets.UTF_8));

byte[] hash = digest.digest();
setVersion(hash, (byte) versionMask);
Expand Down Expand Up @@ -141,7 +154,10 @@ public void configure(Namespace namespace) {
* identifiers.
*/
public static class Version4 extends AbstractUUIDGenerator {
@Override public UUID generate(SourceOfRandomness random, GenerationStatus status) {
@Override public UUID generate(
SourceOfRandomness random,
GenerationStatus status) {

byte[] bytes = random.nextBytes(16);
setVersion(bytes, (byte) 0x40);
setVariant(bytes);
Expand Down Expand Up @@ -202,7 +218,8 @@ public enum Namespaces {
final byte[] bytes;

Namespaces(int difference) {
this.bytes = new byte[] { 0x6B, (byte) 0xA7, (byte) 0xB8, (byte) difference,
this.bytes = new byte[] {
0x6B, (byte) 0xA7, (byte) 0xB8, (byte) difference,
(byte) 0x9D, (byte) 0xAD,
0x11, (byte) 0xD1,
(byte) 0x80, (byte) 0xB4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ a copy of this software and associated documentation files (the
* Produces values of type {@link TimeZone}.
*/
public class TimeZoneGenerator extends Generator<TimeZone> {
private final static String[] availableIDs = getAvailableIDs();
private static final String[] AVAILABLE_IDS = getAvailableIDs();

public TimeZoneGenerator() {
super(TimeZone.class);
}

@Override public TimeZone generate(SourceOfRandomness random, GenerationStatus status) {
return getTimeZone(random.choose(availableIDs));
@Override public TimeZone generate(
SourceOfRandomness random,
GenerationStatus status) {

return getTimeZone(random.choose(AVAILABLE_IDS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ a copy of this software and associated documentation files (the
* @param <U> type of second parameter of produced function
* @param <R> return type of produced function
*/
public class BiFunctionGenerator<T, U, R> extends ComponentizedGenerator<BiFunction> {
public class BiFunctionGenerator<T, U, R>
extends ComponentizedGenerator<BiFunction> {

public BiFunctionGenerator() {
super(BiFunction.class);
}

@SuppressWarnings("unchecked")
@Override public BiFunction<T, U, R> generate(SourceOfRandomness random, GenerationStatus status) {
return makeLambda(BiFunction.class, componentGenerators().get(2), status);
@Override public BiFunction<T, U, R> generate(
SourceOfRandomness random,
GenerationStatus status) {

return makeLambda(
BiFunction.class,
componentGenerators().get(2),
status);
}

@Override public int numberOfNeededComponents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ a copy of this software and associated documentation files (the
* @param <T> type of first parameter of produced predicate
* @param <U> type of second parameter of produced predicate
*/
public class BiPredicateGenerator<T, U> extends ComponentizedGenerator<BiPredicate> {
public class BiPredicateGenerator<T, U>
extends ComponentizedGenerator<BiPredicate> {

private Generator<Boolean> generator;

public BiPredicateGenerator() {
Expand All @@ -51,11 +53,15 @@ public BiPredicateGenerator() {
@Override
public void provide(Generators provided) {
super.provide(provided);

generator = gen().type(boolean.class);
}

@SuppressWarnings("unchecked")
@Override public BiPredicate<T, U> generate(SourceOfRandomness random, GenerationStatus status) {
@Override public BiPredicate<T, U> generate(
SourceOfRandomness random,
GenerationStatus status) {

return makeLambda(BiPredicate.class, generator, status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ public PredicateGenerator() {
@Override
public void provide(Generators provided) {
super.provide(provided);

generator = gen().type(boolean.class);
}

@SuppressWarnings("unchecked")
@Override public Predicate<T> generate(SourceOfRandomness random, GenerationStatus status) {
@Override public Predicate<T> generate(
SourceOfRandomness random,
GenerationStatus status) {

return makeLambda(Predicate.class, generator, status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ a copy of this software and associated documentation files (the
* @param <T> type of first parameter of produced function
* @param <U> type of second parameter of produced function
*/
public class ToDoubleBiFunctionGenerator<T, U> extends ComponentizedGenerator<ToDoubleBiFunction> {
public class ToDoubleBiFunctionGenerator<T, U>
extends ComponentizedGenerator<ToDoubleBiFunction> {

private Generator<Double> generator;

public ToDoubleBiFunctionGenerator() {
Expand All @@ -51,11 +53,15 @@ public ToDoubleBiFunctionGenerator() {
@Override
public void provide(Generators provided) {
super.provide(provided);

generator = gen().type(double.class);
}

@SuppressWarnings("unchecked")
@Override public ToDoubleBiFunction<T, U> generate(SourceOfRandomness random, GenerationStatus status) {
@Override public ToDoubleBiFunction<T, U> generate(
SourceOfRandomness random,
GenerationStatus status) {

return makeLambda(ToDoubleBiFunction.class, generator, status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ a copy of this software and associated documentation files (the
*
* @param <T> type of parameter of produced function
*/
public class ToDoubleFunctionGenerator<T> extends ComponentizedGenerator<ToDoubleFunction> {
public class ToDoubleFunctionGenerator<T>
extends ComponentizedGenerator<ToDoubleFunction> {

private Generator<Double> generator;

public ToDoubleFunctionGenerator() {
Expand All @@ -50,11 +52,15 @@ public ToDoubleFunctionGenerator() {
@Override
public void provide(Generators provided) {
super.provide(provided);

generator = gen().type(double.class);
}

@SuppressWarnings("unchecked")
@Override public ToDoubleFunction<T> generate(SourceOfRandomness random, GenerationStatus status) {
@Override public ToDoubleFunction<T> generate(
SourceOfRandomness random,
GenerationStatus status) {

return makeLambda(ToDoubleFunction.class, generator, status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ a copy of this software and associated documentation files (the
* @param <T> type of first parameter of produced function
* @param <U> type of second parameter of produced function
*/
public class ToIntBiFunctionGenerator<T, U> extends ComponentizedGenerator<ToIntBiFunction> {
public class ToIntBiFunctionGenerator<T, U>
extends ComponentizedGenerator<ToIntBiFunction> {

private Generator<Integer> generator;

public ToIntBiFunctionGenerator() {
Expand All @@ -51,11 +53,15 @@ public ToIntBiFunctionGenerator() {
@Override
public void provide(Generators provided) {
super.provide(provided);

generator = gen().type(int.class);
}

@SuppressWarnings("unchecked")
@Override public ToIntBiFunction<T, U> generate(SourceOfRandomness random, GenerationStatus status) {
@Override public ToIntBiFunction<T, U> generate(
SourceOfRandomness random,
GenerationStatus status) {

return makeLambda(ToIntBiFunction.class, generator, status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ a copy of this software and associated documentation files (the
*
* @param <T> type of parameter of produced function
*/
public class ToIntFunctionGenerator<T> extends ComponentizedGenerator<ToIntFunction> {
public class ToIntFunctionGenerator<T>
extends ComponentizedGenerator<ToIntFunction> {

private Generator<Integer> generator;

public ToIntFunctionGenerator() {
Expand All @@ -50,11 +52,15 @@ public ToIntFunctionGenerator() {
@Override
public void provide(Generators provided) {
super.provide(provided);

generator = gen().type(int.class);
}

@SuppressWarnings("unchecked")
@Override public ToIntFunction<T> generate(SourceOfRandomness random, GenerationStatus status) {
@Override public ToIntFunction<T> generate(
SourceOfRandomness random,
GenerationStatus status) {

return makeLambda(ToIntFunction.class, generator, status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ a copy of this software and associated documentation files (the
* @param <T> type of first parameter of produced function
* @param <U> type of second parameter of produced function
*/
public class ToLongBiFunctionGenerator<T, U> extends ComponentizedGenerator<ToLongBiFunction> {
public class ToLongBiFunctionGenerator<T, U>
extends ComponentizedGenerator<ToLongBiFunction> {

private Generator<Long> generator;

public ToLongBiFunctionGenerator() {
Expand All @@ -51,11 +53,15 @@ public ToLongBiFunctionGenerator() {
@Override
public void provide(Generators provided) {
super.provide(provided);

generator = gen().type(long.class);
}

@SuppressWarnings("unchecked")
@Override public ToLongBiFunction<T, U> generate(SourceOfRandomness random, GenerationStatus status) {
@Override public ToLongBiFunction<T, U> generate(
SourceOfRandomness random,
GenerationStatus status) {

return makeLambda(ToLongBiFunction.class, generator, status);
}

Expand Down
Loading

0 comments on commit 826932f

Please sign in to comment.