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