Skip to content

Commit d2f1aad

Browse files
Implemented the map:contains Metapath function. Cleaned up a bunch of PMD warnings.
1 parent c00dc46 commit d2f1aad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+447
-247
lines changed

core/src/main/java/gov/nist/secauto/metaschema/core/datatype/markup/flexmark/impl/AbstractMarkupWriter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@
6363
import com.vladsch.flexmark.util.sequence.BasedSequence;
6464
import com.vladsch.flexmark.util.sequence.Escaping;
6565

66-
import gov.nist.secauto.metaschema.core.datatype.markup.flexmark.IMarkupWriter;
6766
import gov.nist.secauto.metaschema.core.datatype.markup.flexmark.HtmlQuoteTagExtension.DoubleQuoteNode;
68-
import gov.nist.secauto.metaschema.core.datatype.markup.flexmark.IMarkupWriter.ChildHandler;
67+
import gov.nist.secauto.metaschema.core.datatype.markup.flexmark.IMarkupWriter;
6968
import gov.nist.secauto.metaschema.core.datatype.markup.flexmark.InsertAnchorExtension.InsertAnchorNode;
7069
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
7170
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ default ICollectionValue toCollectionValue() {
158158
ICollectionValue retval;
159159
switch (size()) {
160160
case 0:
161-
retval = ISequence.empty();
161+
retval = empty();
162162
break;
163163
case 1:
164164
retval = ObjectUtils.notNull(stream().findFirst().get());
@@ -254,23 +254,6 @@ static <T extends R, R extends IItem> ISequence<R> map(
254254
.collect(toSequence());
255255
}
256256

257-
/**
258-
* Returns an unmodifiable sequence containing the provided {@code item}.
259-
* <p>
260-
* If the item is {@code null} and empty sequence will be created.
261-
*
262-
* @param <T>
263-
* the type of items contained in the sequence.
264-
* @param item
265-
* the item to add to the sequence
266-
* @return the new sequence
267-
*/
268-
@NonNull
269-
static <T extends IItem> ISequence<T> of( // NOPMD - intentional
270-
@Nullable T item) {
271-
return item == null ? empty() : new SingletonSequence<>(item);
272-
}
273-
274257
/**
275258
* Returns an unmodifiable sequence containing the provided {@code items}.
276259
*
@@ -294,6 +277,23 @@ static <ITEM_TYPE extends IItem> ISequence<ITEM_TYPE> ofCollection( // NOPMD - i
294277
return retval;
295278
}
296279

280+
/**
281+
* Returns an unmodifiable sequence containing the provided {@code item}.
282+
* <p>
283+
* If the item is {@code null} and empty sequence will be created.
284+
*
285+
* @param <T>
286+
* the type of items contained in the sequence.
287+
* @param item
288+
* the item to add to the sequence
289+
* @return the new sequence
290+
*/
291+
@NonNull
292+
static <T extends IItem> ISequence<T> of( // NOPMD - intentional
293+
@Nullable T item) {
294+
return item == null ? empty() : new SingletonSequence<>(item);
295+
}
296+
297297
/**
298298
* Returns an unmodifiable sequence containing the provided {@code items}.
299299
*
@@ -305,9 +305,8 @@ static <ITEM_TYPE extends IItem> ISequence<ITEM_TYPE> ofCollection( // NOPMD - i
305305
*/
306306
// TODO: remove null check on callers
307307
@NonNull
308-
static <T extends IItem> ISequence<T> of( // NOPMD - intentional
309-
Stream<T> items) {
310-
return items == null ? empty() : new StreamSequence<>(items);
308+
static <T extends IItem> ISequence<T> of(@NonNull Stream<T> items) {
309+
return new StreamSequence<>(items);
311310
}
312311

313312
/**

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/InvalidTypeMetapathException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class InvalidTypeMetapathException
5656
* the original exception cause
5757
*/
5858
public InvalidTypeMetapathException(@NonNull IItem item, @NonNull Throwable cause) {
59-
super(TypeMetapathException.INVALID_TYPE_ERROR, String.format("Invalid data type '%s'", item.getClass().getName()),
59+
super(INVALID_TYPE_ERROR, String.format("Invalid data type '%s'", item.getClass().getName()),
6060
cause);
6161
this.item = item;
6262
}
@@ -69,7 +69,7 @@ public InvalidTypeMetapathException(@NonNull IItem item, @NonNull Throwable caus
6969
* the item related to the invalid type error
7070
*/
7171
public InvalidTypeMetapathException(@NonNull IItem item) {
72-
super(TypeMetapathException.INVALID_TYPE_ERROR, String.format("Invalid data type '%s'", item.getClass().getName()));
72+
super(INVALID_TYPE_ERROR, String.format("Invalid data type '%s'", item.getClass().getName()));
7373
this.item = item;
7474
}
7575

@@ -85,7 +85,7 @@ public InvalidTypeMetapathException(@NonNull IItem item) {
8585
* the original exception cause
8686
*/
8787
public InvalidTypeMetapathException(@Nullable IItem item, @Nullable String message, @NonNull Throwable cause) {
88-
super(TypeMetapathException.INVALID_TYPE_ERROR, message, cause);
88+
super(INVALID_TYPE_ERROR, message, cause);
8989
this.item = item;
9090
}
9191

@@ -99,7 +99,7 @@ public InvalidTypeMetapathException(@Nullable IItem item, @Nullable String messa
9999
* the exception message
100100
*/
101101
public InvalidTypeMetapathException(@Nullable IItem item, @Nullable String message) {
102-
super(TypeMetapathException.INVALID_TYPE_ERROR, message);
102+
super(INVALID_TYPE_ERROR, message);
103103
this.item = item;
104104
}
105105

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/antlr/AbstractAstVisitor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -884,12 +884,6 @@ public R visitArrayconstructor(ArrayconstructorContext ctx) {
884884
*/
885885
protected abstract R handleArrayConstructor(@NonNull SquarearrayconstructorContext ctx);
886886

887-
@Override
888-
public R visitSquarearrayconstructor(SquarearrayconstructorContext ctx) {
889-
assert ctx != null;
890-
return handleArrayConstructor(ctx);
891-
}
892-
893887
/**
894888
* Handle the provided expression.
895889
*
@@ -899,6 +893,12 @@ public R visitSquarearrayconstructor(SquarearrayconstructorContext ctx) {
899893
*/
900894
protected abstract R handleArrayConstructor(@NonNull CurlyarrayconstructorContext ctx);
901895

896+
@Override
897+
public R visitSquarearrayconstructor(SquarearrayconstructorContext ctx) {
898+
assert ctx != null;
899+
return handleArrayConstructor(ctx);
900+
}
901+
902902
@Override
903903
public R visitCurlyarrayconstructor(CurlyarrayconstructorContext ctx) {
904904
assert ctx != null;

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractCSTVisitorBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public IExpression visit(ParseTree tree) {
133133

134134
@Nullable
135135
protected <CONTEXT extends ParserRuleContext, T extends IExpression, R extends IExpression>
136-
R nAiryToCollection(
136+
R nairyToCollection(
137137
@NonNull CONTEXT context,
138138
int startIndex,
139139
int step,

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* @param <CONTEXT>
5959
* additional state to pass between nodes visited
6060
*/
61-
@SuppressWarnings("PMD.CouplingBetweenObjects")
61+
@SuppressWarnings({ "PMD.CouplingBetweenObjects", "PMD.ExcessivePublicCount" })
6262
public abstract class AbstractExpressionVisitor<RESULT, CONTEXT> implements IExpressionVisitor<RESULT, CONTEXT> {
6363

6464
/**

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ protected MapConstructor handleMapConstructor(MapconstructorContext context) {
277277
// empty
278278
? new MapConstructor(CollectionUtil.emptyList())
279279
// with members
280-
: nAiryToCollection(context, 3, 2,
280+
: nairyToCollection(context, 3, 2,
281281
(ctx, idx) -> {
282282
int pos = (idx - 3) / 2;
283283
MapconstructorentryContext entry = ctx.mapconstructorentry(pos);
@@ -300,7 +300,7 @@ protected IExpression handleArrayConstructor(SquarearrayconstructorContext conte
300300
// empty
301301
? new ArraySquareConstructor(CollectionUtil.emptyList())
302302
// with members
303-
: nAiryToCollection(context, 1, 2,
303+
: nairyToCollection(context, 1, 2,
304304
(ctx, idx) -> {
305305
int pos = (idx - 1) / 2;
306306
ParseTree tree = ctx.exprsingle(pos);

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public static String toString(@NonNull IExpression expr) {
6666
return new CSTPrinterVisitor().visit(expr);
6767
}
6868

69+
@SuppressWarnings("PMD.ExcessivePublicCount")
6970
private static final class CSTPrinterVisitor
7071
extends AbstractExpressionVisitor<String, State> {
7172

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/IExpressionVisitor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
* @param <CONTEXT>
5959
* additional state to pass between nodes visited
6060
*/
61+
@SuppressWarnings("PMD.ExcessivePublicCount")
6162
public interface IExpressionVisitor<RESULT, CONTEXT> {
6263

6364
/**

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DefaultFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ protected static ISequence<?> convertSequence(@NonNull IArgument argument, @NonN
284284
Stream<? extends IItem> stream = sequence.safeStream();
285285

286286
if (IAnyAtomicItem.class.isAssignableFrom(requiredSequenceTypeClass)) {
287-
Stream<? extends IAnyAtomicItem> atomicStream = stream.flatMap(item -> FnData.atomize(item));
287+
Stream<? extends IAnyAtomicItem> atomicStream = stream.flatMap(FnData::atomize);
288288

289289
// if (IUntypedAtomicItem.class.isInstance(item)) { // NOPMD
290290
// // TODO: apply cast to atomic type

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/InvalidValueForCastFunctionException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class InvalidValueForCastFunctionException
4141
* the exception message
4242
*/
4343
public InvalidValueForCastFunctionException(String message) {
44-
super(InvalidArgumentFunctionException.INVALID_VALUE_FOR_CAST, message);
44+
super(INVALID_VALUE_FOR_CAST, message);
4545
}
4646

4747
/**
@@ -54,7 +54,7 @@ public InvalidValueForCastFunctionException(String message) {
5454
* the original exception cause
5555
*/
5656
public InvalidValueForCastFunctionException(String message, Throwable cause) {
57-
super(InvalidArgumentFunctionException.INVALID_VALUE_FOR_CAST, message, cause);
57+
super(INVALID_VALUE_FOR_CAST, message, cause);
5858
}
5959

6060
/**
@@ -64,7 +64,7 @@ public InvalidValueForCastFunctionException(String message, Throwable cause) {
6464
* the original exception cause
6565
*/
6666
public InvalidValueForCastFunctionException(Throwable cause) {
67-
super(InvalidArgumentFunctionException.INVALID_VALUE_FOR_CAST, cause);
67+
super(INVALID_VALUE_FOR_CAST, cause);
6868
}
6969

7070
}

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayAppend.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
import edu.umd.cs.findbugs.annotations.NonNull;
4444

45-
public class ArrayAppend {
45+
public final class ArrayAppend {
4646
@NonNull
4747
public static final IFunction SIGNATURE = IFunction.builder()
4848
.name("append")
@@ -65,6 +65,10 @@ public class ArrayAppend {
6565
.functionHandler(ArrayAppend::execute)
6666
.build();
6767

68+
private ArrayAppend() {
69+
// disable construction
70+
}
71+
6872
@SuppressWarnings("unused")
6973
@NonNull
7074
private static <T extends ICollectionValue> ISequence<IArrayItem<T>> execute(@NonNull IFunction function,

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayFlatten.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
import edu.umd.cs.findbugs.annotations.NonNull;
4242

43-
public class ArrayFlatten {
43+
public final class ArrayFlatten {
4444
@NonNull
4545
static final IFunction SIGNATURE = IFunction.builder()
4646
.name("flatten")
@@ -58,6 +58,10 @@ public class ArrayFlatten {
5858
.functionHandler(ArrayFlatten::execute)
5959
.build();
6060

61+
private ArrayFlatten() {
62+
// disable construction
63+
}
64+
6165
@SuppressWarnings("unused")
6266
@NonNull
6367
private static ISequence<?> execute(@NonNull IFunction function,

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayGet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import edu.umd.cs.findbugs.annotations.NonNull;
4545

46-
public class ArrayGet {
46+
public final class ArrayGet {
4747
@NonNull
4848
public static final IFunction SIGNATURE = IFunction.builder()
4949
.name("get")
@@ -66,6 +66,10 @@ public class ArrayGet {
6666
.functionHandler(ArrayGet::execute)
6767
.build();
6868

69+
private ArrayGet() {
70+
// disable construction
71+
}
72+
6973
@SuppressWarnings("unused")
7074
@NonNull
7175
private static ISequence<?> execute(@NonNull IFunction function,

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayHead.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import edu.umd.cs.findbugs.annotations.NonNull;
4343
import edu.umd.cs.findbugs.annotations.Nullable;
4444

45-
public class ArrayHead {
45+
public final class ArrayHead {
4646
@NonNull
4747
static final IFunction SIGNATURE = IFunction.builder()
4848
.name("head")
@@ -60,6 +60,10 @@ public class ArrayHead {
6060
.functionHandler(ArrayHead::execute)
6161
.build();
6262

63+
private ArrayHead() {
64+
// disable construction
65+
}
66+
6367
@SuppressWarnings("unused")
6468
@NonNull
6569
private static ISequence<?> execute(@NonNull IFunction function,

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayInsertBefore.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import edu.umd.cs.findbugs.annotations.NonNull;
4545

46-
public class ArrayInsertBefore {
46+
public final class ArrayInsertBefore {
4747
@NonNull
4848
public static final IFunction SIGNATURE = IFunction.builder()
4949
.name("insert-before")
@@ -71,6 +71,10 @@ public class ArrayInsertBefore {
7171
.functionHandler(ArrayInsertBefore::execute)
7272
.build();
7373

74+
private ArrayInsertBefore() {
75+
// disable construction
76+
}
77+
7478
@SuppressWarnings("unused")
7579
@NonNull
7680
private static <T extends ICollectionValue> ISequence<IArrayItem<T>> execute(@NonNull IFunction function,

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayJoin.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import edu.umd.cs.findbugs.annotations.NonNull;
4545

46-
public class ArrayJoin {
46+
public final class ArrayJoin {
4747
@NonNull
4848
public static final IFunction SIGNATURE = IFunction.builder()
4949
.name("join")
@@ -61,6 +61,10 @@ public class ArrayJoin {
6161
.functionHandler(ArrayJoin::execute)
6262
.build();
6363

64+
private ArrayJoin() {
65+
// disable construction
66+
}
67+
6468
@SuppressWarnings("unused")
6569
@NonNull
6670
private static <T extends ICollectionValue> ISequence<? extends IArrayItem<T>> execute(@NonNull IFunction function,
@@ -86,7 +90,7 @@ private static <T extends ICollectionValue> ISequence<? extends IArrayItem<T>> e
8690
public static <T extends ICollectionValue> IArrayItem<T> join(
8791
@NonNull Collection<? extends IArrayItem<T>> arrays) {
8892
return IArrayItem.ofCollection(ObjectUtils.notNull(arrays.stream()
89-
.flatMap(array -> array.stream())
93+
.flatMap(Collection::stream)
9094
.collect(Collectors.toList())));
9195
}
9296
}

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/ArrayPut.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
import edu.umd.cs.findbugs.annotations.NonNull;
4646

47-
public class ArrayPut {
47+
public final class ArrayPut {
4848
@NonNull
4949
public static final IFunction SIGNATURE = IFunction.builder()
5050
.name("put")
@@ -72,6 +72,10 @@ public class ArrayPut {
7272
.functionHandler(ArrayPut::execute)
7373
.build();
7474

75+
private ArrayPut() {
76+
// disable construction
77+
}
78+
7579
@SuppressWarnings("unused")
7680
@NonNull
7781
private static <T extends ICollectionValue> ISequence<? extends IArrayItem<T>> execute(@NonNull IFunction function,

0 commit comments

Comments
 (0)