From 3bd91216710e7a20e84f888dd32c379d514e6648 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 11 Aug 2017 15:16:01 +0200 Subject: [PATCH] [New] Added Resource.getTimedState(String, boolean) --- .../main/java/li/strolch/model/Resource.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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 b6c78bfd9..6277d45e6 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 @@ -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 getTimedState(String id) { + return getTimedState(id, false); + } + + public >> 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" })