boolean (int c1Index, int c2Index) { LongArrayList c2Pairs = new LongArrayList(); long[] distincts = myData.toLongArray(); for (long distinct : distincts) { int pc1 = low(distinct); int pc2 = high(distinct); boolean addedToC1 = false; if (pc1 == c1Index || pc2 == c1Index) { addedToC1 = true; if (distinct < 0) { if (pc1 == c1Index && myData.contains(createPair(pc2, c2Index, true)) || pc2 == c1Index && myData.contains(createPair(c2Index, pc1, true))) { return false; } } } if (pc1 == c2Index || pc2 == c2Index) { if (addedToC1) return false; c2Pairs.add(distinct); } } for (int i = 0; i < c2Pairs.size(); i++) { long c = c2Pairs.getLong(i); myData.remove(c); if (c >= 0) { myData.add(createPair(c1Index, low(c) == c2Index ? high(c) : low(c), false)); } else if (low(c) == c2Index) { myData.add(createPair(c1Index, high(c), true)); } else { myData.add(createPair(low(c), c1Index, true)); } } return true; }