1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.common.internal;
14 import java.util.TreeSet;
17 * A wrapper Comparable class for allowing the creation of "multisets" with the
18 * basic {@link TreeSet} implementation.
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.
25 * @author Tuukka Lehtonen
27 public class ComparableWrapper<T extends Comparable<T>> implements Comparable<ComparableWrapper<T>> {
29 public final int orderNumber;
31 public ComparableWrapper(T t, int orderNumber) {
34 this.orderNumber = orderNumber;
38 public int compareTo(ComparableWrapper<T> o) {
39 int result = t.compareTo(o.t);
40 return result != 0 ? result : (orderNumber - o.orderNumber);