int[] の hashCode() と equals() が不十分に実装されているか、まったく実装されていないようです! (Android でテスト済みですが、どの Java 環境にも当てはまると思います)。
HashSet.contains() を適切に動作させるために、int[] のラッパーを作成する必要がありました (私のコーディング スタイルを批判しないでください。本質を見てください)。
public class IntArray {
private int[] value;
public IntArray(int[] value) {
this.value = value;
}
@Override
public int hashCode() {
int sum = 0;
// Integer overflows are cheerfully welcome.
for (int elem: value) sum += elem;
return sum;
}
@Override
public boolean equals(Object o) {
if (o == null) return (value==null);
if (value != null) {
if (o instanceof int[])
return compare((int[])o);
if (o instanceof IntArray)
return compare(((IntArray)o).value);
}
return false;
}
protected boolean compare(int[] other) {
int len = value.length;
if (other.length != len) return false;
for (int i=0; i<len ; i++)
if (value[i] != other[i]) return false;
return true;
}
}
問題なく動作しますが、カスタム ラッパーやサードパーティ ライブラリは避けたいと思います。オプションはありますか?