-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements and cleanup of fluent api implementation
- Loading branch information
kwakeroni
committed
Nov 25, 2017
1 parent
c2bc774
commit 4b3613b
Showing
26 changed files
with
413 additions
and
309 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
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
46 changes: 46 additions & 0 deletions
46
...rc/main/java/be/kwakeroni/parameters/basic/definition/DefaultMappedDefinitionBuilder.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,46 @@ | ||
package be.kwakeroni.parameters.basic.definition; | ||
|
||
import be.kwakeroni.parameters.basic.client.model.Mapped; | ||
import be.kwakeroni.parameters.basic.definition.builder.MappedDefinitionBuilder; | ||
import be.kwakeroni.parameters.client.api.model.EntryType; | ||
import be.kwakeroni.parameters.definition.ext.DefinitionBuilder; | ||
import be.kwakeroni.parameters.definition.ext.DefinitionBuilderFinalizer; | ||
import be.kwakeroni.parameters.definition.ext.PartialDefinition; | ||
import be.kwakeroni.parameters.types.api.ParameterType; | ||
|
||
import java.util.function.Function; | ||
|
||
final /* value */ class DefaultMappedDefinitionBuilder<KeyType, SubType extends EntryType> implements MappedDefinitionBuilder<KeyType, SubType> { | ||
private String keyParameter; | ||
private ParameterType<KeyType> keyType; | ||
private DefinitionBuilder<SubType> subGroup; | ||
|
||
private <NewKeyType, NewSubType extends EntryType> | ||
DefaultMappedDefinitionBuilder<NewKeyType, NewSubType> with(ParameterType<NewKeyType> key, DefinitionBuilder<NewSubType> subGroup) { | ||
DefaultMappedDefinitionBuilder<NewKeyType, NewSubType> self = (DefaultMappedDefinitionBuilder<NewKeyType, NewSubType>) this; | ||
self.keyType = key; | ||
self.subGroup = subGroup; | ||
return self; | ||
} | ||
|
||
@Override | ||
public <NewKeyType> MappedDefinitionBuilder<NewKeyType, SubType> withKeyParameter(String keyParameter, ParameterType<NewKeyType> keyType) { | ||
this.keyParameter = keyParameter; | ||
return with(keyType, subGroup); | ||
} | ||
|
||
@Override | ||
public <NewSubType extends EntryType> MappedDefinitionBuilder<KeyType, NewSubType> mappingTo(DefinitionBuilder<NewSubType> subGroup) { | ||
return with(keyType, subGroup); | ||
} | ||
|
||
@Override | ||
public PartialDefinition<?, Mapped<KeyType, SubType>> createPartialDefinition(String name, Function<DefinitionBuilderFinalizer, DefinitionBuilderFinalizer> theirFinalizer) { | ||
PartialDefinition<?, SubType> subGroupDefinition = subGroup.createPartialDefinition(name, myFinalizer().andThen(theirFinalizer)); | ||
return new DefaultMappedDefinition<>(keyParameter, keyType, subGroupDefinition); | ||
} | ||
|
||
private Function<DefinitionBuilderFinalizer, DefinitionBuilderFinalizer> myFinalizer() { | ||
return builder -> builder.prependParameter(keyParameter); | ||
} | ||
} |
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.