incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1228612 - /incubator/lcf/warthog/trunk/src/main/java/org/apache/warthog/api/DoubleComparatorAscending.java
Date Sat, 07 Jan 2012 13:21:10 GMT
Author: kwright
Date: Sat Jan  7 13:21:10 2012
New Revision: 1228612

URL: http://svn.apache.org/viewvc?rev=1228612&view=rev
Log:
Add a double comparator

Added:
    incubator/lcf/warthog/trunk/src/main/java/org/apache/warthog/api/DoubleComparatorAscending.java
  (with props)

Added: incubator/lcf/warthog/trunk/src/main/java/org/apache/warthog/api/DoubleComparatorAscending.java
URL: http://svn.apache.org/viewvc/incubator/lcf/warthog/trunk/src/main/java/org/apache/warthog/api/DoubleComparatorAscending.java?rev=1228612&view=auto
==============================================================================
--- incubator/lcf/warthog/trunk/src/main/java/org/apache/warthog/api/DoubleComparatorAscending.java
(added)
+++ incubator/lcf/warthog/trunk/src/main/java/org/apache/warthog/api/DoubleComparatorAscending.java
Sat Jan  7 13:21:10 2012
@@ -0,0 +1,46 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.api;
+
+/** Class that compares double values, and sorts in ascending order.
+*/
+public class DoubleComparatorAscending implements WHComparator
+{
+  /** Comparison method.
+  * This is only ever used to compare values; it cannot be used to compare null vs. non-null.
+  */
+  public int compare(WHValue leftValue, WHValue rightValue)
+    throws WHException
+  {
+    if (leftValue == null && rightValue == null)
+      return RESULT_EQUALS;
+    // Sort null values to the end
+    if (leftValue == null)
+      return RESULT_LESS;
+    if (rightValue == null)
+      return RESULT_GREATER;
+    double leftDoubleValue = leftValue.doubleValue();
+    double rightDoubleValue = rightValue.doubleValue();
+    if (leftDoubleValue == rightDoubleValue)
+      return RESULT_EQUALS;
+    return (leftDoubleValue < rightDoubleValue)?RESULT_GREATER:RESULT_LESS;
+  }
+  
+}
\ No newline at end of file

Propchange: incubator/lcf/warthog/trunk/src/main/java/org/apache/warthog/api/DoubleComparatorAscending.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/warthog/trunk/src/main/java/org/apache/warthog/api/DoubleComparatorAscending.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message