Add winery source code
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / datatypes / select2 / Select2DataItem.java
1 /*******************************************************************************
2  * Copyright (c) 2014 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
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.datatypes.select2;
13
14 /**
15  * Models a data item for select2. In case optgroups have to be returned, use
16  * this element in a TreeMap
17  */
18 public class Select2DataItem implements Comparable<Select2DataItem> {
19         
20         private final String id;
21         private final String text;
22         
23         
24         public Select2DataItem(String id, String text) {
25                 this.id = id;
26                 this.text = text;
27         }
28         
29         public String getId() {
30                 return this.id;
31         }
32         
33         public String getText() {
34                 return this.text;
35         }
36         
37         /**
38          * Sort order is based on text
39          */
40         @Override
41         public int compareTo(Select2DataItem o) {
42                 return this.getText().compareTo(o.getText());
43         }
44         
45         /**
46          * Equality is checked at id level
47          */
48         @Override
49         public boolean equals(Object o) {
50                 if (!(o instanceof Select2DataItem)) {
51                         return false;
52                 }
53                 return this.getId().equals(((Select2DataItem) o).getId());
54         }
55         
56 }