1 /*******************************************************************************
2 * Copyright (c) 2012-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.topologymodeler;
14 import java.util.List;
15 import java.util.SortedMap;
16 import java.util.SortedSet;
17 import java.util.TreeMap;
18 import java.util.TreeSet;
20 import org.eclipse.winery.common.interfaces.QNameWithName;
22 public class WineryUtil {
25 * LocalName is the ID of the element, whereas Name is the speaking name
27 public static class LocalNameNamePair implements Comparable<LocalNameNamePair> {
33 public LocalNameNamePair(String localName, String name) {
34 this.localName = localName;
38 public String getLocalName() {
39 return this.localName;
42 public String getName() {
47 * Ordering according to name
50 public int compareTo(LocalNameNamePair otherPair) {
51 return this.name.compareTo(otherPair.name);
55 public int hashCode() {
56 return this.localName.hashCode();
60 public boolean equals(Object o) {
61 if (o instanceof LocalNameNamePair) {
62 return this.localName.equals(((LocalNameNamePair) o).getLocalName());
70 public static SortedMap<String, SortedSet<LocalNameNamePair>> convertQNameWithNameListToNamespaceToLocalNameNamePairList(List<QNameWithName> list) {
72 throw new IllegalArgumentException("list may not be null");
74 SortedMap<String, SortedSet<LocalNameNamePair>> res = new TreeMap<>();
75 for (QNameWithName qnameWithName : list) {
76 SortedSet<LocalNameNamePair> localNameNamePairSet = res.get(qnameWithName.qname.getNamespaceURI());
77 if (localNameNamePairSet == null) {
78 localNameNamePairSet = new TreeSet<>();
79 res.put(qnameWithName.qname.getNamespaceURI(), localNameNamePairSet);
81 LocalNameNamePair pair = new LocalNameNamePair(qnameWithName.qname.getLocalPart(), qnameWithName.name);
82 localNameNamePairSet.add(pair);