[Fix] Refactored Search API to auto cast
This commit is contained in:
parent
d7f090ed9e
commit
c64fdf81d7
|
@ -8,7 +8,7 @@ import li.strolch.utils.collections.DateRange;
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public interface ExpressionBuilder<T extends StrolchRootElement> {
|
public interface ExpressionBuilder {
|
||||||
|
|
||||||
Object extract(StrolchRootElement element);
|
Object extract(StrolchRootElement element);
|
||||||
|
|
||||||
|
@ -16,59 +16,59 @@ public interface ExpressionBuilder<T extends StrolchRootElement> {
|
||||||
return e -> e;
|
return e -> e;
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> isEqualTo(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> isEqualTo(Object right) {
|
||||||
return element -> PredicatesSupport.isEqualTo(right).matches(extract(element));
|
return element -> PredicatesSupport.isEqualTo(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> isNotEqualTo(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> isNotEqualTo(Object right) {
|
||||||
return element -> PredicatesSupport.isNotEqualTo(right).matches(extract(element));
|
return element -> PredicatesSupport.isNotEqualTo(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> isEqualToIgnoreCase(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> isEqualToIgnoreCase(Object right) {
|
||||||
return element -> PredicatesSupport.isEqualToIgnoreCase(right).matches(extract(element));
|
return element -> PredicatesSupport.isEqualToIgnoreCase(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> isNotEqualToIgnoreCase(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> isNotEqualToIgnoreCase(Object right) {
|
||||||
return element -> PredicatesSupport.isNotEqualToIgnoreCase(right).matches(extract(element));
|
return element -> PredicatesSupport.isNotEqualToIgnoreCase(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> startsWith(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> startsWith(Object right) {
|
||||||
return element -> PredicatesSupport.startsWith(right).matches(extract(element));
|
return element -> PredicatesSupport.startsWith(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> startsWithIgnoreCase(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> startsWithIgnoreCase(Object right) {
|
||||||
return element -> PredicatesSupport.startsWithIgnoreCase(right).matches(extract(element));
|
return element -> PredicatesSupport.startsWithIgnoreCase(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> endsWith(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> endsWith(Object right) {
|
||||||
return element -> PredicatesSupport.endsWith(right).matches(extract(element));
|
return element -> PredicatesSupport.endsWith(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> endsWithIgnoreCase(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> endsWithIgnoreCase(Object right) {
|
||||||
return element -> PredicatesSupport.endsWithIgnoreCase(right).matches(extract(element));
|
return element -> PredicatesSupport.endsWithIgnoreCase(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> contains(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> contains(Object right) {
|
||||||
return element -> PredicatesSupport.contains(right).matches(extract(element));
|
return element -> PredicatesSupport.contains(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> listContains(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> listContains(Object right) {
|
||||||
return element -> PredicatesSupport.listContains(right).matches(extract(element));
|
return element -> PredicatesSupport.listContains(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> containsIgnoreCase(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> containsIgnoreCase(Object right) {
|
||||||
return element -> PredicatesSupport.containsIgnoreCase(right).matches(extract(element));
|
return element -> PredicatesSupport.containsIgnoreCase(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> isIn(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> isIn(Object right) {
|
||||||
return element -> PredicatesSupport.isIn(right).matches(extract(element));
|
return element -> PredicatesSupport.isIn(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> isInIgnoreCase(Object right) {
|
default <T extends StrolchRootElement> SearchExpression<T> isInIgnoreCase(Object right) {
|
||||||
return element -> PredicatesSupport.isInIgnoreCase(right).matches(extract(element));
|
return element -> PredicatesSupport.isInIgnoreCase(right).matches(extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> inRange(DateRange range) {
|
default <T extends StrolchRootElement> SearchExpression<T> inRange(DateRange range) {
|
||||||
return element -> PredicatesSupport.inRange(range).matches(extract(element));
|
return element -> PredicatesSupport.inRange(range).matches(extract(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class ExpressionsSupport {
|
||||||
return element -> predicate.matches(element.getId());
|
return element -> predicate.matches(element.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends StrolchRootElement> ExpressionBuilder<T> id() {
|
public static ExpressionBuilder id() {
|
||||||
return StrolchElement::getId;
|
return StrolchElement::getId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,17 +26,17 @@ public class ExpressionsSupport {
|
||||||
return element -> predicate.matches(element.getName());
|
return element -> predicate.matches(element.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends StrolchRootElement> ExpressionBuilder<T> name() {
|
public static <T extends StrolchRootElement> ExpressionBuilder name() {
|
||||||
return StrolchElement::getName;
|
return StrolchElement::getName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends StrolchRootElement> SearchExpression<T> date(SearchPredicate predicate) {
|
public static <T extends StrolchRootElement> SearchExpression<T> date(SearchPredicate predicate) {
|
||||||
ExpressionBuilder<StrolchRootElement> eb = date();
|
ExpressionBuilder eb = date();
|
||||||
return element -> predicate.coerce(eb.getValueCoercer(element)).matches(eb);
|
return element -> predicate.coerce(eb.getValueCoercer(element)).matches(eb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends StrolchRootElement> ExpressionBuilder<T> date() {
|
public static <T extends StrolchRootElement> ExpressionBuilder date() {
|
||||||
return new ExpressionBuilder<T>() {
|
return new ExpressionBuilder() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValueCoercer getValueCoercer(StrolchRootElement context) {
|
public ValueCoercer getValueCoercer(StrolchRootElement context) {
|
||||||
|
@ -55,12 +55,12 @@ public class ExpressionsSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends StrolchRootElement> SearchExpression<T> state(SearchPredicate predicate) {
|
public static <T extends StrolchRootElement> SearchExpression<T> state(SearchPredicate predicate) {
|
||||||
ExpressionBuilder<StrolchRootElement> eb = state();
|
ExpressionBuilder eb = state();
|
||||||
return element -> predicate.coerce(eb.getValueCoercer(element)).matches(eb.extract(element));
|
return element -> predicate.coerce(eb.getValueCoercer(element)).matches(eb.extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends StrolchRootElement> ExpressionBuilder<T> state() {
|
public static ExpressionBuilder state() {
|
||||||
return new ExpressionBuilder<T>() {
|
return new ExpressionBuilder() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValueCoercer getValueCoercer(StrolchRootElement context) {
|
public ValueCoercer getValueCoercer(StrolchRootElement context) {
|
||||||
|
@ -84,12 +84,12 @@ public class ExpressionsSupport {
|
||||||
|
|
||||||
public static <T extends StrolchRootElement> SearchExpression<T> param(String bagId, String paramId,
|
public static <T extends StrolchRootElement> SearchExpression<T> param(String bagId, String paramId,
|
||||||
SearchPredicate predicate) {
|
SearchPredicate predicate) {
|
||||||
ExpressionBuilder<StrolchRootElement> eb = param(bagId, paramId);
|
ExpressionBuilder eb = param(bagId, paramId);
|
||||||
return element -> predicate.coerce(eb.getValueCoercer(element)).matches(eb.extract(element));
|
return element -> predicate.coerce(eb.getValueCoercer(element)).matches(eb.extract(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends StrolchRootElement> ExpressionBuilder<T> param(String bagId, String paramId) {
|
public static <T extends StrolchRootElement> ExpressionBuilder param(String bagId, String paramId) {
|
||||||
return new ExpressionBuilder<T>() {
|
return new ExpressionBuilder() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValueCoercer getValueCoercer(StrolchRootElement context) {
|
public ValueCoercer getValueCoercer(StrolchRootElement context) {
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
package li.strolch.search;
|
package li.strolch.search;
|
||||||
|
|
||||||
import li.strolch.model.Order;
|
|
||||||
import li.strolch.model.Resource;
|
|
||||||
import li.strolch.model.StrolchRootElement;
|
import li.strolch.model.StrolchRootElement;
|
||||||
import li.strolch.model.activity.Activity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a search expression interface to perform where clauses on {@link StrolchRootElement}
|
* Defines a search expression interface to perform where clauses on {@link StrolchRootElement}
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface SearchExpression<T extends StrolchRootElement> {
|
public interface SearchExpression<T extends StrolchRootElement> {
|
||||||
|
@ -31,8 +26,9 @@ public interface SearchExpression<T extends StrolchRootElement> {
|
||||||
*
|
*
|
||||||
* @return the new search expression with an internal OR of the two search expressions
|
* @return the new search expression with an internal OR of the two search expressions
|
||||||
*/
|
*/
|
||||||
default SearchExpression<T> or(SearchExpression<T> right) {
|
@SuppressWarnings("unchecked")
|
||||||
return element -> this.matches(element) || right.matches(element);
|
default <U extends StrolchRootElement> SearchExpression<U> or(SearchExpression<T> right) {
|
||||||
|
return element -> this.matches((T) element) || right.matches((T) element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,8 +39,9 @@ public interface SearchExpression<T extends StrolchRootElement> {
|
||||||
*
|
*
|
||||||
* @return the new search expression with an internal AND of the two search expressions
|
* @return the new search expression with an internal AND of the two search expressions
|
||||||
*/
|
*/
|
||||||
default SearchExpression<T> and(SearchExpression<T> right) {
|
@SuppressWarnings("unchecked")
|
||||||
return element -> this.matches(element) && right.matches(element);
|
default <U extends StrolchRootElement> SearchExpression<U> and(SearchExpression<T> right) {
|
||||||
|
return element -> this.matches((T) element) && right.matches((T) element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,40 +49,8 @@ public interface SearchExpression<T extends StrolchRootElement> {
|
||||||
*
|
*
|
||||||
* @return a new search expression where this search expression is negated
|
* @return a new search expression where this search expression is negated
|
||||||
*/
|
*/
|
||||||
default SearchExpression<T> not() {
|
@SuppressWarnings("unchecked")
|
||||||
return element -> !this.matches(element);
|
default <U extends StrolchRootElement> SearchExpression<U> not() {
|
||||||
}
|
return element -> !this.matches((T) element);
|
||||||
|
|
||||||
/**
|
|
||||||
* Map this search expression to a {@link Resource} search expression
|
|
||||||
*
|
|
||||||
* @return a new search expression for Resource elements
|
|
||||||
*/
|
|
||||||
default SearchExpression<Resource> asResource() {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
SearchExpression<Resource> exp = element -> this.matches((T) element);
|
|
||||||
return exp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map this search expression to a {@link Order} search expression
|
|
||||||
*
|
|
||||||
* @return a new search expression for Order elements
|
|
||||||
*/
|
|
||||||
default SearchExpression<Order> asOrder() {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
SearchExpression<Order> exp = element -> this.matches((T) element);
|
|
||||||
return exp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map this search expression to a {@link Activity} search expression
|
|
||||||
*
|
|
||||||
* @return a new search expression for Activity elements
|
|
||||||
*/
|
|
||||||
default SearchExpression<Activity> asActivity() {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
SearchExpression<Activity> exp = element -> this.matches((T) element);
|
|
||||||
return exp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,53 +7,54 @@ import li.strolch.model.StrolchRootElement;
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public interface SearchExpressions<T extends StrolchRootElement> {
|
public interface SearchExpressions {
|
||||||
|
|
||||||
default SearchExpression<T> not(SearchExpression<T> expression) {
|
default <T extends StrolchRootElement> SearchExpression<T> not(SearchExpression<T> expression) {
|
||||||
return element -> !expression.matches(element);
|
return element -> !expression.matches(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
default ExpressionBuilder<T> id() {
|
default ExpressionBuilder id() {
|
||||||
return ExpressionsSupport.id();
|
return ExpressionsSupport.id();
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> id(SearchPredicate predicate) {
|
default <T extends StrolchRootElement> SearchExpression<T> id(SearchPredicate predicate) {
|
||||||
return ExpressionsSupport.id(predicate);
|
return ExpressionsSupport.id(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
default ExpressionBuilder<T> name() {
|
default ExpressionBuilder name() {
|
||||||
return ExpressionsSupport.name();
|
return ExpressionsSupport.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> name(SearchPredicate predicate) {
|
default <T extends StrolchRootElement> SearchExpression<T> name(SearchPredicate predicate) {
|
||||||
return ExpressionsSupport.name(predicate);
|
return ExpressionsSupport.name(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
default ExpressionBuilder<T> date() {
|
default ExpressionBuilder date() {
|
||||||
return ExpressionsSupport.date();
|
return ExpressionsSupport.date();
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> date(SearchPredicate predicate) {
|
default <T extends StrolchRootElement> SearchExpression<T> date(SearchPredicate predicate) {
|
||||||
return ExpressionsSupport.date(predicate);
|
return ExpressionsSupport.date(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
default ExpressionBuilder<T> state() {
|
default ExpressionBuilder state() {
|
||||||
return ExpressionsSupport.state();
|
return ExpressionsSupport.state();
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> state(SearchPredicate predicate) {
|
default <T extends StrolchRootElement> SearchExpression<T> state(SearchPredicate predicate) {
|
||||||
return ExpressionsSupport.state(predicate);
|
return ExpressionsSupport.state(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
default ExpressionBuilder<T> param(String bagId, String paramId) {
|
default ExpressionBuilder param(String bagId, String paramId) {
|
||||||
return ExpressionsSupport.param(bagId, paramId);
|
return ExpressionsSupport.param(bagId, paramId);
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> param(String bagId, String paramId, SearchPredicate predicate) {
|
default <T extends StrolchRootElement> SearchExpression<T> param(String bagId, String paramId,
|
||||||
|
SearchPredicate predicate) {
|
||||||
return ExpressionsSupport.param(bagId, paramId, predicate);
|
return ExpressionsSupport.param(bagId, paramId, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
default SearchExpression<T> paramNull(String bagId, String paramId) {
|
default <T extends StrolchRootElement> SearchExpression<T> paramNull(String bagId, String paramId) {
|
||||||
return ExpressionsSupport.paramNull(bagId, paramId);
|
return ExpressionsSupport.paramNull(bagId, paramId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import li.strolch.utils.helper.ExceptionHelper;
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public abstract class StrolchSearch<T extends StrolchRootElement>
|
public abstract class StrolchSearch<T extends StrolchRootElement>
|
||||||
implements SearchExpressions<T>, SearchPredicates, Restrictable {
|
implements SearchExpressions, SearchPredicates, Restrictable {
|
||||||
|
|
||||||
private String privilegeValue;
|
private String privilegeValue;
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,7 @@ public class StrolchSearchTest {
|
||||||
|
|
||||||
Map<String, State> states = new ActivitySearch()
|
Map<String, State> states = new ActivitySearch()
|
||||||
|
|
||||||
.types().where(state().isEqualTo(State.PLANNING).and(name(isEqualTo("Activity"))).asActivity())
|
.types().where(state().isEqualTo(State.PLANNING).and(name(isEqualTo("Activity"))))
|
||||||
|
|
||||||
.search(tx).toMap(Activity::getId, Activity::getState);
|
.search(tx).toMap(Activity::getId, Activity::getState);
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return the found {@link Parameter} or null if it was not found
|
* @return the found {@link Parameter} or null if it was not found
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public <U, T extends Parameter<U>> T getParameter(String bagKey, String paramKey) {
|
public <U, T extends Parameter<U>> T getParameter(String bagKey, String paramKey) {
|
||||||
return getParameter(bagKey, paramKey, false);
|
return getParameter(bagKey, paramKey, false);
|
||||||
}
|
}
|
||||||
|
@ -105,8 +106,9 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
* @return the found {@link Parameter} or null if it was not found
|
* @return the found {@link Parameter} or null if it was not found
|
||||||
*
|
*
|
||||||
* @throws StrolchModelException
|
* @throws StrolchModelException
|
||||||
* if the element does not exist and <code>assertExists</code> is true
|
* if the element does not exist and {@code assertExists} is true
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public <U, T extends Parameter<U>> T getParameter(String bagKey, String paramKey, boolean assertExists)
|
public <U, T extends Parameter<U>> T getParameter(String bagKey, String paramKey, boolean assertExists)
|
||||||
throws StrolchModelException {
|
throws StrolchModelException {
|
||||||
if (this.parameterBagMap == null) {
|
if (this.parameterBagMap == null) {
|
||||||
|
@ -147,6 +149,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return the parameters with the given interpretation
|
* @return the parameters with the given interpretation
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public List<Parameter<?>> getParametersByInterpretation(String bagKey, String interpretation) {
|
public List<Parameter<?>> getParametersByInterpretation(String bagKey, String interpretation) {
|
||||||
ParameterBag bag = getParameterBag(bagKey);
|
ParameterBag bag = getParameterBag(bagKey);
|
||||||
if (bag == null)
|
if (bag == null)
|
||||||
|
@ -167,6 +170,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return the parameters with the given interpretation
|
* @return the parameters with the given interpretation
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public List<Parameter<?>> getParametersByInterpretationAndUom(String bagKey, String interpretation, String uom) {
|
public List<Parameter<?>> getParametersByInterpretationAndUom(String bagKey, String interpretation, String uom) {
|
||||||
ParameterBag bag = getParameterBag(bagKey);
|
ParameterBag bag = getParameterBag(bagKey);
|
||||||
if (bag == null)
|
if (bag == null)
|
||||||
|
@ -186,6 +190,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
* @throws StrolchException
|
* @throws StrolchException
|
||||||
* if the {@link ParameterBag} does not exist
|
* if the {@link ParameterBag} does not exist
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void addParameter(String bagKey, Parameter<?> parameter) throws StrolchException {
|
public void addParameter(String bagKey, Parameter<?> parameter) throws StrolchException {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
if (this.parameterBagMap == null) {
|
if (this.parameterBagMap == null) {
|
||||||
|
@ -211,6 +216,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return the removed {@link Parameter} or null if it did not exist
|
* @return the removed {@link Parameter} or null if it did not exist
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public <U, T extends Parameter<U>> T removeParameter(String bagKey, String paramKey) {
|
public <U, T extends Parameter<U>> T removeParameter(String bagKey, String paramKey) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
if (this.parameterBagMap == null) {
|
if (this.parameterBagMap == null) {
|
||||||
|
@ -232,6 +238,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return the {@link ParameterBag} with the given key, or null if it does not exist
|
* @return the {@link ParameterBag} with the given key, or null if it does not exist
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public ParameterBag getParameterBag(String key) {
|
public ParameterBag getParameterBag(String key) {
|
||||||
return getParameterBag(key, false);
|
return getParameterBag(key, false);
|
||||||
}
|
}
|
||||||
|
@ -246,6 +253,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return the {@link ParameterBag} with the given key, or null if it does not exist
|
* @return the {@link ParameterBag} with the given key, or null if it does not exist
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public ParameterBag getParameterBag(String key, boolean assertExists) {
|
public ParameterBag getParameterBag(String key, boolean assertExists) {
|
||||||
if (this.parameterBagMap == null) {
|
if (this.parameterBagMap == null) {
|
||||||
if (assertExists) {
|
if (assertExists) {
|
||||||
|
@ -272,6 +280,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return the {@link ParameterBag ParameterBags} of the given type
|
* @return the {@link ParameterBag ParameterBags} of the given type
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public List<ParameterBag> getParameterBagsByType(String type) {
|
public List<ParameterBag> getParameterBagsByType(String type) {
|
||||||
return this.parameterBagMap.values() //
|
return this.parameterBagMap.values() //
|
||||||
.stream() //
|
.stream() //
|
||||||
|
@ -285,6 +294,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
* @param bag
|
* @param bag
|
||||||
* the {@link ParameterBag} to add
|
* the {@link ParameterBag} to add
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void addParameterBag(ParameterBag bag) {
|
public void addParameterBag(ParameterBag bag) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
if (this.parameterBagMap == null) {
|
if (this.parameterBagMap == null) {
|
||||||
|
@ -307,6 +317,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return the removed {@link ParameterBag}, or null if it does not exist
|
* @return the removed {@link ParameterBag}, or null if it does not exist
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public ParameterBag removeParameterBag(String key) {
|
public ParameterBag removeParameterBag(String key) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
if (this.parameterBagMap == null) {
|
if (this.parameterBagMap == null) {
|
||||||
|
@ -320,6 +331,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
|
* @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean hasParameterBags() {
|
public boolean hasParameterBags() {
|
||||||
return this.parameterBagMap != null && !this.parameterBagMap.isEmpty();
|
return this.parameterBagMap != null && !this.parameterBagMap.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -332,6 +344,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
|
* @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean hasParameterBag(String bagKey) {
|
public boolean hasParameterBag(String bagKey) {
|
||||||
return this.parameterBagMap != null && this.parameterBagMap.containsKey(bagKey);
|
return this.parameterBagMap != null && this.parameterBagMap.containsKey(bagKey);
|
||||||
}
|
}
|
||||||
|
@ -349,6 +362,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
* bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not exist on
|
* bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not exist on
|
||||||
* the {@link ParameterBag}
|
* the {@link ParameterBag}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean hasParameter(String bagKey, String paramKey) {
|
public boolean hasParameter(String bagKey, String paramKey) {
|
||||||
if (this.parameterBagMap == null) {
|
if (this.parameterBagMap == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -366,6 +380,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
*
|
*
|
||||||
* @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
|
* @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Set<String> getParameterBagKeySet() {
|
public Set<String> getParameterBagKeySet() {
|
||||||
if (this.parameterBagMap == null) {
|
if (this.parameterBagMap == null) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
|
@ -377,6 +392,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
|
||||||
* Fills {@link GroupedParameterizedElement} properties of this clone
|
* Fills {@link GroupedParameterizedElement} properties of this clone
|
||||||
*
|
*
|
||||||
* @param clone
|
* @param clone
|
||||||
|
* the clone to fill
|
||||||
*/
|
*/
|
||||||
protected void fillClone(GroupedParameterizedElement clone) {
|
protected void fillClone(GroupedParameterizedElement clone) {
|
||||||
super.fillClone(clone);
|
super.fillClone(clone);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package li.strolch.model;
|
package li.strolch.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
|
@ -25,7 +26,7 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
*
|
*
|
||||||
* @return the found {@link Parameter} or null if it was not found
|
* @return the found {@link Parameter} or null if it was not found
|
||||||
*/
|
*/
|
||||||
public <U, T extends Parameter<U>> T getParameter(String bagKey, String paramKey);
|
<U, T extends Parameter<U>> T getParameter(String bagKey, String paramKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if
|
* Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if
|
||||||
|
@ -40,7 +41,33 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
*
|
*
|
||||||
* @return the found {@link Parameter} or null if it was not found
|
* @return the found {@link Parameter} or null if it was not found
|
||||||
*/
|
*/
|
||||||
public <U, T extends Parameter<U>> T getParameter(String bagKey, String paramKey, boolean assertExists);
|
<U, T extends Parameter<U>> T getParameter(String bagKey, String paramKey, boolean assertExists);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all the {@link Parameter Parameters} with the given interpretation
|
||||||
|
*
|
||||||
|
* @param bagKey
|
||||||
|
* the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
|
||||||
|
* @param interpretation
|
||||||
|
* the interpretation for which the parameters are to be returned
|
||||||
|
*
|
||||||
|
* @return the parameters with the given interpretation
|
||||||
|
*/
|
||||||
|
List<Parameter<?>> getParametersByInterpretation(String bagKey, String interpretation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all the {@link Parameter Parameters} with the given interpretation
|
||||||
|
*
|
||||||
|
* @param bagKey
|
||||||
|
* the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
|
||||||
|
* @param interpretation
|
||||||
|
* the interpretation for which the parameters are to be returned
|
||||||
|
* @param uom
|
||||||
|
* the uom for which the parameters are to be returned
|
||||||
|
*
|
||||||
|
* @return the parameters with the given interpretation
|
||||||
|
*/
|
||||||
|
List<Parameter<?>> getParametersByInterpretationAndUom(String bagKey, String interpretation, String uom);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new {@link Parameter} to the {@link ParameterBag} with the given key
|
* Adds a new {@link Parameter} to the {@link ParameterBag} with the given key
|
||||||
|
@ -53,7 +80,7 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
* @throws StrolchException
|
* @throws StrolchException
|
||||||
* if the {@link ParameterBag} does not exist
|
* if the {@link ParameterBag} does not exist
|
||||||
*/
|
*/
|
||||||
public void addParameter(String bagKey, Parameter<?> parameter) throws StrolchException;
|
void addParameter(String bagKey, Parameter<?> parameter) throws StrolchException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey
|
* Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey
|
||||||
|
@ -65,7 +92,7 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
*
|
*
|
||||||
* @return the removed {@link Parameter} or null if it did not exist
|
* @return the removed {@link Parameter} or null if it did not exist
|
||||||
*/
|
*/
|
||||||
public <U, T extends Parameter<U>> T removeParameter(String bagKey, String paramKey);
|
<U, T extends Parameter<U>> T removeParameter(String bagKey, String paramKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link ParameterBag} with the given key, or null if it does not exist
|
* Returns the {@link ParameterBag} with the given key, or null if it does not exist
|
||||||
|
@ -75,7 +102,7 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
*
|
*
|
||||||
* @return the {@link ParameterBag} with the given key, or null if it does not exist
|
* @return the {@link ParameterBag} with the given key, or null if it does not exist
|
||||||
*/
|
*/
|
||||||
public ParameterBag getParameterBag(String key);
|
ParameterBag getParameterBag(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link ParameterBag} with the given key, or null if it does not exist
|
* Returns the {@link ParameterBag} with the given key, or null if it does not exist
|
||||||
|
@ -87,7 +114,17 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
*
|
*
|
||||||
* @return the {@link ParameterBag} with the given key, or null if it does not exist
|
* @return the {@link ParameterBag} with the given key, or null if it does not exist
|
||||||
*/
|
*/
|
||||||
public ParameterBag getParameterBag(String key, boolean assertExists);
|
ParameterBag getParameterBag(String key, boolean assertExists);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link ParameterBag ParameterBags} of the given type
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* the type of {@link ParameterBag} to return
|
||||||
|
*
|
||||||
|
* @return the {@link ParameterBag ParameterBags} of the given type
|
||||||
|
*/
|
||||||
|
List<ParameterBag> getParameterBagsByType(String type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement}
|
* Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement}
|
||||||
|
@ -95,7 +132,7 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
* @param bag
|
* @param bag
|
||||||
* the {@link ParameterBag} to add
|
* the {@link ParameterBag} to add
|
||||||
*/
|
*/
|
||||||
public void addParameterBag(ParameterBag bag);
|
void addParameterBag(ParameterBag bag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the {@link ParameterBag} with the given key
|
* Removes the {@link ParameterBag} with the given key
|
||||||
|
@ -105,14 +142,14 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
*
|
*
|
||||||
* @return the removed {@link ParameterBag}, or null if it does not exist
|
* @return the removed {@link ParameterBag}, or null if it does not exist
|
||||||
*/
|
*/
|
||||||
public ParameterBag removeParameterBag(String key);
|
ParameterBag removeParameterBag(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
|
* Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
|
||||||
*
|
*
|
||||||
* @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
|
* @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
|
||||||
*/
|
*/
|
||||||
public boolean hasParameterBags();
|
boolean hasParameterBags();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
|
* Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
|
||||||
|
@ -122,7 +159,7 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
*
|
*
|
||||||
* @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
|
* @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
|
||||||
*/
|
*/
|
||||||
public boolean hasParameterBag(String bagKey);
|
boolean hasParameterBag(String bagKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
|
* Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
|
||||||
|
@ -137,12 +174,12 @@ public interface ParameterBagContainer extends StrolchElement {
|
||||||
* bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not exist on
|
* bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not exist on
|
||||||
* the {@link ParameterBag}
|
* the {@link ParameterBag}
|
||||||
*/
|
*/
|
||||||
public boolean hasParameter(String bagKey, String paramKey);
|
boolean hasParameter(String bagKey, String paramKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
|
* Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
|
||||||
*
|
*
|
||||||
* @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
|
* @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
|
||||||
*/
|
*/
|
||||||
public Set<String> getParameterBagKeySet();
|
Set<String> getParameterBagKeySet();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue