public interface PropertyExport
Exports are typically in the form of Key-Value pairs where the key is the Property
canonical name and/or 'out' aliases and the value is the real value of the Property.
AndHow#export() returns a Stream of PropertyExport's, one PropertyExport per
Property. The ExportCollector has several collectors that transform and collect the
stream into Maps or Properties of key-value pairs.
See AndHow#export() for export details and examples.
| Modifier and Type | Method and Description |
|---|---|
Exporter.EXPORT_CANONICAL_NAME |
getCanonicalNameOption()
Option read from the containing
ManualExportAllowed annotation to determine if the
canonical name of the Property should be included. |
Class<?> |
getContainingClass()
The class directly containing the Property.
|
List<String> |
getExportNames()
The complete list of export names for this property, which may be null, empty or many.
|
Exporter.EXPORT_OUT_ALIASES |
getOutAliasOption()
Option read from the containing
ManualExportAllowed annotation to determine if 'out'
aliases of the Property should be included. |
Property<?> |
getProperty()
The Property being exported.
|
Object |
getValue()
Fetch the Object value of the Property, e.g., an Integer Property will return an Integer.
|
String |
getValueAsString()
Fetch the value as a String from the Property.
|
PropertyExport |
mapNames(List<String> exportNames)
Intended for using with Java
stream()s, this method maps this instance to a new one
with new export names. |
PropertyExport |
mapValue(Object value)
Intended for using with Java
stream()s, this method maps this instance to a new one
with a new Object value for the Property, i.e., the 'value' part of a key-value pair. |
PropertyExport |
mapValueAsString(String value)
Intended for using with Java
stream()s, this method maps this instance to a new one
with a new String value for the Property, i.e., the 'value' part of a key-value pair. |
Property<?> getProperty()
Class<?> getContainingClass()
Exporter.EXPORT_CANONICAL_NAME getCanonicalNameOption()
ManualExportAllowed annotation to determine if the
canonical name of the Property should be included.
If included, the canonical name would be included in the list of names returned from
getExportNames() and then ultimately as one of the names in the final key-value
pairs.
Exporter.EXPORT_OUT_ALIASES getOutAliasOption()
ManualExportAllowed annotation to determine if 'out'
aliases of the Property should be included.
'Out' aliases are alternate names for a Property for the purpose of export, so generally
they are intended to be included.
List<String> getExportNames()
This method builds and returns the default export name list based on the
getCanonicalNameOption() & getOutAliasOption() options, or, if
mapNames(List) was used to construct this instance, the list of names specified.
See AndHow.export(Class[]) for an example that remaps export names.
Object getValue()
Nominally this is the same as getProperty().getValue(), however,
mapValue(Object) can be used to rewrite the value.
Take care to map the method that will be used by the collector you have chosen:
getValueAsString(): use mapValueAsString(String)getValue(): use mapValue(Object)String getValueAsString()
Nominally this is the same as getProperty().getValueAsString(), however,
mapValueAsString(String) can be used to rewrite the value.
Take care to map the method that will be used by the collector you have chosen:
getValueAsString(): use mapValueAsString(String)getValue(): use mapValue(Object)
Implementation note: The nominal implementation of this method should call
getProperty().getValueAsString() and not delegate to getValue(), since the
type returned by getValue may be overridden and not match the Property type.
PropertyExport mapNames(List<String> exportNames)
stream()s, this method maps this instance to a new one
with new export names.
Calling getExportNames() on the new instance returns the new exportNames.
Specifying an empty or null list of names will remove this Property from export.
See AndHow.export(Class[]) for an example that remaps export names.
exportNames - A new list of export names to be used, rather than the default ones.PropertyExport mapValue(Object value)
stream()s, this method maps this instance to a new one
with a new Object value for the Property, i.e., the 'value' part of a key-value pair.
Calling getValue() on the new instance returns the new value, which may be null.
This example uses mapValue() to multiply Property values by 2 if they are integers:
Map<String, Object> export =
AndHow.instance().export(MyClass.class)
.map(p -> p.mapValue(
(p.getValue() != null && p.getValue() instanceof Integer)
? (Integer)p.getValue() * 2:p.getValue()) )
.collect(ExportCollector.objectMap());
Take care to map the method that will be used by the collector you have chosen:
getValueAsString(): use mapValueAsString(String)getValue(): use mapValue(Object)value - The new value to return for the value of this Property.PropertyExport mapValueAsString(String value)
stream()s, this method maps this instance to a new one
with a new String value for the Property, i.e., the 'value' part of a key-value pair.
Calling getValueAsString() on the new instance returns the new value, which may be null.
This example uses mapValueAsString() to convert Property values to uppercase:
Map<String, String> export =
AndHow.instance().export(MyClass.class)
.map( p -> p.mapValueAsString( p.getValueAsString() != null
? p.getValueAsString().toUpperCase():null) )
.collect(ExportCollector.stringMap());
Take care to map the method that will be used by the collector you have chosen:
getValueAsString(): use mapValueAsString(String)getValue(): use mapValue(Object)value - The new value to return for the String value of this Property.Copyright © 2022. All rights reserved.