Skip to content

Commit

Permalink
Fixed ordering of generated flag fields. They will now be ordered in …
Browse files Browse the repository at this point in the history
…the order in which they are declared in the Metaschema module.
  • Loading branch information
david-waltermire committed Nov 25, 2023
1 parent 8f31e4d commit 8ce09fc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import gov.nist.secauto.metaschema.databind.codegen.typeinfo.ITypeResolver;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -74,12 +76,16 @@ protected boolean initInstanceTypeInfos() {
boolean retval;
if (flagTypeInfos == null) {
// create Java properties for the definition's flags
flagTypeInfos = getDefinition().getFlagInstances().stream()
flagTypeInfos = Collections.unmodifiableMap(getDefinition().getFlagInstances().stream()
.map(instance -> {
assert instance != null;
return newFlagTypeInfo(instance);
})
.collect(Collectors.toUnmodifiableMap(IFlagInstanceTypeInfo::getPropertyName, Function.identity()));
.collect(Collectors.toMap(
IFlagInstanceTypeInfo::getPropertyName,
Function.identity(),
(v1, v2) -> v2,
LinkedHashMap::new)));
retval = true;
} else {
retval = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ protected void readFlagInstances(
@NonNull StartElement start) throws IOException, XMLStreamException {

Map<QName, IBoundFlagInstance> flagInstanceMap = targetDefinition.getFlagInstances().stream()
.collect(Collectors.toMap(IBoundFlagInstance::getXmlQName, Function.identity()));
.collect(Collectors.toMap(
IBoundFlagInstance::getXmlQName,
Function.identity()));

for (Attribute attribute : CollectionUtil.toIterable(ObjectUtils.notNull(start.getAttributes()))) {
QName qname = attribute.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ public ChoiceGroupInstance(
this)));
this.classToInstanceMap = ObjectUtils.notNull(Lazy.lazy(() -> Collections.unmodifiableMap(
getModelInstances().stream()
.collect(CustomCollectors.toMap(item -> item.getDefinition().getBoundClass(), CustomCollectors.identity(),
.collect(CustomCollectors.toMap(
item -> item.getDefinition().getBoundClass(),
CustomCollectors.identity(),
(key, vOld, vNew) -> vNew)))));
this.qnameToInstanceMap = ObjectUtils.notNull(Lazy.lazy(() -> Collections.unmodifiableMap(
getModelInstances().stream()
.collect(CustomCollectors.toMap(item -> item.getXmlQName(), CustomCollectors.identity(),
.collect(CustomCollectors.toMap(
item -> item.getXmlQName(),
CustomCollectors.identity(),
(key, vOld, vNew) -> vNew)))));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package gov.nist.secauto.metaschema.databind.model.impl;

import gov.nist.secauto.metaschema.core.model.IFlagContainerSupport;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.model.IBoundFlagInstance;
import gov.nist.secauto.metaschema.databind.model.IClassBinding;
Expand All @@ -36,6 +37,7 @@
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -76,11 +78,13 @@ public FlagContainerSupport(
intermediate = intermediate.andThen(peeker);
}

this.flagInstances = ObjectUtils.notNull(instances
this.flagInstances = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(instances
.peek(intermediate)
.collect(Collectors.toUnmodifiableMap(
.collect(Collectors.toMap(
IBoundFlagInstance::getEffectiveName,
Function.identity())));
Function.identity(),
(v1, v2) -> v2,
LinkedHashMap::new))));
}

private void handle(IBoundFlagInstance instance) {
Expand Down

0 comments on commit 8ce09fc

Please sign in to comment.