1 /*
2 * SPDX-FileCopyrightText: none
3 * SPDX-License-Identifier: CC0-1.0
4 */
5
6 package gov.nist.secauto.metaschema.core.metapath.item;
7
8 import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
9 import gov.nist.secauto.metaschema.core.metapath.ICollectionValue;
10 import gov.nist.secauto.metaschema.core.metapath.ISequence;
11
12 import java.util.stream.Stream;
13
14 import edu.umd.cs.findbugs.annotations.NonNull;
15
16 public interface IItem extends ICollectionValue {
17
18 /**
19 * Get the item's "wrapped" value. This "wrapped" value may be:
20 * <ul>
21 * <li>In the case of an Assembly, a Java object representing the fields and
22 * flags of the assembly.</li>
23 * <li>In the case of a Field with flags, a Java object representing the field
24 * value and flags of the field.
25 * <li>In the case of a Field without flags or a flag, a Java type managed by a
26 * {@link IDataTypeAdapter} or a primitive type provided by the Java standard
27 * library.
28 * </ul>
29 *
30 * @return the value or {@code null} if the item has no available value
31 */
32 Object getValue();
33
34 /**
35 * Determine if the item has an associated value.
36 *
37 * @return {@code true} if the item has a non-{@code null} value or
38 * {@code false} otherwise
39 */
40 default boolean hasValue() {
41 return getValue() != null;
42 }
43
44 @Override
45 default ISequence<?> asSequence() {
46 return ISequence.of(this);
47 }
48
49 @SuppressWarnings("null")
50 @Override
51 default Stream<? extends IItem> flatten() {
52 return Stream.of(this);
53 }
54
55 /**
56 * A visitor callback used to visit a variety of Metapath item types.
57 *
58 * @param visitor
59 * the visitor to call back
60 */
61 void accept(@NonNull IItemVisitor visitor);
62 }