From d3850256097a4a821fb41717a132e5d48b575dc1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 12 Jan 2018 16:15:39 +0100 Subject: [PATCH] [Minor] Added PolicyContainer.getPolicyDef(Class) --- .../src/main/java/li/strolch/model/Order.java | 11 ++- .../li/strolch/model/PolicyContainer.java | 34 +++++---- .../main/java/li/strolch/model/Resource.java | 11 ++- .../li/strolch/model/activity/Action.java | 28 +++++--- .../li/strolch/model/activity/Activity.java | 71 ++++++++++--------- 5 files changed, 94 insertions(+), 61 deletions(-) diff --git a/li.strolch.model/src/main/java/li/strolch/model/Order.java b/li.strolch.model/src/main/java/li/strolch/model/Order.java index 8205106a3..cf5fba785 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/Order.java +++ b/li.strolch.model/src/main/java/li/strolch/model/Order.java @@ -1,12 +1,12 @@ /* * Copyright 2013 Robert von Burg - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -129,6 +129,11 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem return this.policyDefs; } + @Override + public PolicyDef getPolicyDef(Class clazz) { + return getPolicyDefs().getPolicyDef(clazz.getSimpleName()); + } + @Override public PolicyDef getPolicyDef(String type) { return getPolicyDefs().getPolicyDef(type); diff --git a/li.strolch.model/src/main/java/li/strolch/model/PolicyContainer.java b/li.strolch.model/src/main/java/li/strolch/model/PolicyContainer.java index e70ffa822..2bab69cff 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/PolicyContainer.java +++ b/li.strolch.model/src/main/java/li/strolch/model/PolicyContainer.java @@ -7,18 +7,18 @@ import li.strolch.model.policy.PolicyDefs; /** * A {@link PolicyContainer} has a reference to {@link PolicyDefs} on which Policy configurations are stored for the * given object - * + * * @author Robert von Burg */ public interface PolicyContainer { /** * Returns the reference to the {@link PolicyDefs} - * + * * @return the reference to the {@link PolicyDefs} - * + * * @throws StrolchPolicyException - * if no {@link PolicyDefs} are available + * if no {@link PolicyDefs} are available */ public PolicyDefs getPolicyDefs() throws StrolchPolicyException; @@ -29,29 +29,39 @@ public interface PolicyContainer { /** * Returns true if this container has the {@link PolicyDef} with the given type, false if not - * + * * @param type - * the type of policy def to return - * + * the type of policy def to return + * * @return true if this container has the {@link PolicyDef} with the given type, false if not */ public boolean hasPolicyDef(String type); /** * Returns the {@link PolicyDef} for the given type - * + * * @param type - * the type of policy def to return - * + * the type of policy def to return + * * @return the policy def of the given type */ public PolicyDef getPolicyDef(String type); + /** + * Returns the {@link PolicyDef} for the given class + * + * @param clazz + * the type of policy def to return + * + * @return the policy def of the given class + */ + public PolicyDef getPolicyDef(Class clazz); + /** * Set the reference to the {@link PolicyDefs} - * + * * @param policyDefs - * the {@link PolicyDefs} to set + * the {@link PolicyDefs} to set */ public void setPolicyDefs(PolicyDefs policyDefs); } diff --git a/li.strolch.model/src/main/java/li/strolch/model/Resource.java b/li.strolch.model/src/main/java/li/strolch/model/Resource.java index 6277d45e6..e4a8d9592 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/Resource.java +++ b/li.strolch.model/src/main/java/li/strolch/model/Resource.java @@ -1,12 +1,12 @@ /* * Copyright 2013 Robert von Burg - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -162,6 +162,11 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE return this.policyDefs; } + @Override + public PolicyDef getPolicyDef(Class clazz) { + return getPolicyDefs().getPolicyDef(clazz.getSimpleName()); + } + @Override public PolicyDef getPolicyDef(String type) { return getPolicyDefs().getPolicyDef(type); diff --git a/li.strolch.model/src/main/java/li/strolch/model/activity/Action.java b/li.strolch.model/src/main/java/li/strolch/model/activity/Action.java index ec0b5f4ee..7d6d97f3b 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/activity/Action.java +++ b/li.strolch.model/src/main/java/li/strolch/model/activity/Action.java @@ -1,12 +1,12 @@ /* * Copyright 2015 Martin Smock - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -43,7 +43,7 @@ import li.strolch.model.visitor.IActivityElementVisitor; * An {@link Action} represents a single step within an {@link Activity}, that is, one that is not further decomposed * within the {@link Activity}. A {@link Activity} applies {@link IValueChange} objects at the start and end time of the * {@link Activity}. - * + * * @author Martin Smock */ public class Action extends GroupedParameterizedElement implements IActivityElement, PolicyContainer { @@ -91,7 +91,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem /** * @param resourceId - * the id of the {@link Resource} the {@link Action} acts on + * the id of the {@link Resource} the {@link Action} acts on */ public void setResourceId(String resourceId) { this.resourceId = resourceId; @@ -107,7 +107,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem /** * @param state - * the target State of the aAction + * the target State of the aAction */ public void setState(State state) { this.state = state; @@ -122,6 +122,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem /** * @param resourceType + * the resource type */ public void setResourceType(String resourceType) { this.resourceType = resourceType; @@ -129,7 +130,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem /** * Returns true if this {@link Action} contains any {@link IValueChange changes}, false if not - * + * * @return true if this {@link Action} contains any {@link IValueChange changes}, false if not */ public boolean hasChanges() { @@ -137,9 +138,9 @@ public class Action extends GroupedParameterizedElement implements IActivityElem } /** - * @param add - * IValueChange to be applied to the Resource - * + * @param change + * IValueChange to be applied to the Resource + * * @return true (as specified by {@link Collection#add}) */ public boolean addChange(IValueChange> change) { @@ -158,7 +159,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem public Iterator>> changesIterator() { if (this.changes == null) - return Collections.>> emptyList().iterator(); + return Collections.>>emptyList().iterator(); return this.changes.iterator(); } @@ -212,6 +213,11 @@ public class Action extends GroupedParameterizedElement implements IActivityElem return this.policyDefs != null; } + @Override + public PolicyDef getPolicyDef(Class clazz) { + return getPolicyDefs().getPolicyDef(clazz.getSimpleName()); + } + @Override public boolean hasPolicyDef(String type) { return this.policyDefs != null && policyDefs.hasPolicyDef(type); diff --git a/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java b/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java index 1e6a92769..24573aea3 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java +++ b/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java @@ -1,12 +1,12 @@ /* * Copyright 2015 Martin Smock - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,6 +15,11 @@ */ package li.strolch.model.activity; +import java.text.MessageFormat; +import java.util.*; +import java.util.Map.Entry; +import java.util.stream.Stream; + import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchModelException; import li.strolch.exception.StrolchPolicyException; @@ -27,15 +32,10 @@ import li.strolch.model.visitor.IActivityElementVisitor; import li.strolch.model.visitor.StrolchElementVisitor; import li.strolch.utils.dbc.DBC; -import java.text.MessageFormat; -import java.util.*; -import java.util.Map.Entry; -import java.util.stream.Stream; - /** * Parameterized object grouping a collection of {@link Activity} and {@link Action} objects defining the process to be * scheduled - * + * * @author Martin Smock */ public class Activity extends AbstractStrolchRootElement @@ -61,11 +61,11 @@ public class Activity extends AbstractStrolchRootElement * Default constructor * * @param id - * the id + * the id * @param name - * the name + * the name * @param type - * the type + * the type */ public Activity(String id, String name, String type, TimeOrdering timeOrdering) { super(id, name, type); @@ -118,7 +118,7 @@ public class Activity extends AbstractStrolchRootElement /** * Returns true if this {@link Activity} contains any children i.e. any of {@link Action} or {@link Activity} - * + * * @return true if this {@link Activity} contains any children i.e. any of {@link Action} or {@link Activity} */ public boolean hasElements() { @@ -128,12 +128,12 @@ public class Activity extends AbstractStrolchRootElement /** * Returns true if this {@link Activity} contains a child with the given id. The element instance type is ignored, * i.e. {@link Action} or {@link Activity} - * + * * @param id - * the id of the element to check for - * + * the id of the element to check for + * * @return true if this {@link Activity} contains a child with the given id. The element instance type is ignored, - * i.e. {@link Action} or {@link Activity} + * i.e. {@link Action} or {@link Activity} */ public boolean hasElement(String id) { return this.elements != null && this.elements.containsKey(id); @@ -141,8 +141,9 @@ public class Activity extends AbstractStrolchRootElement /** * add an activity element to the LinkedHashMap of IActivityElements - * + * * @param activityElement + * * @return the element added */ @SuppressWarnings("unchecked") @@ -167,10 +168,10 @@ public class Activity extends AbstractStrolchRootElement /** * Removes the element with the given id and returns it, if it exists - * + * * @param id - * the id of the element to remove - * + * the id of the element to remove + * * @return the removed element, or null if it does not exist */ @SuppressWarnings("unchecked") @@ -183,9 +184,10 @@ public class Activity extends AbstractStrolchRootElement /** * get IActivityElement by id - * + * * @param id - * the id of the IActivityElement + * the id of the IActivityElement + * * @return IActivityElement */ @SuppressWarnings("unchecked") @@ -297,7 +299,7 @@ public class Activity extends AbstractStrolchRootElement /** * Returns all the actions as a flat list - * + * * @return the list of actions */ public List getActionsAsFlatList() { @@ -317,10 +319,10 @@ public class Activity extends AbstractStrolchRootElement /** * Returns all the actions in the entire hierarchy with the given state - * + * * @param state - * the state of the action to return - * + * the state of the action to return + * * @return the list of actions with the given state */ public List getActionsWithState(State state) { @@ -340,10 +342,10 @@ public class Activity extends AbstractStrolchRootElement /** * Returns all the actions in the entire hierarchy with the given type - * + * * @param type - * the type of action to return - * + * the type of action to return + * * @return the list of actions with the given type */ public List getActionsByType(String type) { @@ -366,7 +368,7 @@ public class Activity extends AbstractStrolchRootElement */ public Iterator> elementIterator() { if (this.elements == null) - return Collections. emptyMap().entrySet().iterator(); + return Collections.emptyMap().entrySet().iterator(); return this.elements.entrySet().iterator(); } @@ -375,7 +377,7 @@ public class Activity extends AbstractStrolchRootElement */ public Stream> elementStream() { if (this.elements == null) - return Collections. emptyMap().entrySet().stream(); + return Collections.emptyMap().entrySet().stream(); return this.elements.entrySet().stream(); } @@ -419,6 +421,11 @@ public class Activity extends AbstractStrolchRootElement return this.policyDefs; } + @Override + public PolicyDef getPolicyDef(Class clazz) { + return getPolicyDefs().getPolicyDef(clazz.getSimpleName()); + } + @Override public PolicyDef getPolicyDef(String type) { return getPolicyDefs().getPolicyDef(type);