/** * Addes a skip of the given size to the start of the nindo if distance is * positive, reduces initial skips if the distance is negative. * * @return a new nindo */ public static Nindo shift(final int distance, Nindo nindo) { int remaining = Math.max(0, -distance); Builder b = builder(); if (distance > 0) { b.skip(distance); } for (MutationComponent c : nindo.mutationList) { if (remaining > 0) { if (c instanceof Skip) { int skipSize = ((Skip) c).skipSize; int diff = Math.min(remaining, skipSize); remaining -= diff; if (diff < skipSize) { b.skip(skipSize - diff); } } else { Preconditions.illegalArgument("Not enough initial skips in nindo to take off"); } } else { c.apply(b); } } return b.build(); }