Package eu.bandm.tools.ramus.ogma
Interface Data
public interface Data
Interface of wrappers for semantic data.
There is no need for client code to deal with concrete subclasses.
Wrapping and unwrapping are performed behind the scenes, by semantic parser
actions and abstract accessors of type Data.View, respectively.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFunctional interface for unwrapping interpretation of semantic data.static classA placeholder for a view that can be initialized late. -
Method Summary
Modifier and TypeMethodDescriptiondefault DataAdds an element to a list.asList()Unwraps a list to its elements.static DataWraps an atomic value.static <D,T> Data Wraps a copy of a lexical token.static <D,T> Data Wraps a lexical token.default <A> DataTransforms a wrapped atomic value with a given function.default Dataget()Returns the present content of an optional value.Returns the source code location of a wrapped token.default intReturns the tag index of a tagged value.default intReturns the total number of choices of a tagged value.default StringgetText()Returns the text content of a wrapped token.default ObjectgetType()Returns the token type of a wrapped token.default ObjectgetValue()Returns the atomic value wrapped by this data value.default <A> AgetValueAs(Class<A> type) Returns the atomic value wrapped by this data value if of the expected type.default booleanisAtomic()Checks whether this data value wraps an atomic value.default booleanChecks whether this data value wraps an atomic value of the given type.default booleanChecks whether this data value wraps a lexical token.default booleanChecks whether this data value is optional.default booleanisPair()Checks whether this data value is a pair.default booleanChecks whether an optional value is present.default booleanChecks whether this data value is a sequence.default booleanisTagged()Checks whether this data value is tagged.default booleanisTagged(int expectedTotal) Checks whether this data value is tagged out of a given total number of choices.static DataMarks a value as optional and present.default <A,B> Data Transforms a wrapped atomic value with a given function.static Datanone()Returns an empty optional value.default DataReturns the present content of an optional value or a default.default DataReturns the present content of an optional value or a default.static DataCombines two data elements into a pair.static DataCombines zero or more data elements into a sequence.static UnaryOperator<Data> tag(int index, int total) Returns a function that marks values with a numerical tag.static DataMarks a value with a numerical tag.default Datauntag()Returns the content of a tagged value.default Datauntag(int expectedTotal) Returns the content of a tagged value out of the given number of choices.
-
Method Details
-
atomic
Wraps an atomic value.- Parameters:
value- the value- Returns:
- a wrapper around
value
-
content
Wraps a copy of a lexical token.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
token- the token- Returns:
- a wrapped copy of
token - Throws:
NullPointerException- iftokenis null
-
content
Wraps a lexical token.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
location- the source code location, ornullif not availabletext- the text contenttype- the token type- Returns:
- a wrapped token
- Throws:
NullPointerException- iftextortypeis null
-
sequence
Combines zero or more data elements into a sequence.- Parameters:
elems- the elements- Returns:
- a sequence containing all of
elems - Throws:
NullPointerException- ifelemsis null
-
pair
Combines two data elements into a pair.- Parameters:
left- the left elementright- the right element- Returns:
- a pair containing
leftandright - Throws:
NullPointerException- ifleftorrightis null
-
just
Marks a value as optional and present.- Parameters:
value- the content value- Returns:
- an optional and present wrapper
-
none
Returns an empty optional value.- Returns:
- a value that does not contain data
-
tag
Marks a value with a numerical tag.Tags are nonnegative indices out of a specified number of choices.
- Parameters:
index- the tag indextotal- the total number of choicesvalue- the content value- Returns:
- a value tagged as
indexout oftotal - Throws:
IllegalArgumentException- ifindex < 0ortotal < 0, or ifindex >= total.
-
tag
Returns a function that marks values with a numerical tag.Tags are nonnegative indices out of a specified number of choices.
- Parameters:
index- the tag indextotal- the total number of choices- Returns:
- a function that tags values as
indexout oftotal - Throws:
IllegalArgumentException- ifindex < 0ortotal < 0, or ifindex >= total.- See Also:
-
isSequence
default boolean isSequence()Checks whether this data value is a sequence.- Returns:
trueif this data value is a sequence;falseotherwise- See Also:
-
isAtomic
default boolean isAtomic()Checks whether this data value wraps an atomic value.- Returns:
trueif this data value wraps an atomic value;falseotherwise- See Also:
-
isAtomic
Checks whether this data value wraps an atomic value of the given type.- Parameters:
type- the expected type- Returns:
trueif this data value wraps an atomic value of typetype;falseotherwise- Throws:
NullPointerException- iftypeis null- See Also:
-
isContent
default boolean isContent()Checks whether this data value wraps a lexical token.- Returns:
trueif this data value wraps a lexical token;falseotherwise- See Also:
-
isPair
default boolean isPair()Checks whether this data value is a pair.- Returns:
trueif this data value is a pair;falseotherwise- See Also:
-
isTagged
default boolean isTagged()Checks whether this data value is tagged.- Returns:
trueif this data value is tagged;falseotherwise- See Also:
-
isTagged
default boolean isTagged(int expectedTotal) Checks whether this data value is tagged out of a given total number of choices.- Parameters:
expectedTotal- the expected total number of choices- Returns:
trueif this data value is tagged and its total number of choices is equal toexpectedTotal;falseotherwise- See Also:
-
isOptional
default boolean isOptional()Checks whether this data value is optional.- Returns:
trueif this data value is optional;falseotherwise- See Also:
-
getValueAs
Returns the atomic value wrapped by this data value if of the expected type.- Type Parameters:
A- the expected type- Parameters:
type- the expected type- Returns:
- the unwrapped atomic value
- Throws:
UnsupportedOperationException- if this data value does not wrap an atomic valueClassCastException- if the unwrapped value is not of the expected typeNullPointerException- iftypeis null
-
getValue
Returns the atomic value wrapped by this data value.- Returns:
- the unwrapped atomic value
- Throws:
UnsupportedOperationException- if this data value does not wrap an atomic value
-
mapAs
Transforms a wrapped atomic value with a given function.- Type Parameters:
A- the expected typeB- the result type- Parameters:
type- the expected typefun- a function that maps the wrapped atomic value to another atomic value- Returns:
- the wrapped result of mapping the wrapped atomic value
- Throws:
UnsupportedOperationException- if this data value does not wrap an atomic valueClassCastException- if the unwrapped value is not of the expected typeNullPointerException- iftypeorfunis null
-
flatMapAs
Transforms a wrapped atomic value with a given function.- Type Parameters:
A- the expected type- Parameters:
type- the expected typefun- a function that maps the wrapped atomic value to some arbitrary value- Returns:
- the result of mapping the wrapped atomic value
- Throws:
UnsupportedOperationException- if this data value does not wrap an atomic valueClassCastException- if the unwrapped value is not of the expected typeNullPointerException- iftypeorfunis null
-
add
Adds an element to a list.- Parameters:
elem- the element to add- Returns:
- a new list containing all elements of this list followed by
elem - Throws:
UnsupportedOperationException- if this value is not a list
-
asList
Unwraps a list to its elements.- Returns:
- the elements of this data value if it is a list
- Throws:
UnsupportedOperationException- if this value is not a list
-
getTagIndex
default int getTagIndex()Returns the tag index of a tagged value.- Returns:
- the tag index of this data value if it is tagged
- Throws:
UnsupportedOperationException- if this value is not tagged
-
getTagTotal
default int getTagTotal()Returns the total number of choices of a tagged value.- Returns:
- the total number of choices of this data value if it is tagged
- Throws:
UnsupportedOperationException- if this value is not tagged
-
untag
Returns the content of a tagged value.- Returns:
- the content of this data value if it is tagged
- Throws:
UnsupportedOperationException- if this value is not tagged
-
untag
Returns the content of a tagged value out of the given number of choices.- Parameters:
expectedTotal- the expected total number of choices- Returns:
- the content of this data value if it is tagged and its total number
of choices is equal to
expectedTotal - Throws:
UnsupportedOperationException- if this value is not taggedIllegalArgumentException- if this value is tagged but its total number of choices is not equal toexpectedTotal
-
getLocation
Returns the source code location of a wrapped token.- Returns:
- the source code location of the wrapped token, or
nullif not available - Throws:
UnsupportedOperationException- if this data value does not wrap a token
-
getText
Returns the text content of a wrapped token.- Returns:
- the text content of the wrapped token
- Throws:
UnsupportedOperationException- if this data value does not wrap a token
-
getType
Returns the token type of a wrapped token.- Returns:
- the token type of the wrapped token
- Throws:
UnsupportedOperationException- if this data value does not wrap a token
-
isPresent
default boolean isPresent()Checks whether an optional value is present.- Returns:
trueif this value is optional and present;falseif this value is optional and absent- Throws:
UnsupportedOperationException- if this value is not optional
-
get
Returns the present content of an optional value.- Returns:
- the content if this value is optional and present
- Throws:
UnsupportedOperationException- if this value is not optionalNoSuchElementException- if this value is optional but absent
-
orElse
Returns the present content of an optional value or a default.- Parameters:
defaultValue- the default value to stand for absence- Returns:
- the content if this value is optional and present;
defaultValueif this value is optional and absent - Throws:
UnsupportedOperationException- if this value is not optional
-
orElseGet
Returns the present content of an optional value or a default.- Parameters:
defaultValue- an operation that either supplies the default value to stand for absence or throwsNoSuchElementException- Returns:
- the content if this value is optional and present; the result of
defaultValue.get()if this value is optional and absent - Throws:
UnsupportedOperationException- if this value is not optionalNullPointerException- ifdefaultValueis null
-