private static Map<Integer, Integer> applyAlignmentAndCheckCycles(Map<Integer, Integer> alignmentMap, int k, List<Integer> eligible) {

		// Convert to lists to establish a fixed order (avoid concurrent modification)
		List<Integer> preimage = new ArrayList<Integer>(alignmentMap.keySet()); // currently unmodified
		List<Integer> image = new ArrayList<Integer>(preimage);

		for (int n = 1; n <= k; n++) {
			// apply alignment
			for (int i = 0; i < image.size(); i++) {
				final Integer pre = image.get(i);
				final Integer post = (pre == null ? null : alignmentMap.get(pre));
				image.set(i, post);

				// Make cycles ineligible
				if (post != null && post.equals(preimage.get(i))) {
					eligible.remove(preimage.get(i)); // Could be O(n) with List impl
				}
			}
		}

		Map<Integer, Integer> imageMap = new HashMap<Integer, Integer>(alignmentMap.size());

		// now populate with actual values
		for (int i = 0; i < preimage.size(); i++) {
			Integer pre = preimage.get(i);
			Integer postK = image.get(i);
			imageMap.put(pre, postK);
		}
		return imageMap;
	}
private static Map < Integer , Integer > applyAlignmentAndCheckCycles ( Map < Integer , Integer > alignmentMap , int k , List < Integer > eligible ) { List < Integer > preimage = new ArrayList < Integer > ( alignmentMap . keySet ( ) ) ; List < Integer > image = new ArrayList < Integer > ( preimage ) ; for ( int n = 1 ; n <= k ; n ++ ) { for ( int i = 0 ; i < image . size ( ) ; i ++ ) { final Integer pre = image . get ( i ) ; final Integer post = ( pre == null ? null : alignmentMap . get ( pre ) ) ; image . set ( i , post ) ; if ( post != null && post . equals ( preimage . get ( i ) ) ) { eligible . remove ( preimage . get ( i ) ) ; } } } Map < Integer , Integer > imageMap = new HashMap < Integer , Integer > ( alignmentMap . size ( ) ) ; for ( int i = 0 ; i < preimage . size ( ) ; i ++ ) { Integer pre = preimage . get ( i ) ; Integer postK = image . get ( i ) ; imageMap . put ( pre , postK ) ; } return imageMap ; }
Like {@link AlignmentTools#applyAlignment(Map, int)}, returns a map of k applications of alignmentMap. However,
it also sets loops of size less than k as ineligible.

@param alignmentMap
f(x)
@param k
@param eligible
Eligible residues. Residues from small cycles are removed.
@return f^k(x)