Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 487C311F34 for ; Tue, 23 Sep 2014 04:47:20 +0000 (UTC) Received: (qmail 42679 invoked by uid 500); 23 Sep 2014 04:47:20 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 42639 invoked by uid 500); 23 Sep 2014 04:47:20 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 42630 invoked by uid 99); 23 Sep 2014 04:47:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Sep 2014 04:47:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Sep 2014 04:47:18 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D04C12388993; Tue, 23 Sep 2014 04:46:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1626937 - /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Tuple.java Date: Tue, 23 Sep 2014 04:46:58 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140923044658.D04C12388993@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Tue Sep 23 04:46:58 2014 New Revision: 1626937 URL: http://svn.apache.org/r1626937 Log: o The class now implements Comparable o Added a Comparator for the keys o Added the missing hasCode() and equals() methods Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Tuple.java Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Tuple.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Tuple.java?rev=1626937&r1=1626936&r2=1626937&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Tuple.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Tuple.java Tue Sep 23 04:46:58 2014 @@ -20,6 +20,9 @@ package org.apache.directory.mavibot.btree; +import java.util.Comparator; + + /** * The Tuple class is used when we browse a btree, it will contain the results * fetched from the btree. @@ -29,7 +32,7 @@ package org.apache.directory.mavibot.btr * @param The type for the Key * @param The type for the stored value */ -public class Tuple +public class Tuple implements Comparable> { /** The key */ protected K key; @@ -37,6 +40,9 @@ public class Tuple /** The value */ protected V value; + /** The key comparator */ + protected Comparator keyComparator; + /** * Creates a Tuple with no content @@ -59,6 +65,19 @@ public class Tuple /** + * Creates a Tuple containing a key and its associated value. + * @param key The key + * @param value The associated value + */ + public Tuple( K key, V value, Comparator keyComparator ) + { + this.key = key; + this.value = value; + this.keyComparator = keyComparator; + } + + + /** * @return the key */ public K getKey() @@ -95,6 +114,77 @@ public class Tuple /** + * @see Object#hashCode() + */ + @Override + public int hashCode() + { + return key.hashCode(); + } + + + /** + * @see Object#equals() + */ + @SuppressWarnings("unchecked") + @Override + public boolean equals( Object obj ) + { + if ( this == obj ) + { + return true; + } + + if ( !( obj instanceof Tuple ) ) + { + return false; + } + + if ( this.key == null ) + { + return ( ( Tuple ) obj ).key == null; + } + + return this.key.equals( ( ( Tuple ) obj ).key ); + } + + + /** + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo( Tuple t ) + { + if ( keyComparator != null ) + { + return keyComparator.compare( key, t.key ); + } + else + { + return 0; + } + } + + + /** + * @return the keyComparator + */ + public Comparator getKeyComparator() + { + return keyComparator; + } + + + /** + * @param keyComparator the keyComparator to set + */ + public void setKeyComparator( Comparator keyComparator ) + { + this.keyComparator = keyComparator; + } + + + /** * @see Object#toString() */ public String toString()