Skip to content
Snippets Groups Projects
Commit f1f7aea5 authored by David Trachtenherz's avatar David Trachtenherz
Browse files

Some static utility methods moved to new class ModelElementUtils

refs 337
parent f1c01aeb
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$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 "";
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment