+ public static LeafListEffectiveStatement copyLeafList(final LeafListEffectiveStatement original,
+ final QName argument, final int flags, final @Nullable LeafListSchemaNode newOriginal) {
+ if (original instanceof RegularLeafListEffectiveStatement) {
+ return new RegularLeafListEffectiveStatement((RegularLeafListEffectiveStatement) original, newOriginal,
+ argument, flags);
+ } else if (original instanceof SlimLeafListEffectiveStatement) {
+ return new SlimLeafListEffectiveStatement((SlimLeafListEffectiveStatement) original, newOriginal, argument,
+ flags);
+ } else if (original instanceof EmptyLeafListEffectiveStatement) {
+ // Promote to slim
+ return new SlimLeafListEffectiveStatement((EmptyLeafListEffectiveStatement) original, newOriginal, argument,
+ flags);
+ } else {
+ throw new IllegalArgumentException("Unsupported original " + original);
+ }
+ }
+
+ public static LeafListEffectiveStatement createLeafList(final LeafListStatement declared, final QName argument,
+ final int flags, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
+ final ImmutableSet<String> defaultValues, final @Nullable ElementCountConstraint elementCountConstraint,
+ final @Nullable LeafListSchemaNode original)
+ throws SubstatementIndexingException {
+ if (defaultValues.isEmpty()) {
+ return original == null && elementCountConstraint == null
+ ? new EmptyLeafListEffectiveStatement(declared, argument, flags, substatements)
+ : new SlimLeafListEffectiveStatement(declared, argument, flags, substatements, original,
+ elementCountConstraint);
+ }
+
+ return new RegularLeafListEffectiveStatement(declared, argument, flags, substatements, original, defaultValues,
+ elementCountConstraint);
+ }
+