LongPredicate (boolean forClasses) { return new LongPredicate() { boolean addZero = forClasses ? classPackageHashes.hasNull() : resourcePackageHashes.hasNull(); @Override public boolean test(long it) { if (it == 0) { if (!addZero) { return false; } addZero = false; } return true; } }; }