Skip to content

Commit

Permalink
fix(api) fix issue with type template lost in some builders
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffrey Picron committed May 30, 2017
1 parent e30a471 commit 9216d52
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ gradle.properties
CHANGELOG_tmp.md
working
working-mathcing
out/
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {

subprojects {
group 'com.arboratum'
version '0.1.9'
version '0.1.10'

apply plugin: 'java'
apply plugin: 'idea'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import org.apache.commons.math3.stat.Frequency;

import java.util.*;
import java.util.logging.Logger;

/**
* Created by gpicron on 08/08/2016.
*/
public class CollectionGeneratorBuilder<VALUE, COL extends Collection<VALUE>> extends AbstractGeneratorBuilder<COL> {
private static final Logger log = Logger.getLogger(CollectionGeneratorBuilder.class.getName());


public static final ImmutableSet<Class> SUPPORTED_TYPES = ImmutableSet.of(
List.class, Set.class
Expand Down Expand Up @@ -80,8 +83,12 @@ public CollectionGeneratorBuilder<VALUE, COL> of(Generator<? extends Number> siz
int size = sizeGenerator.apply(randomSequence).intValue();
Set r = new HashSet(size);

for (int i = 0; i < size; i++) {
for (int i = 0; r.size() < size; i++) {
r.add(valueGenerator.generate(randomSequence));

if (i > 10 * size) {
log.warning("Seems we cannot generate a value for the set that doesn't exist yet. Stop trying.");
}
}
return (COL)r;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,28 @@ protected void assertFieldTypeSupported() {

}

public EnumeratedDistributionGeneratorBuilder weights(double... weights) {
public EnumeratedDistributionGeneratorBuilder<CLASS> weights(double... weights) {
this.weights = weights;

return this;
}
public EnumeratedDistributionGeneratorBuilder weights(long... weights) {
public EnumeratedDistributionGeneratorBuilder<CLASS> weights(long... weights) {
this.weights = Arrays.stream(weights).mapToDouble(l -> (double)l).toArray();

return this;
}


public EnumeratedDistributionGeneratorBuilder values(CLASS... values) {
public EnumeratedDistributionGeneratorBuilder<CLASS> values(CLASS... values) {
this.values = values;

return this;
}
public EnumeratedDistributionGeneratorBuilder from(Frequency frequency) {
public EnumeratedDistributionGeneratorBuilder<CLASS> from(Frequency frequency) {
return from(frequency, v -> (CLASS) v);
}

public <K extends Comparable<K>>EnumeratedDistributionGeneratorBuilder from(Frequency frequency, final Function<K, CLASS> keyToValueMapper) {
public <K extends Comparable<K>> EnumeratedDistributionGeneratorBuilder<CLASS> from(Frequency frequency, final Function<K, CLASS> keyToValueMapper) {
final int size = frequency.getUniqueCount();
this.values = (CLASS[]) new Object[size];
this.weights = new double[size];
Expand All @@ -133,17 +133,17 @@ public <K extends Comparable<K>>EnumeratedDistributionGeneratorBuilder from(Freq
}


public EnumeratedDistributionGeneratorBuilder valuesFromCSVResource(String resource) {
public EnumeratedDistributionGeneratorBuilder<CLASS> valuesFromCSVResource(String resource) {
return valuesFromCSVResource(resource, v -> (CLASS) v);
}

public EnumeratedDistributionGeneratorBuilder valuesFromCSVResource(String resource, final Function<String, CLASS> keyToValueMapper) {
public EnumeratedDistributionGeneratorBuilder<CLASS> valuesFromCSVResource(String resource, final Function<String, CLASS> keyToValueMapper) {
final Frequency frequency = DistributionUtils.fromCsvResource(resource);

return from(frequency, keyToValueMapper);
}

public EnumeratedDistributionGeneratorBuilder generators(AbstractGeneratorBuilder<? extends CLASS>... values) {
public EnumeratedDistributionGeneratorBuilder<CLASS> generators(AbstractGeneratorBuilder<? extends CLASS>... values) {
this.valueBuilders = values;

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ public void initialize() {
.weights(1, 2)
.build();


// configure the generators of relations
final Generator<Relation> relationGenerator = aBean(Relation.class)
.injectIdIn("id") // we don't generate the list of persons as we will have to memoize it because it is state dependent
.build();
final Generator<UpdateOf<Relation>> relationUpdateGenerator = enumerated(UpdateOf.class)
final Generator<UpdateOf> relationUpdateGenerator = enumerated(UpdateOf.class)
.generators(
aBean(JoinRelationCommand.class), // we don't generate the added person as we will have to memoize it because it is state dependent
aBean(LeaveRelationCommand.class).with("index", aInteger().uniform(0, 1000)))
Expand Down
Empty file modified gradlew
100755 → 100644
Empty file.

0 comments on commit 9216d52

Please sign in to comment.