Author: elecharny
Date: Mon Apr 1 09:22:15 2013
New Revision: 1463117
URL: http://svn.apache.org/r1463117
Log:
Fixed the IntComparator and added a test for this class
Added:
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/IntComparatorTest.java
Modified:
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java
Modified:
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java?rev=1463117&r1=1463116&r2=1463117&view=diff
==============================================================================
---
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java
(original)
+++
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java
Mon Apr 1 09:22:15 2013
@@ -46,14 +46,25 @@ public class IntComparator implements Co
if ( integer1 == null )
{
- throw new IllegalArgumentException( "The first object to compare
must not be null" );
+ if ( integer2 == null )
+ {
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
}
-
- if ( integer2 == null )
+ else
{
- throw new IllegalArgumentException( "The second object to compare
must not be null" );
+ if ( integer2 == null )
+ {
+ return 1;
+ }
+ else
+ {
+ return integer1.compareTo( integer2 );
+ }
}
-
- return integer1.compareTo( integer2 );
}
}
Added:
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/IntComparatorTest.java
URL:
http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/IntComparatorTest.java?rev=1463117&view=auto
==============================================================================
---
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/IntComparatorTest.java
(added)
+++
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/IntComparatorTest.java
Mon Apr 1 09:22:15 2013
@@ -0,0 +1,51 @@
+/*
+ * 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 IntComparator class
+ *
+ * @author <a href="mailto:[email protected]">Mavibot labs Project</a>
+ */
+public class IntComparatorTest
+{
+ @Test
+ public void testIntComparator()
+ {
+ IntComparator comparator = new IntComparator();
+
+ assertEquals( 0, comparator.compare( null, null ) );
+ assertEquals( 0, comparator.compare( 1, 1 ) );
+ assertEquals( 0, comparator.compare( -1, -1 ) );
+ assertEquals( 1, comparator.compare( 1, null ) );
+ assertEquals( 1, comparator.compare( 2, 1 ) );
+ assertEquals( 1, comparator.compare( 3, 1 ) );
+ assertEquals( 1, comparator.compare( 1, -1 ) );
+ assertEquals( -1, comparator.compare( null, 1 ) );
+ assertEquals( -1, comparator.compare( 1, 2 ) );
+ assertEquals( -1, comparator.compare( -1, 1 ) );
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]