1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
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.databoard.util;
14 import java.util.Comparator;
16 public class NumberComparator implements Comparator<Number> {
18 public static final NumberComparator INSTANCE = new NumberComparator();
21 public int compare(Number n1, Number n2) {
22 boolean integerCompare =
23 (n1 instanceof Float==false) &&
24 (n1 instanceof Double==false) &&
25 (n2 instanceof Float==false) &&
26 (n2 instanceof Double==false);
29 long v1 = n1.longValue();
30 long v2 = n2.longValue();
31 return (v1>v2 ? -1 : (v1==v2 ? 0 : 1));
33 double v1 = n1.doubleValue();
34 double v2 = n2.doubleValue();
35 return (v1>v2 ? -1 : (v1==v2 ? 0 : 1));