1 /*******************************************************************************
2 * Copyright (c) 2015 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.repository.datatypes.select2;
14 import java.util.HashMap;
16 import java.util.SortedSet;
17 import java.util.TreeSet;
19 public class Select2DataWithOptGroups {
21 Map<String, Select2OptGroup> idx = new HashMap<>();
25 * Add an item to a group
27 * @param group the group
28 * @param id the id of the item
29 * @param text the text of the item {@inheritDoc}
31 public void add(String group, String id, String text) {
32 Select2OptGroup optGroup = this.idx.get(group);
33 if (optGroup == null) {
34 optGroup = new Select2OptGroup(group);
35 this.idx.put(group, optGroup);
38 Select2DataItem item = new Select2DataItem(id, text);
39 optGroup.addItem(item);
42 public SortedSet<Select2OptGroup> asSortedSet() {
43 // convert the index to the real result
44 SortedSet<Select2OptGroup> res = new TreeSet<>();
45 for (Select2OptGroup optGroup : this.idx.values()) {