Commit in java/trunk/util on MAIN
pom.xml+19added 62
src/main/java/org/lcsim/hps/util/Pair.java+107added 62
+126
2 added files
add util package (just one class for now)

java/trunk/util
pom.xml added at 62
--- java/trunk/util/pom.xml	                        (rev 0)
+++ java/trunk/util/pom.xml	2013-12-03 21:36:45 UTC (rev 62)
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>hps-util</artifactId>
+    <groupId>org.hps</groupId>
+    <name>util</name>
+    <version>1.0-SNAPSHOT</version>
+    <description>miscellaneous utility classes</description>
+    <parent>
+        <groupId>org.lcsim</groupId>
+        <artifactId>lcsim-parent</artifactId>
+        <version>3.0-SNAPSHOT</version>
+    </parent>
+    <scm>
+        <connection>scm:svn:svn://svn.freehep.org/hps/java/trunk/util</connection>
+        <developerConnection>scm:svn:svn://svn.freehep.org/hps/java/trunk/util</developerConnection>
+        <url>http://java.freehep.org/svn/repos/hps/list/java/trunk/util/</url>
+    </scm>
+</project>

java/trunk/util/src/main/java/org/lcsim/hps/util
Pair.java added at 62
--- java/trunk/util/src/main/java/org/lcsim/hps/util/Pair.java	                        (rev 0)
+++ java/trunk/util/src/main/java/org/lcsim/hps/util/Pair.java	2013-12-03 21:36:45 UTC (rev 62)
@@ -0,0 +1,107 @@
+
+package org.lcsim.hps.util;
+
+
+/**
+ * A Class to hold a pair of immutable objects
+ * 
+ * 
+ * @author Omar Moreno <[log in to unmask]>
+ * @version $Id: Pair.java,v 1.1 2012/03/26 07:05:28 omoreno Exp $
+ */
+public class Pair<T, S> implements Comparable<Pair<T, S>> {
+    
+    private final T firstElement;
+    private final S secondElement;
+    
+    /**
+     * Default constructor 
+     * 
+     * @param firstElement
+     *      The first element in the pair
+     * @param secondElement
+     *      The second element in the pair
+     */
+    public Pair(T firstElement, S secondElement)
+    {
+        this.firstElement = firstElement;
+        this.secondElement = secondElement;
+    }
+    
+    /**
+     * Get the first element in the pair
+     * 
+     * @return firstElement
+     *      The first element in the pair
+     */
+    public T getFirstElement()
+    {
+        return firstElement;
+    }
+    
+    /**
+     * Get the second element in the pair
+     * 
+     * @return secondElement
+     *      The second element in the pair
+     */
+    public S getSecondElement()
+    {
+        return secondElement;
+    }
+    
+    /**
+     * Compares this pair to the specified pair
+     * 
+     * @param pair
+     *      The pair to compare to
+     * 
+     * @return returns 0, 1 or -1 if the hash code of the pair is equal, greater
+     *         than or less than the specified pair
+     */
+    @Override
+    public int compareTo(Pair<T,S> pair){
+        if(pair != null){
+            if(pair.equals(this)) return 0;
+            else if(pair.hashCode() > this.hashCode()) return 1;
+            else if(pair.hashCode() < this.hashCode()) return -1;
+        }
+        
+        return -1;
+    }
+
+    /**
+     * The hash code for the pair
+     */
+    @Override
+    public int hashCode()
+    {
+        int hashCode = firstElement.hashCode() + (31*secondElement.hashCode());
+        return hashCode;
+    }
+
+    /**
+     * Checks if the elements in this pair are equal to the elements of the 
+     * specified pair
+     * 
+     * @param obj
+     *      The pair to compare to
+     * @return true if both elements are equal, false otherwise
+     */
+    @Override
+    public boolean equals(Object obj) {
+        
+        if (obj == null) return false;
+      
+        if(obj.getClass() == Pair.class){
+        
+            final Pair<T, S> pair = (Pair<T, S>) obj;
+            if(!this.firstElement.equals(pair.firstElement) 
+               && (this.firstElement == null || !this.firstElement.equals(pair.firstElement))) return false;
+            if (this.secondElement != pair.secondElement 
+               && (this.secondElement == null || !this.secondElement.equals(pair.secondElement))) return false;
+        }
+        
+        return true;
+    }
+}
SVNspam 0.1