1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.util;
14 import java.util.Comparator;
\r
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));