[New] Added Resource.getTimedState(String, boolean)

This commit is contained in:
Robert von Burg 2017-08-11 15:16:01 +02:00
parent 0c6f62e31e
commit 3bd9121671
1 changed files with 18 additions and 2 deletions

View File

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Set;
import li.strolch.exception.StrolchException;
import li.strolch.exception.StrolchModelException;
import li.strolch.exception.StrolchPolicyException;
import li.strolch.model.Locator.LocatorBuilder;
import li.strolch.model.policy.PolicyDef;
@ -101,12 +102,27 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
strolchTimedState.setParent(this);
}
@SuppressWarnings({ "unchecked" })
public <T extends StrolchTimedState<? extends IValue<?>>> T getTimedState(String id) {
return getTimedState(id, false);
}
public <T extends StrolchTimedState<? extends IValue<?>>> T getTimedState(String id, boolean assertExists) {
if (this.timedStateMap == null) {
if (assertExists) {
String msg = "The TimedState {0} does not exist";
throw new StrolchModelException(MessageFormat.format(msg, getLocator().append(Tags.STATE, id)));
}
return null;
}
return (T) this.timedStateMap.get(id);
@SuppressWarnings("unchecked")
T timedState = (T) this.timedStateMap.get(id);
if (timedState == null && assertExists) {
String msg = "The TimedState {0} does not exist";
throw new StrolchModelException(MessageFormat.format(msg, getLocator().append(Tags.STATE, id)));
}
return timedState;
}
@SuppressWarnings({ "unchecked", "rawtypes" })