]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/internal/ComparableWrapper.java
1c23685ae0443950338d1713d52de87759fb59f8
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / internal / ComparableWrapper.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.common.internal;\r
13 \r
14 import java.util.TreeSet;\r
15 \r
16 /**\r
17  * A wrapper Comparable class for allowing the creation of "multisets" with the\r
18  * basic {@link TreeSet} implementation.\r
19  * \r
20  * <p>\r
21  * This class will define the {@link Comparable#compareTo(Object)} method in\r
22  * such a way that the result will only be 0 if both the wrapped object and the\r
23  * {@link #orderNumber} argument match.\r
24  * \r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public class ComparableWrapper<T extends Comparable<T>> implements Comparable<ComparableWrapper<T>> {\r
28     public final T   t;\r
29     public final int orderNumber;\r
30 \r
31     public ComparableWrapper(T t, int orderNumber) {\r
32         assert t != null;\r
33         this.t = t;\r
34         this.orderNumber = orderNumber;\r
35     }\r
36 \r
37     @Override\r
38     public int compareTo(ComparableWrapper<T> o) {\r
39         int result = t.compareTo(o.t);\r
40         return result != 0 ? result : (orderNumber - o.orderNumber);\r
41     }\r
42 }\r