You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by el...@apache.org on 2013/03/31 21:37:11 UTC

svn commit: r1463035 - in /labs/mavibot/branches/mavibot-multivalue-support/mavibot/src: main/java/org/apache/mavibot/btree/comparator/ test/java/org/apache/mavibot/btree/comparator/

Author: elecharny
Date: Sun Mar 31 19:37:11 2013
New Revision: 1463035

URL: http://svn.apache.org/r1463035
Log:
o Added the Boolean and BooleanArray comparators
o Added the associated tests

Added:
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanArrayComparatorTest.java
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanComparatorTest.java
Modified:
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanArrayComparator.java
    labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java

Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanArrayComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanArrayComparator.java?rev=1463035&r1=1463034&r2=1463035&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanArrayComparator.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanArrayComparator.java Sun Mar 31 19:37:11 2013
@@ -47,12 +47,12 @@ public class BooleanArrayComparator impl
 
         if ( booleanArray1 == null )
         {
-            throw new IllegalArgumentException( "The first object to compare must not be null" );
+            return -1;
         }
 
         if ( booleanArray2 == null )
         {
-            throw new IllegalArgumentException( "The second object to compare must not be null" );
+            return 1;
         }
 
         if ( booleanArray1.length < booleanArray2.length )

Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java?rev=1463035&r1=1463034&r2=1463035&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java Sun Mar 31 19:37:11 2013
@@ -46,12 +46,12 @@ public class BooleanComparator implement
 
         if ( boolean1 == null )
         {
-            throw new IllegalArgumentException( "The first object to compare must not be null" );
+            return -1;
         }
 
         if ( boolean2 == null )
         {
-            throw new IllegalArgumentException( "The second object to compare must not be null" );
+            return 1;
         }
 
         return boolean1.compareTo( boolean2 );

Added: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanArrayComparatorTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanArrayComparatorTest.java?rev=1463035&view=auto
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanArrayComparatorTest.java (added)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanArrayComparatorTest.java Sun Mar 31 19:37:11 2013
@@ -0,0 +1,82 @@
+/*
+ *  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.mavibot.btree.comparator;
+
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+/**
+ * Test the BooleanArrayComparator class
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class BooleanArrayComparatorTest
+{
+    @Test
+    public void testBooleanArrayComparator()
+    {
+        BooleanArrayComparator comparator = new BooleanArrayComparator();
+
+        assertEquals( 0, comparator.compare( null, null ) );
+
+        boolean[] b1 = new boolean[]
+            { true, true, true };
+        boolean[] b2 = new boolean[]
+            { true, true, false };
+        boolean[] b3 = new boolean[]
+            { true, false, true };
+        boolean[] b4 = new boolean[]
+            { false, true, true };
+        boolean[] b5 = new boolean[]
+            { true, true };
+
+        // 0
+        assertEquals( 0, comparator.compare( null, null ) );
+        assertEquals( 0, comparator.compare( new boolean[]
+            {}, new boolean[]
+            {} ) );
+        assertEquals( 0, comparator.compare( b1, b1 ) );
+
+        // -1
+        assertEquals( -1, comparator.compare( null, new boolean[]
+            {} ) );
+        assertEquals( -1, comparator.compare( null, b1 ) );
+        assertEquals( -1, comparator.compare( new boolean[]
+            {}, b1 ) );
+        assertEquals( -1, comparator.compare( new boolean[]
+            {}, b4 ) );
+        assertEquals( -1, comparator.compare( b5, b1 ) );
+        assertEquals( -1, comparator.compare( b5, b3 ) );
+
+        // 1
+        assertEquals( 1, comparator.compare( new boolean[]
+            {}, null ) );
+        assertEquals( 1, comparator.compare( b1, null ) );
+        assertEquals( 1, comparator.compare( b1, new boolean[]
+            {} ) );
+        assertEquals( 1, comparator.compare( b1, b2 ) );
+        assertEquals( 1, comparator.compare( b1, b3 ) );
+        assertEquals( 1, comparator.compare( b1, b4 ) );
+        assertEquals( 1, comparator.compare( b1, b5 ) );
+    }
+}

Added: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanComparatorTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanComparatorTest.java?rev=1463035&view=auto
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanComparatorTest.java (added)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/BooleanComparatorTest.java Sun Mar 31 19:37:11 2013
@@ -0,0 +1,50 @@
+/*
+ *  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.mavibot.btree.comparator;
+
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+/**
+ * Test the BooleanComparator class
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class BooleanComparatorTest
+{
+    @Test
+    public void testBooleanComparator()
+    {
+        BooleanComparator comparator = new BooleanComparator();
+
+        assertEquals( 0, comparator.compare( null, null ) );
+        assertEquals( 0, comparator.compare( true, true ) );
+        assertEquals( 0, comparator.compare( false, false ) );
+        assertEquals( 1, comparator.compare( false, null ) );
+        assertEquals( 1, comparator.compare( true, null ) );
+        assertEquals( 1, comparator.compare( true, false ) );
+        assertEquals( -1, comparator.compare( null, false ) );
+        assertEquals( -1, comparator.compare( null, true ) );
+        assertEquals( -1, comparator.compare( false, true ) );
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org