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 17:34:00 UTC
svn commit: r1462987 -
/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/
Author: elecharny
Date: Sun Mar 31 15:34:00 2013
New Revision: 1462987
URL: http://svn.apache.org/r1462987
Log:
Added some array comparators for int, boolean, char, short
Added:
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/CharArrayComparator.java
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntArrayComparator.java
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortArrayComparator.java
Modified:
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/LongArrayComparator.java
Added: 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=1462987&view=auto
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanArrayComparator.java (added)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanArrayComparator.java Sun Mar 31 15:34:00 2013
@@ -0,0 +1,98 @@
+/*
+ * 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 java.util.Comparator;
+
+
+/**
+ * Compares boolean arrays. A boolean is considered as below the other one if the first boolean
+ * is false when the second one is true.
+ *
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class BooleanArrayComparator implements Comparator<boolean[]>
+{
+ /**
+ * Compare two boolean arrays.
+ *
+ * @param booleanArray1 First boolean array
+ * @param booleanArray2 Second boolean array
+ * @return 1 if booleanArray1 > booleanArray2, 0 if booleanArray1 == booleanArray2, -1 if booleanArray1 < booleanArray2
+ */
+ public int compare( boolean[] booleanArray1, boolean[] booleanArray2 )
+ {
+ if ( booleanArray1 == booleanArray2 )
+ {
+ return 0;
+ }
+
+ if ( booleanArray1 == null )
+ {
+ throw new IllegalArgumentException( "The first object to compare must not be null" );
+ }
+
+ if ( booleanArray2 == null )
+ {
+ throw new IllegalArgumentException( "The second object to compare must not be null" );
+ }
+
+ if ( booleanArray1.length < booleanArray2.length )
+ {
+ return -1;
+ }
+
+ if ( booleanArray1.length > booleanArray2.length )
+ {
+ return 1;
+ }
+
+ for ( int pos = 0; pos < booleanArray1.length; pos++ )
+ {
+ int comp = compare( booleanArray1[pos], booleanArray2[pos] );
+
+ if ( comp != 0 )
+ {
+ return comp;
+ }
+ }
+
+ return 0;
+ }
+
+
+ private int compare( boolean boolean1, boolean boolean2 )
+ {
+ if ( boolean1 == boolean2 )
+ {
+ return 0;
+ }
+
+ if ( boolean1 )
+ {
+ return 1;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+}
Added: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/CharArrayComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/CharArrayComparator.java?rev=1462987&view=auto
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/CharArrayComparator.java (added)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/CharArrayComparator.java Sun Mar 31 15:34:00 2013
@@ -0,0 +1,95 @@
+/*
+ * 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 java.util.Comparator;
+
+
+/**
+ * Compares char arrays
+ *
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class CharArrayComparator implements Comparator<char[]>
+{
+ /**
+ * Compare two char arrays.
+ *
+ * @param charArray1 First char array
+ * @param charArray2 Second char array
+ * @return 1 if charArray1 > charArray2, 0 if charArray1 == charArray2, -1 if charArray1 < charArray2
+ */
+ public int compare( char[] charArray1, char[] charArray2 )
+ {
+ if ( charArray1 == charArray2 )
+ {
+ return 0;
+ }
+
+ if ( charArray1 == null )
+ {
+ throw new IllegalArgumentException( "The first object to compare must not be null" );
+ }
+
+ if ( charArray2 == null )
+ {
+ throw new IllegalArgumentException( "The second object to compare must not be null" );
+ }
+
+ if ( charArray1.length < charArray2.length )
+ {
+ return -1;
+ }
+
+ if ( charArray1.length > charArray2.length )
+ {
+ return 1;
+ }
+
+ for ( int pos = 0; pos < charArray1.length; pos++ )
+ {
+ int comp = compare( charArray1[pos], charArray2[pos] );
+
+ if ( comp != 0 )
+ {
+ return comp;
+ }
+ }
+
+ return 0;
+ }
+
+
+ private int compare( char char1, char char2 )
+ {
+ if ( char1 < char2 )
+ {
+ return -1;
+ }
+
+ if ( char1 > char2 )
+ {
+ return 1;
+ }
+
+ return 0;
+ }
+}
Added: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntArrayComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntArrayComparator.java?rev=1462987&view=auto
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntArrayComparator.java (added)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntArrayComparator.java Sun Mar 31 15:34:00 2013
@@ -0,0 +1,95 @@
+/*
+ * 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 java.util.Comparator;
+
+
+/**
+ * Compares int arrays
+ *
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class IntArrayComparator implements Comparator<int[]>
+{
+ /**
+ * Compare two long arrays.
+ *
+ * @param intArray1 First int array
+ * @param intArray2 Second int array
+ * @return 1 if intArray1 > intArray2, 0 if intArray1 == intArray2, -1 if intArray1 < intArray2
+ */
+ public int compare( int[] intArray1, int[] intArray2 )
+ {
+ if ( intArray1 == intArray2 )
+ {
+ return 0;
+ }
+
+ if ( intArray1 == null )
+ {
+ throw new IllegalArgumentException( "The first object to compare must not be null" );
+ }
+
+ if ( intArray2 == null )
+ {
+ throw new IllegalArgumentException( "The second object to compare must not be null" );
+ }
+
+ if ( intArray1.length < intArray2.length )
+ {
+ return -1;
+ }
+
+ if ( intArray1.length > intArray2.length )
+ {
+ return 1;
+ }
+
+ for ( int pos = 0; pos < intArray1.length; pos++ )
+ {
+ int comp = compare( intArray1[pos], intArray2[pos] );
+
+ if ( comp != 0 )
+ {
+ return comp;
+ }
+ }
+
+ return 0;
+ }
+
+
+ private int compare( int int1, int int2 )
+ {
+ if ( int1 < int2 )
+ {
+ return -1;
+ }
+
+ if ( int1 > int2 )
+ {
+ return 1;
+ }
+
+ return 0;
+ }
+}
Modified: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/LongArrayComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/LongArrayComparator.java?rev=1462987&r1=1462986&r2=1462987&view=diff
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/LongArrayComparator.java (original)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/LongArrayComparator.java Sun Mar 31 15:34:00 2013
@@ -33,8 +33,8 @@ public class LongArrayComparator impleme
/**
* Compare two long arrays.
*
- * @param longArray1 First longArray
- * @param longArray2 Second longArray
+ * @param longArray1 First long array
+ * @param longArray2 Second long array
* @return 1 if longArray1 > longArray2, 0 if longArray1 == longArray2, -1 if longArray1 < longArray2
*/
public int compare( long[] longArray1, long[] longArray2 )
@@ -84,6 +84,7 @@ public class LongArrayComparator impleme
{
return -1;
}
+
if ( long1 > long2 )
{
return 1;
Added: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortArrayComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortArrayComparator.java?rev=1462987&view=auto
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortArrayComparator.java (added)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortArrayComparator.java Sun Mar 31 15:34:00 2013
@@ -0,0 +1,95 @@
+/*
+ * 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 java.util.Comparator;
+
+
+/**
+ * Compares short arrays
+ *
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class ShortArrayComparator implements Comparator<short[]>
+{
+ /**
+ * Compare two short arrays.
+ *
+ * @param shortArray1 First short array
+ * @param shortArray2 Second short array
+ * @return 1 if shortArray1 > shortArray2, 0 if shortArray1 == shortArray2, -1 if shortArray1 < shortArray2
+ */
+ public int compare( short[] shortArray1, short[] shortArray2 )
+ {
+ if ( shortArray1 == shortArray2 )
+ {
+ return 0;
+ }
+
+ if ( shortArray1 == null )
+ {
+ throw new IllegalArgumentException( "The first object to compare must not be null" );
+ }
+
+ if ( shortArray2 == null )
+ {
+ throw new IllegalArgumentException( "The second object to compare must not be null" );
+ }
+
+ if ( shortArray1.length < shortArray2.length )
+ {
+ return -1;
+ }
+
+ if ( shortArray1.length > shortArray2.length )
+ {
+ return 1;
+ }
+
+ for ( int pos = 0; pos < shortArray1.length; pos++ )
+ {
+ int comp = compare( shortArray1[pos], shortArray2[pos] );
+
+ if ( comp != 0 )
+ {
+ return comp;
+ }
+ }
+
+ return 0;
+ }
+
+
+ private int compare( short short1, short short2 )
+ {
+ if ( short1 < short2 )
+ {
+ return -1;
+ }
+
+ if ( short1 > short2 )
+ {
+ return 1;
+ }
+
+ return 0;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org