This is the current syntax...
mapOfObjects(Role.class, Contributor.class)
.reference("person", PERSON_SUMMARY_TEMPLATE)
.arrayOfObjects("credits")
.reference("responsibleOrganization", ORG_SUMMARY_TEMPLATE)
.value("percentCredit")
.end()
What if we separate the method that specifies a collection (e.g. array or map) from the thing it contains? For example, we could have a syntax like this...
map(Role.class)
.object(Contributor.class)
.reference("person", PERSON_SUMMARY_TEMPLATE)
.array("credits")
.object(Credit.class)
.reference("responsibleOrganization", ORG_SUMMARY_TEMPLATE)
.value("percentCredit")
.end()
The map
and array
methods create a builder that has a just a few methods on it.
interface CollectionBuilder {
CollectionBuilder map(...);
CollectionBuilder array(...);
ViewTemplateBuilder object(...);
ViewTemplateBuilder value(...);
}
The cool new thing this approach allows is collection composition.
map(Role.class)
.array()
.object(Contributor.class)
.reference("person", PERSON_SUMMARY_TEMPLATE)
.array("credits")
.object(Credit.class)
.reference("responsibleOrganization", ORG_SUMMARY_TEMPLATE)
.value("percentCredit")
.end()
So I can have a map whose entries are arrays, or an array of arrays, or an array of maps, etc.