From 786a189943538074574b8d29bf6dbac4215f60f5 Mon Sep 17 00:00:00 2001 From: mdb Date: Tue, 18 Feb 2003 18:22:50 +0000 Subject: [PATCH] Implement Comparable. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1057 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/util/IntTuple.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/IntTuple.java b/projects/samskivert/src/java/com/samskivert/util/IntTuple.java index 006200c5..2a69172f 100644 --- a/projects/samskivert/src/java/com/samskivert/util/IntTuple.java +++ b/projects/samskivert/src/java/com/samskivert/util/IntTuple.java @@ -1,5 +1,5 @@ // -// $Id: IntTuple.java,v 1.2 2002/11/30 04:09:13 mdb Exp $ +// $Id: IntTuple.java,v 1.3 2003/02/18 18:22:50 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -24,6 +24,7 @@ package com.samskivert.util; * A simple object that holds a reference to two ints. */ public class IntTuple + implements Comparable { /** The left int. */ public int left; @@ -51,6 +52,17 @@ public class IntTuple return left ^ right; } + // documentation inherited from interface + public int compareTo (Object o) + { + if (o instanceof IntTuple) { + IntTuple ot = (IntTuple)o; + return (left == ot.left) ? (right - ot.right) : (left - ot.left); + } else { + return -1; + } + } + /** * A tuple is equal to another tuple if the left and right elements * are equal to the left and right elements (respectively) of the