public final class Values extends Object
PropertyValue
s and Term
s.
This allows you to extract specific Term
instances from a given PropertyValue
if that Term
is the only
member within the list.
Examples:
Optional<HexColorValue> color = Values.asHexColor(declaration.propertyValue())
Optional<KeywordValue> keyword = Values.asKeyword(declaration.propertyValue())
Optional<NumericalValue> number = Values.asNumerical(declaration.propertyValue())
Modifier and Type | Method and Description |
---|---|
static <T extends Term> |
as(Class<T> klass,
PropertyValue value)
Helper method to convert or extract the more narrowly-typed
Term instance. |
static Optional<HexColorValue> |
asHexColor(PropertyValue value)
Gets the single
HexColorValue within the given PropertyValue . |
static Optional<KeywordValue> |
asKeyword(PropertyValue value)
Gets the single
KeywordValue within the given PropertyValue . |
static Optional<Keyword> |
asKeywordConstant(PropertyValue value)
Same as
asKeyword(PropertyValue) , except this returns the specific Keyword enum value (not the syntax unit). |
static Optional<NumericalValue> |
asNumerical(PropertyValue value)
Gets the single
NumericalValue within the given PropertyValue . |
static Optional<StringValue> |
asString(PropertyValue value)
Gets the single
StringValue within the given PropertyValue . |
static <T extends Term> |
filter(Class<T> klass,
PropertyValue value)
Filters the terms in the given
PropertyValue to only the ones of the given class type. |
static PropertyValue |
join(OperatorType operatorType,
Iterable<PropertyValue> toJoin)
Joins multiple
PropertyValue s together with the given OperatorType . |
static List<PropertyValue> |
split(OperatorType operatorType,
PropertyValue value)
Splits the
PropertyValue at the given operator. |
public static Optional<HexColorValue> asHexColor(PropertyValue value)
HexColorValue
within the given PropertyValue
. The returned Optional
will only be
present if the given property value contains only one Term
which is an instance of a HexColorValue
.
This allows you to work with HexColorValue
specific methods when getting a Declaration
's property value.
Example:
HexColorValue color = Value.asHexColor(declaration.getPropertyValue())
value
- The value.Optional
if the PropertyValue
doesn't match the conditions as
stated above.public static Optional<KeywordValue> asKeyword(PropertyValue value)
KeywordValue
within the given PropertyValue
. The returned Optional
will only be
present if the given property value contains only one Term
which is an instance of a KeywordValue
.
This allows you to work with KeywordValue
specific methods when getting a Declaration
's property value.
Example:
KeywordValue keyword = Value.asKeyword(declaration.getPropertyValue())
value
- The value.Optional
if the PropertyValue
doesn't match the conditions as stated
above.public static Optional<Keyword> asKeywordConstant(PropertyValue value)
asKeyword(PropertyValue)
, except this returns the specific Keyword enum value (not the syntax unit).
Gets the single Keyword
(from a single KeywordValue
) within the given PropertyValue
. The returned
Optional
will only be present if the given property value contains only one Term
which is an instance of a
KeywordValue
and has a recognized keyword.
Example:
Keyword keyword = Value.asKeywordEnum(declaration.getPropertyValue())
value
- The value.Optional
if the PropertyValue
doesn't match the conditions as stated
above.public static Optional<NumericalValue> asNumerical(PropertyValue value)
NumericalValue
within the given PropertyValue
. The returned Optional
will only be
present if the given property value contains only one Term
which is an instance of a NumericalValue
.
This allows you to work with NumericalValue
specific methods when getting a Declaration
's property value.
Example:
NumericalValue number = Value.asNumerical(declaration.getPropertyValue())
value
- The value.Optional
if the PropertyValue
doesn't match the conditions as
stated above.public static Optional<StringValue> asString(PropertyValue value)
StringValue
within the given PropertyValue
. The returned Optional
will only be
present if the given property value contains only one Term
which is an instance of a StringValue
.
This allows you to work with StringValue
specific methods when getting a Declaration
's property value.
Example:
StringValue string = Value.asString(declaration.getPropertyValue())
value
- The value.Optional
if the PropertyValue
doesn't match the conditions as stated
above.public static <T extends Term> Optional<T> as(Class<T> klass, PropertyValue value)
Term
instance.T
- The type of Term
.klass
- Class of the Term
.value
- The PropertyValue
that is or contains the Term
.Optional
if it doesn't match.public static <T extends Term> Iterable<T> filter(Class<T> klass, PropertyValue value)
PropertyValue
to only the ones of the given class type.
Example:
Iterable<FunctionValue> functions = Values.filter(FunctionValue.class, declaration.propertyValue()
T
- Filters to terms of this type.klass
- Filter to terms of this class.value
- The PropertyValue
to filter.public static List<PropertyValue> split(OperatorType operatorType, PropertyValue value)
PropertyValue
at the given operator.
For example, given a PropertyValue
with the following:
{Term}{SPACE}{Term}{SLASH}{Term}{SPACE}{Term}Calling this method with
OperatorType.SLASH
would return a list with two new PropertyValue
instances. The
first one would contain the first two terms and space operator, and the second one would contain the last two terms and
space operator.operatorType
- Split on this OperatorType
.value
- The PropertyValue
to split.PropertyValue
s split from the original.join(OperatorType, Iterable)
public static PropertyValue join(OperatorType operatorType, Iterable<PropertyValue> toJoin)
PropertyValue
s together with the given OperatorType
.operatorType
- Join using this OperatorType
.toJoin
- The list of PropertyValue
s to join.PropertyValue
instance.split(OperatorType, PropertyValue)
Copyright (c) 2019, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE file in the repository.