Relatedness implements Comparable<Relatedness> { public static int[] intersection(int[] a, int[] b, int aSize, int bSize) { int i = 0, j = 0; list.clear(); while ((i < aSize) && (j < bSize)) { if (a[i] < b[j]) { i++; continue; } if (a[i] > b[j]) { j++; continue; } list.add(a[i]); i++; j++; } return list.toIntArray(); } Relatedness(); protected  Relatedness(int x, int y); void set(int x, int y); void setScore(double score); @Override int compareTo(Relatedness r); abstract String getName(); boolean hasNegativeScores(); abstract Relatedness copy(); @Override int hashCode(); @Override boolean equals(Object obj); double getScore(); int getX(); void setX(int x); int getY(); void setY(int y); int[] outX(); int[] outY(); int[] inIntersection(); int[] outIntersection(); int[] inoutX(); int[] inoutY(); static int[] sortedunion(int[] a, int[] b, int aSize, int bSize); static int[] intersection(int[] a, int[] b, int aSize, int bSize); static int intersectionSize(int[] a, int[] b, int aSize, int bSize); static int unionSize(int[] a, int[] b, int aSize, int bSize); @Override String toString(); String getNames();  }
@Test public void testIntersection() { int[] a = new int[] { 1,3,5,10,12}; int[] b = new int[] {1,12,20}; int[] inter = new int[] {1,12}; int[] union = new int[] {1,3,5,10,12,20}; Assert.assertArrayEquals(inter, Relatedness.intersection(a, b, 5, 3)); Assert.assertArrayEquals(union, Relatedness.sortedunion(a, b, 5, 3)); }