/** Empties the destination and copies the section of the source into the destination. */ public void execute() { Trace.log(2, "executing CopyCommand"); Part newPart = source.extract(startSlot, endSlot); Part.PartIterator i = newPart.iterator(); dest.empty(); while (i.hasNext()) dest.addUnit(i.next()); }
public Part fitPart(int freeSlots) { if (freeSlots == 0) return null; Part fitPart = this.copy(); while (fitPart.size() > freeSlots) { Part scaledPart = new Part(); Part.PartIterator i = fitPart.iterator(); while (i.hasNext()) { Unit unit = i.next(); if (unit.getRhythmValue() != 1) { Trace.log(3, "in fitPart, setting rhythmValue"); unit.setRhythmValue(unit.getRhythmValue() / 2); if (unit.getRhythmValue() <= MIN_RHYTHM_VALUE) return null; } scaledPart.addUnit(unit); } fitPart = scaledPart; } return fitPart; }