1 /*******************************************************************************
2 * Copyright (c) 2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.common.ids.elements;
14 import org.eclipse.winery.common.ids.GenericId;
15 import org.eclipse.winery.common.ids.XMLId;
18 * Models an ID of a TOSCA element, which is NOT a TOSCAcomponentId
20 * It has a parent and an xmlId
22 public abstract class TOSCAElementId extends GenericId {
24 private final GenericId parent;
27 public TOSCAElementId(GenericId parent, XMLId xmlId) {
33 public GenericId getParent() {
38 public boolean equals(Object obj) {
39 if (obj instanceof TOSCAElementId) {
40 TOSCAElementId otherId = (TOSCAElementId) obj;
41 // the XML id has to be equal and the parents have to be equal
42 return (otherId.getXmlId().equals(this.getXmlId())) && (otherId.getParent().equals(this.getParent()));
49 public int compareTo(GenericId o1) {
50 if (o1 instanceof TOSCAElementId) {
51 TOSCAElementId o = (TOSCAElementId) o1;
52 if (this.getParent().equals(o.getParent())) {
53 return this.getXmlId().compareTo(o.getXmlId());
55 return this.getParent().compareTo(o.getParent());
58 // comparing TOSCAcomponentIDs with non-TOSCAcomponentIDs is not
60 throw new IllegalStateException();
65 public int hashCode() {
66 return this.getParent().hashCode() ^ this.getXmlId().hashCode();
70 public String toString() {
72 res = this.getClass().toString() + " / " + this.getXmlId().getDecoded();
74 res += "parent: " + this.getParent().toString();