Class ProductSwitch
java.lang.Object
org.faktorips.runtime.productswitch.ProductSwitch
The
ProductSwitch class is used to generically and recursively switch the
IProductComponent of an IConfigurableModelObject and its children.
By default, it uses the only replacement that is configured in the product configuration. If more
than one replacement is found, it uses the IProductComponent.getKindId() to determine the
correct replacement.
The default behavior can be changed by providing a BiPredicate that provides a more
specific way than the kindId to find a replacement, or by providing a different implementation of
the MatchingProductFinder or the AdvancedProductFinder interface.
- Since:
- 23.6
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classThis builder class uses theAdvancedProductFinderto switch to a newIProductComponentstatic classThis builder class uses theMatchingProductFinderto switch to a newIProductComponentstatic classThis builder class configures the conditions used for finding the correct replacementIProductComponentfor multiplePolicyAssociations.static classThis builder class configures the conditions used for finding the correct replacementIProductComponent. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BiPredicate<IProductComponent,IProductComponent> ThisBiPredicateuses theIProductComponent.getKindId()to find a suitable replacement for a product switch. -
Method Summary
Modifier and TypeMethodDescriptionstatic ProductFinderResultcreateEmptyResult(IConfigurableModelObject modelObject) Creates aProductFinderResultobject with an error message indicating that the switch failed because the specified object has no suitable replacements.static ProductFinderResultcreateErrorResult(IConfigurableModelObject modelObject, List<IProductComponent> matchingProductComponents) Creates aProductFinderResultobject with an error message indicating that the switch failed because the specified object has multiple replacements.from(IConfigurableModelObject modelObject) Switches the specified model object and all its configurable children to corresponding objects from the new product component.
-
Field Details
-
BY_KIND_ID
ThisBiPredicateuses theIProductComponent.getKindId()to find a suitable replacement for a product switch. It can be used as a fallback for thefrom(IConfigurableModelObject)method.Example usage:
// fallback after a BiPredicate for a special case ProductSwitch.from(modelObject).with(mySpecialBiPredicate.or(ProductSwitch.BY_KIND_ID)).to(otherProductComponent); // using only ProductSwitch.from(modelObject).with(ProductSwitch.BY_KIND_ID).to(otherProductComponent); // is the same as the default behavior of ProductSwitch.from(modelObject).to(otherProductComponent);
-
-
Method Details
-
from
Switches the specified model object and all its configurable children to corresponding objects from the new product component.Example usage:
ProductSwitch.from(modelObject).to(newProductComponent); // or ProductSwitch.from(modelObject) .matchingBy(attributeName) .to(newProductComponent);- Parameters:
modelObject- the model object that should be switched to a different product- Returns:
- the
ProductSwitchConditionBuilder
-
createErrorResult
public static ProductFinderResult createErrorResult(IConfigurableModelObject modelObject, List<IProductComponent> matchingProductComponents) Creates aProductFinderResultobject with an error message indicating that the switch failed because the specified object has multiple replacements.- Parameters:
modelObject- the object where the switch failedmatchingProductComponents- the results from the product finder- Returns:
- a
ProductFinderResult.error(String)object with a message
-
createEmptyResult
Creates aProductFinderResultobject with an error message indicating that the switch failed because the specified object has no suitable replacements.- Parameters:
modelObject- the object where the switch failed- Returns:
- a
ProductFinderResult.error(String)object with a message
-