diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/IdentifierUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/IdentifierUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..290e5fb5893286ff248bb243d25bff228db44f76 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/IdentifierUtils.java @@ -0,0 +1,48 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| 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.kernel.utils; + +import org.fortiss.tooling.kernel.model.INamedElement; + +/** + * Utility class for unique identifiers. + * + * @author hoelzl + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +public class IdentifierUtils { + + /** + * Returns the unique identifier built from the model element's name and ID. + * All non-word characters in the returned string are replace with '_'. + */ + public static String getUniqueIdentifier(INamedElement modelElement) { + return (modelElement.getName() + "_ID_" + modelElement.getId()) + .replaceAll("\\W", "_"); + } + + /** + * Returns the identifier built from the model element's name. All non-word + * characters in the returned string are replace with '_'. + */ + public static String getIdentifier(INamedElement modelElement) { + return modelElement.getName().replaceAll("\\W", "_"); + } +}