-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements on the DSL and remove some unexpected methods from it. (#15
- Loading branch information
Cael
authored
Nov 21, 2018
1 parent
ac7e246
commit fee08e5
Showing
13 changed files
with
317 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/uk/co/caeldev/builder4test/ElementListBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package uk.co.caeldev.builder4test; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
public class ElementListBuilder<K> { | ||
|
||
private final Creator<K> creator; | ||
private final List<Map<Field, Optional>> elements; | ||
|
||
private ElementListBuilder(Creator<K> creator) { | ||
this.creator = creator; | ||
this.elements = new ArrayList<>(); | ||
} | ||
|
||
public static <K> ElementListBuilder<K> elementListBuilder(Creator<K> creator) { | ||
return new ElementListBuilder<>(creator); | ||
} | ||
|
||
public ElementBuilder<K> element() { | ||
ElementBuilder<K> elementBuilder = ElementBuilder.elementBuilder(this); | ||
this.elements.add(elementBuilder.getFields()); | ||
return elementBuilder; | ||
} | ||
|
||
public List<K> get() { | ||
|
||
if (elements.isEmpty()) { | ||
return Lists.newArrayList(EntityBuilder.entityBuilder(creator).get()); | ||
} | ||
|
||
return elements.stream() | ||
.filter(it -> it.size() != 0) | ||
.map(it -> EntityBuilder.entityBuilder(creator, it).get()) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,22 @@ | ||
package uk.co.caeldev.builder4test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
public class ListBuilder<K> { | ||
|
||
private final Creator<K> creator; | ||
private final List<Map<Field, Optional>> elements; | ||
|
||
private ListBuilder(Creator<K> creator) { | ||
this.creator = creator; | ||
this.elements = new ArrayList<>(); | ||
} | ||
|
||
protected static <K> ListBuilder<K> listBuilder(Creator<K> creator) { | ||
return new ListBuilder<>(creator); | ||
} | ||
|
||
public ElementBuilder<K> element() { | ||
ElementBuilder<K> elementBuilder = ElementBuilder.elementBuilder(this); | ||
this.elements.add(elementBuilder.getFields()); | ||
return elementBuilder; | ||
} | ||
|
||
public List<K> get() { | ||
return elements.stream() | ||
.filter(it -> it.size() != 0) | ||
.map(it -> EntityBuilder.entityBuilder(creator, it).get()) | ||
.collect(Collectors.toList()); | ||
public ElementListBuilder<K> elements() { | ||
return ElementListBuilder.elementListBuilder(creator); | ||
} | ||
|
||
public RandomListBuilder<K> size(int size) { | ||
return RandomListBuilder.randomListBuilder(size, creator); | ||
public FixedSizeListBuilder<K> size(int size) { | ||
return FixedSizeListBuilder.fixedSizeListBuilder(size, creator); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package uk.co.caeldev.builder4test; | ||
|
||
public interface LookUp { | ||
public abstract class LookUp { | ||
|
||
<V> void put(Field<V> field, V value); | ||
protected abstract <V> void put(Field<V> field, V value); | ||
|
||
<V> V get(Field<V> field); | ||
public abstract <V> V get(Field<V> field); | ||
|
||
<V> V get(Field<V> field, V defaultValue); | ||
public abstract <V> V get(Field<V> field, V defaultValue); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.