From 9b2fc22cc07ebebe66e6931d0f49925d0483cff0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 21 Mar 2017 15:33:06 +0100 Subject: [PATCH] [New] Added new ElementDateVisitor and ElementStateVisitor These allow to get the date or state respectively from a StrolchRootElement which supports such a field (Order and/or Activity) and thus eliminates the need for casting --- .../model/visitor/ElementDateVisitor.java | 43 +++++++++++++++++++ .../model/visitor/ElementStateVisitor.java | 42 ++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 li.strolch.model/src/main/java/li/strolch/model/visitor/ElementDateVisitor.java create mode 100644 li.strolch.model/src/main/java/li/strolch/model/visitor/ElementStateVisitor.java diff --git a/li.strolch.model/src/main/java/li/strolch/model/visitor/ElementDateVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/ElementDateVisitor.java new file mode 100644 index 000000000..8a410d2e2 --- /dev/null +++ b/li.strolch.model/src/main/java/li/strolch/model/visitor/ElementDateVisitor.java @@ -0,0 +1,43 @@ +/* + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.model.visitor; + +import java.util.Date; + +import li.strolch.model.Order; +import li.strolch.model.Resource; +import li.strolch.model.activity.Activity; + +/** + * @author Robert von Burg + */ +public class ElementDateVisitor implements StrolchRootElementVisitor { + + @Override + public Date visitOrder(Order order) { + return order.getDate(); + } + + @Override + public Date visitResource(Resource resource) { + throw new IllegalArgumentException("Resources have no date!"); + } + + @Override + public Date visitActivity(Activity activity) { + throw new IllegalArgumentException("Activities have no date!"); + } +} diff --git a/li.strolch.model/src/main/java/li/strolch/model/visitor/ElementStateVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/ElementStateVisitor.java new file mode 100644 index 000000000..561dfcef1 --- /dev/null +++ b/li.strolch.model/src/main/java/li/strolch/model/visitor/ElementStateVisitor.java @@ -0,0 +1,42 @@ +/* + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.model.visitor; + +import li.strolch.model.Order; +import li.strolch.model.Resource; +import li.strolch.model.State; +import li.strolch.model.activity.Activity; + +/** + * @author Robert von Burg + */ +public class ElementStateVisitor implements StrolchRootElementVisitor { + + @Override + public State visitOrder(Order order) { + return order.getState(); + } + + @Override + public State visitResource(Resource resource) { + throw new IllegalArgumentException("Resources have no state!"); + } + + @Override + public State visitActivity(Activity activity) { + return activity.getState(); + } +}