From bd7b07f3f126891545674e6ef0878ccd8b51967b Mon Sep 17 00:00:00 2001 From: asivache Date: Mon, 14 Dec 2009 00:15:44 +0000 Subject: [PATCH] added PrimitivePair.Long and a few shortcut utility methods to PrimitivePairs: add(pair), subtract(pair), assignFrom(pair) git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2347 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/PrimitivePair.java | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/java/src/org/broadinstitute/sting/utils/PrimitivePair.java b/java/src/org/broadinstitute/sting/utils/PrimitivePair.java index 7363ba3c3..8abb41414 100644 --- a/java/src/org/broadinstitute/sting/utils/PrimitivePair.java +++ b/java/src/org/broadinstitute/sting/utils/PrimitivePair.java @@ -29,5 +29,147 @@ public class PrimitivePair { the member field. */ public int getSecond() { return second; } + + /** Increments the elements of this pair by the + * corresponding elements of the pair p and returns this + * pair (modified). This method does not allocate a new pair, but changes + * in place the values stored in the object the method is invoked from. The + * method is unsafe: if p is null, a runtime exception will be thrown. + * @param p + * @return + */ + public PrimitivePair.Int add(PrimitivePair.Int p) { + first += p.first; + second += p.second; + return this; + } + + /** Decrements the elements of this pair by the + * corresponding elements of the pair p and returns this + * pair (modified). This method does not allocate a new pair, but changes + * in place the values stored in the object the method is invoked from. The + * method is unsafe: if p is null, a runtime exception will be thrown. + * @param p + * @return + */ + public PrimitivePair.Int subtract(PrimitivePair.Int p) { + first -= p.first; + second -= p.second; + return this; + } + + /** Copies values from the argument p into the corresponding + * elements of this pair and returns this pair (modified). + * @param p + * @return + */ + public PrimitivePair.Int assignFrom(PrimitivePair.Int p ) { + first = p.first; + second = p.second; + return this; + } + + } + + public static class Long { + // declare public, STL-style for easier and more efficient access: + public long first; + public long second; + + public Long(long x, long y) { first = x; second = y; } + public Long() { first = second = 0; } + + public void set(long x, long y) { first = x; second = y; } + + /** Java-style getter; note that we currently allow direct access to + the member field. + */ + public long getFirst() { return first; } + + /** Java-style getter; note that we currently allow direct access to + the member field. + */ + public long getSecond() { return second; } + + /** Increments the elements of this pair by the + * corresponding elements of the pair p and returns this + * pair (modified). This method does not allocate a new pair, but changes + * in place the values stored in the object the method is invoked from. The + * method is unsafe: if p is null, a runtime exception will be thrown. + * @param p + * @return + */ + public PrimitivePair.Long add(PrimitivePair.Int p) { + first += p.first; + second += p.second; + return this; + } + + /** Increments the elements of this pair by the + * corresponding elements of the pair p and returns this + * pair (modified). This method does not allocate a new pair, but changes + * in place the values stored in the object the method is invoked from. The + * method is unsafe: if p is null, a runtime exception will be thrown. + * @param p + * @return + */ + public PrimitivePair.Long add(PrimitivePair.Long p) { + first += p.first; + second += p.second; + return this; + } + + /** Decrements the elements of this pair by the + * corresponding elements of the pair p and returns this + * pair (modified). This method does not allocate a new pair, but changes + * in place the values stored in the object the method is invoked from. The + * method is unsafe: if p is null, a runtime exception will be thrown. + * @param p + * @return + */ + public PrimitivePair.Long subtract(PrimitivePair.Int p) { + first -= p.first; + second -= p.second; + return this; + } + + /** Decrements the elements of this pair by the + * corresponding elements of the pair p and returns this + * pair (modified). This method does not allocate a new pair, but changes + * in place the values stored in the object the method is invoked from. The + * method is unsafe: if p is null, a runtime exception will be thrown. + * @param p + * @return + */ + public PrimitivePair.Long subtract(PrimitivePair.Long p) { + first -= p.first; + second -= p.second; + return this; + } + + /** Copies values from the argument p into the corresponding + * elements of this pair and returns this pair (modified). + * @param p + * @return + */ + public PrimitivePair.Long assignFrom(PrimitivePair.Long p ) { + first = p.first; + second = p.second; + return this; + } + + /** Copies values from the argument p into the corresponding + * elements of this pair and returns this pair (modified). + * @param p + * @return + */ + public PrimitivePair.Long assignFrom(PrimitivePair.Int p ) { + first = p.first; + second = p.second; + return this; + } + + } + }