public void moveUp() {
   if (iPrimary != null) {
     iPrimary.moveUp();
   } else {
     if (iPrev == null) {
       clearAll();
     } else {
       iPrev.moveUp();
       swapWith(iPrev);
     }
   }
 }
 public void remove() {
   if (iPrimary != null) {
     iPrimary.remove();
   } else {
     if (iNext != null && isAllowFreeTime() == iNext.isAllowFreeTime()) {
       replaceWith(iNext);
       iNext.remove();
     } else {
       replaceWith(null);
     }
   }
 }
 public void moveDown() {
   if (iPrimary != null) {
     iPrimary.moveDown();
   } else {
     if (iNext == null) {
       clearAll();
     } else {
       iNext.moveDown();
       swapWith(iNext);
     }
   }
 }
 public void swapUp() {
   if (iPrimary != null) {
     iPrimary.swapUp();
   } else {
     swapWith(iPrev);
   }
 }
 public void swapDown() {
   if (iPrimary != null) {
     iPrimary.swapDown();
   } else {
     swapWith(iNext);
   }
 }
 private void clearAllAlternatives() {
   if (iPrimary != null) {
     setHint("");
   }
   setValue(null);
   if (iAlternative != null) iAlternative.clearAllAlternatives();
 }
 private void swapWith(CourseSelectionBox other) {
   hideSuggestionList();
   other.hideSuggestionList();
   String x = getError();
   setError(other.getError());
   other.setError(x);
   boolean b = isEnabled();
   setEnabled(other.isEnabled());
   other.setEnabled(b);
   if (iPrimary != null) {
     x = getHint();
     setHint(other.getHint());
     other.setHint(x);
   }
   x = getValue();
   setValue(other.getValue(), false);
   other.setValue(x, false);
   if (iAlternative != null) iAlternative.swapWith(other.iAlternative);
   if (iWaitList != null && other.iWaitList != null) {
     Boolean ch = iWaitList.getValue();
     iWaitList.setValue(other.iWaitList.getValue());
     other.iWaitList.setValue(ch);
   }
 }
 private void replaceWith(CourseSelectionBox other) {
   hideSuggestionList();
   if (other != null) other.hideSuggestionList();
   setError(other == null ? null : other.getError());
   setEnabled(
       other == null ? iPrimary == null || !iPrimary.getValue().isEmpty() : other.isEnabled());
   if (iPrimary != null) setHint(other == null ? "" : other.getHint());
   setValue(other == null ? null : other.getValue(), false);
   if (iAlternative != null) iAlternative.replaceWith(other == null ? null : other.iAlternative);
   if (iWaitList != null) {
     iWaitList.setValue(
         other == null || other.iWaitList == null ? false : other.iWaitList.getValue());
   }
 }
 private void clearAll() {
   if (iPrimary != null) iPrimary.clearAll();
   else clearAllAlternatives();
 }