From f1f7aea50ee2fcc6ed09a147a2afa5e3cd0cf801 Mon Sep 17 00:00:00 2001 From: David Trachtenherz <trachtenherz@fortiss.org> Date: Thu, 1 Dec 2011 13:44:58 +0000 Subject: [PATCH] Some static utility methods moved to new class ModelElementUtils refs 337 --- .../tooling/base/utils/ModelElementUtils.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/ModelElementUtils.java diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/ModelElementUtils.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/ModelElementUtils.java new file mode 100644 index 000000000..0929055ef --- /dev/null +++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/ModelElementUtils.java @@ -0,0 +1,77 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2011 ForTISS GmbH | +| | +| 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 org.fortiss.tooling.base.utils; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.fortiss.tooling.base.model.element.IHiddenSpecification; +import org.fortiss.tooling.base.model.element.IModelElement; +import org.fortiss.tooling.base.model.element.IModelElementSpecification; + +/** + * Utility class for model elements. + * + * @see IModelElement + * @see IModelElementSpecification + * + * @author trachtenherz + * @author $Author: hoelzl $ + * @version $Rev: 18709 $ + * @ConQAT.Rating RED Hash: + */ +public class ModelElementUtils { + /** + * Returns a list of specifications from {@code specifications} that are not + * subclass of {@link IHiddenSpecification}. + */ + public static List<IModelElementSpecification> nonHiddenSpecifications( + Collection<IModelElementSpecification> specifications) { + List<IModelElementSpecification> res = new LinkedList<IModelElementSpecification>(); + for (IModelElementSpecification s : specifications) { + if (!(s instanceof IHiddenSpecification)) { + res.add(s); + } + } + return res; + } + + /** + * Returns the {@link IModelElementSpecification#specificationDescription()} + * result for {@code spec}. + * <p> + * If the specification is hidden (instance of {@link IHiddenSpecification}) + * or does not support this operation ( + * {@link IModelElementSpecification#specificationDescription()} throws + * {@link UnsupportedOperationException}) then empty string is returned. + * + */ + public static String specificationDescription( + IModelElementSpecification spec) { + if (spec instanceof IHiddenSpecification) { + // Empty representation for hidden specifications + return ""; + } + try { + return spec.specificationDescription(); + } catch (UnsupportedOperationException e) { + return ""; + } + } +} -- GitLab