[Minor] Added PolicyContainer.getPolicyDef(Class)

This commit is contained in:
Robert von Burg 2018-01-12 16:15:39 +01:00
parent a7a33e4e0c
commit d385025609
5 changed files with 94 additions and 61 deletions

View File

@ -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);

View File

@ -18,7 +18,7 @@ public interface PolicyContainer {
* @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;
@ -31,7 +31,7 @@ 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
*/
@ -41,17 +41,27 @@ public interface PolicyContainer {
* 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);
}

View File

@ -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);

View File

@ -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 <code>State</code> of the a<code>Action</code>
* the target <code>State</code> of the a<code>Action</code>
*/
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;
@ -137,8 +138,8 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
}
/**
* @param add
* <code>IValueChange</code> to be applied to the <code>Resource</code>
* @param change
* <code>IValueChange</code> to be applied to the <code>Resource</code>
*
* @return <tt>true</tt> (as specified by {@link Collection#add})
*/
@ -158,7 +159,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
public Iterator<IValueChange<? extends IValue<?>>> changesIterator() {
if (this.changes == null)
return Collections.<IValueChange<? extends IValue<?>>> emptyList().iterator();
return Collections.<IValueChange<? extends IValue<?>>>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);

View File

@ -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,11 +32,6 @@ 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
@ -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);
@ -130,10 +130,10 @@ public class Activity extends AbstractStrolchRootElement
* 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);
@ -143,6 +143,7 @@ public class Activity extends AbstractStrolchRootElement
* add an activity element to the <code>LinkedHashMap</code> of <code>IActivityElements</code>
*
* @param activityElement
*
* @return the element added
*/
@SuppressWarnings("unchecked")
@ -169,7 +170,7 @@ 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
*/
@ -185,7 +186,8 @@ public class Activity extends AbstractStrolchRootElement
* get <code>IActivityElement</code> by id
*
* @param id
* the id of the <code>IActivityElement</code>
* the id of the <code>IActivityElement</code>
*
* @return IActivityElement
*/
@SuppressWarnings("unchecked")
@ -319,7 +321,7 @@ 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
*/
@ -342,7 +344,7 @@ 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
*/
@ -366,7 +368,7 @@ public class Activity extends AbstractStrolchRootElement
*/
public Iterator<Entry<String, IActivityElement>> elementIterator() {
if (this.elements == null)
return Collections.<String, IActivityElement> emptyMap().entrySet().iterator();
return Collections.<String, IActivityElement>emptyMap().entrySet().iterator();
return this.elements.entrySet().iterator();
}
@ -375,7 +377,7 @@ public class Activity extends AbstractStrolchRootElement
*/
public Stream<Entry<String, IActivityElement>> elementStream() {
if (this.elements == null)
return Collections.<String, IActivityElement> emptyMap().entrySet().stream();
return Collections.<String, IActivityElement>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);