public class PropertyExportImpl extends Object implements PropertyExport
| Modifier and Type | Class and Description |
|---|---|
protected static class |
PropertyExportImpl.PropertyExportWrap
A wrapper class that make it easy to wrap, delegate and override methods.
|
| Constructor and Description |
|---|
PropertyExportImpl(Property<?> property,
Class<?> containingClass,
Exporter.EXPORT_CANONICAL_NAME canonicalNameOpt,
Exporter.EXPORT_OUT_ALIASES outAliasOpt)
Full state constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected List<String> |
buildExportNames()
Build the export names based on annotation options.
|
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. |
protected static PropertyExport |
mapNames(List<String> exportNames,
PropertyExport inner)
Construct a new PropertyExport, overriding the getExportNames() method.
|
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. |
protected static PropertyExport |
mapValue(Object value,
PropertyExport inner)
Construct a new PropertyExport, overriding the getValue() method.
|
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. |
protected static PropertyExport |
mapValueAsString(String value,
PropertyExport inner)
Construct a new PropertyExport, overriding the getValueAsString() method.
|
public PropertyExportImpl(Property<?> property, Class<?> containingClass, Exporter.EXPORT_CANONICAL_NAME canonicalNameOpt, Exporter.EXPORT_OUT_ALIASES outAliasOpt)
property - The Property being exported.containingClass - The class immediately containing the Property.canonicalNameOpt - Option of if/when to include the canonical name in exportsoutAliasOpt - Option of if to include out alias names in the exports.public Property<?> getProperty()
PropertyExportgetProperty in interface PropertyExportpublic Class<?> getContainingClass()
PropertyExportgetContainingClass in interface PropertyExportpublic Exporter.EXPORT_CANONICAL_NAME getCanonicalNameOption()
PropertyExportManualExportAllowed 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
PropertyExport.getExportNames() and then ultimately as one of the names in the final key-value
pairs.
getCanonicalNameOption in interface PropertyExportpublic Exporter.EXPORT_OUT_ALIASES getOutAliasOption()
PropertyExportManualExportAllowed 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.
getOutAliasOption in interface PropertyExportpublic List<String> getExportNames()
PropertyExport
This method builds and returns the default export name list based on the
PropertyExport.getCanonicalNameOption() & PropertyExport.getOutAliasOption() options, or, if
PropertyExport.mapNames(List) was used to construct this instance, the list of names specified.
See AndHow.export(Class[]) for an example that remaps export names.
getExportNames in interface PropertyExportpublic Object getValue()
PropertyExport
Nominally this is the same as getProperty().getValue(), however,
PropertyExport.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:
PropertyExport.getValueAsString(): use PropertyExport.mapValueAsString(String)PropertyExport.getValue(): use PropertyExport.mapValue(Object)getValue in interface PropertyExportpublic String getValueAsString()
PropertyExport
Nominally this is the same as getProperty().getValueAsString(), however,
PropertyExport.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:
PropertyExport.getValueAsString(): use PropertyExport.mapValueAsString(String)PropertyExport.getValue(): use PropertyExport.mapValue(Object)
Implementation note: The nominal implementation of this method should call
getProperty().getValueAsString() and not delegate to PropertyExport.getValue(), since the
type returned by getValue may be overridden and not match the Property type.
getValueAsString in interface PropertyExportpublic PropertyExport mapNames(List<String> exportNames)
PropertyExportstream()s, this method maps this instance to a new one
with new export names.
Calling PropertyExport.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.
mapNames in interface PropertyExportexportNames - A new list of export names to be used, rather than the default ones.public PropertyExport mapValue(Object value)
PropertyExportstream()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 PropertyExport.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:
PropertyExport.getValueAsString(): use PropertyExport.mapValueAsString(String)PropertyExport.getValue(): use PropertyExport.mapValue(Object)mapValue in interface PropertyExportvalue - The new value to return for the value of this Property.public PropertyExport mapValueAsString(String value)
PropertyExportstream()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 PropertyExport.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:
PropertyExport.getValueAsString(): use PropertyExport.mapValueAsString(String)PropertyExport.getValue(): use PropertyExport.mapValue(Object)mapValueAsString in interface PropertyExportvalue - The new value to return for the String value of this Property.protected List<String> buildExportNames()
The ManualExportAllowed annotation on the class containing the Property or
a class containing that class determines the export name options.
See getCanonicalNameOption(), getOutAliasOption(), and
ManualExportAllowed for details.
protected static PropertyExport mapNames(List<String> exportNames, PropertyExport inner)
exportNames - The new list of export names to return from the getExportNames() method.inner - The inner instance to delegate to for other methods.protected static PropertyExport mapValue(Object value, PropertyExport inner)
value - The new value to return from the getValue() method.inner - The inner instance to delegate to for other methods.protected static PropertyExport mapValueAsString(String value, PropertyExport inner)
value - The new value to return from the getValueAsString() method.inner - The inner instance to delegate to for other methods.Copyright © 2022. All rights reserved.