Class PropertyMapping
- java.lang.Object
-
- com.broadleafcommerce.metadata.dsl.core.Mapping<PropertyMapping>
-
- com.broadleafcommerce.metadata.dsl.core.extension.mappings.PropertyMapping
-
- All Implemented Interfaces:
Copyable<PropertyMapping>
,Serializable
public class PropertyMapping extends Mapping<PropertyMapping> implements Serializable
An implementation ofMapping
for mapping a source value to its destination.- Author:
- Nick Crum (ncrum)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PropertyMapping.DefaultOperations
-
Constructor Summary
Constructors Constructor Description PropertyMapping()
PropertyMapping(PropertyMapping mapping)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canEqual(Object other)
PropertyMapping
copy()
PropertyMapping
copyFrom(boolean copyFrom)
PropertyMapping
copyValue(String from, String to)
Copies the source property and maps to the destination property.PropertyMapping
copyValue(String from, String to, Object defaultValue)
Copies the source property and maps to the destination property.PropertyMapping
defaultValue(Object defaultValue)
boolean
equals(Object o)
PropertyMapping
from(String from)
String
getFrom()
The name of the property to renameString
getOperation()
The type of operation applied when mapping the property.String
getTo()
The new name of the property.Object
getValue()
int
hashCode()
boolean
isCopy()
Whether or not the property is copied.PropertyMapping
mapValue(String from, String to)
Maps the source's property to the destination's property.PropertyMapping
mapValue(String from, String to, Object defaultValue)
Maps the source's property to the destination's property with a default value.PropertyMapping
mapValueFromRoot(String to)
Maps theROOT
to the destination.PropertyMapping
mapValueToRoot(String from)
Maps the source's property to theROOT
.PropertyMapping
mergeTo()
PropertyMapping
nullValue(String to)
Sets the destination property to null.PropertyMapping
operation(String operation)
PropertyMapping
replaceTo()
PropertyMapping
setValue(String to, Object defaultValue)
Sets the value on the destination.PropertyMapping
to(String to)
-
-
-
Field Detail
-
ROOT
public static final String ROOT
Reference to the "root" object being mapped.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PropertyMapping
public PropertyMapping()
-
PropertyMapping
public PropertyMapping(PropertyMapping mapping)
-
-
Method Detail
-
copy
public PropertyMapping copy()
- Specified by:
copy
in interfaceCopyable<PropertyMapping>
- Returns:
- a deep copy of this instance
-
from
public PropertyMapping from(@Nullable String from)
-
to
public PropertyMapping to(@Nullable String to)
-
defaultValue
public PropertyMapping defaultValue(@Nullable Object defaultValue)
-
operation
public PropertyMapping operation(@Nullable String operation)
-
replaceTo
public PropertyMapping replaceTo()
-
mergeTo
public PropertyMapping mergeTo()
-
copyFrom
public PropertyMapping copyFrom(boolean copyFrom)
-
mapValue
public PropertyMapping mapValue(String from, String to)
Maps the source's property to the destination's property. Useful for mapping a property, for example:// mapValue("state", "region"); { state: "TX" } => { region: "TX" }
- Parameters:
from
- the source propertyto
- the destination property- Returns:
- the mapping
-
mapValue
public PropertyMapping mapValue(String from, String to, @Nullable Object defaultValue)
Maps the source's property to the destination's property with a default value. Useful for when you need a useful default, for example:// mapValue("state", "region", "N/A"); { city: "Washington" } => { city: "Washington", region: "N/A" }
- Parameters:
from
- the source propertyto
- the destination propertydefaultValue
- the default value- Returns:
- the mapping
-
mapValueToRoot
public PropertyMapping mapValueToRoot(String from)
Maps the source's property to theROOT
. Useful for reducing an object down to one of its properties, for example:// mapValueToRoot("label") { label: "RED" } => "RED"
- Parameters:
from
- the source property- Returns:
- the mapping
-
mapValueFromRoot
public PropertyMapping mapValueFromRoot(String to)
Maps theROOT
to the destination. Useful for mapping an object to a property of a new object.// mapValueFromRoot("details") { label: "RED" } => { details: { label: "RED" } }
- Parameters:
to
- the destination property- Returns:
- the mapping
-
setValue
public PropertyMapping setValue(String to, @Nullable Object defaultValue)
Sets the value on the destination. Useful for defaulting the value of a property, for example:// setValue("state", "TX"); { city: "Austin" } => { city: "Austin", state: "TX" }
- Parameters:
to
- the destination propertydefaultValue
- the default value of the property- Returns:
- the mapping
-
nullValue
public PropertyMapping nullValue(String to)
Sets the destination property to null. Useful for clearing out a value, for example:// nullValue("state"); { state: "TX" } => { state: null }
- Parameters:
to
- the destination property- Returns:
- the mapping
-
copyValue
public PropertyMapping copyValue(String from, String to)
Copies the source property and maps to the destination property. Useful for mapping a property while preserving the original value, for example:// copyValue("state", "region"); { state: "TX" } => { state: "TX", region: "TX" }
- Parameters:
from
- the source propertyto
- the destination property- Returns:
- the mapping
-
copyValue
public PropertyMapping copyValue(String from, String to, @Nullable Object defaultValue)
Copies the source property and maps to the destination property. Useful for when you need a useful default, for example:// copyValue("state", "region", "TX"); { } => { region: "TX" }
- Parameters:
from
- the source propertyto
- the destination propertydefaultValue
- the default value- Returns:
- the mapping
-
getFrom
public String getFrom()
The name of the property to rename
-
getTo
public String getTo()
-
getOperation
public String getOperation()
The type of operation applied when mapping the property.
-
getValue
public Object getValue()
-
isCopy
public boolean isCopy()
Whether or not the property is copied. If false, the original property will be omitted.
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classMapping<PropertyMapping>
-
canEqual
protected boolean canEqual(Object other)
- Overrides:
canEqual
in classMapping<PropertyMapping>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classMapping<PropertyMapping>
-
-