int (Object o1, Object o2) { final Long w1 = myWeights.get(o1); final Long w2 = myWeights.get(o2); if (w1 != null || w2 != null) { return w1 != null && w2 != null ? sign(w2 - w1) : w1 != null ? -1 : 1; } return myInitialPositions.indexOf(o1) - myInitialPositions.indexOf(o2); }