/**
   * Moves the configuration object with the given index in the list of configuration objects. This
   * is implemented by swapping contents of two Preferences child nodes.
   *
   * @param index Index of configuration object to move.
   * @param up If <code>true</code>, move configuration up in list, otherwise, move it down.
   */
  public void moveElement(int index, boolean up) {
    // copy-paste all config
    int targetIndex = up ? (index - 1) : (index + 1);
    if (targetIndex < 0 || targetIndex > preferences.getChildNodeNames().length - 1) {
      return;
    }

    MutablePreferences source = preferences.createChildNode(prefix + index);
    MutablePreferences target = preferences.createChildNode(prefix + targetIndex);
    SimplePreferences buf = new SimplePreferences(null);
    ConfigUtil.copyPreferences(source, buf);
    ConfigUtil.copyPreferences(target, source);
    ConfigUtil.copyPreferences(buf, target);
  }
  private void tidyUp(int startIndex) {
    maxId = -1;
    // build a list as they are now in config
    try {
      List<T> elements = buildFromConfig(preferences, prefix, configClass);

      for (int i = startIndex; i < elements.size(); i++) {
        if (elements.get(i).getId() > i) {
          T t = createObject(i);
          Preferences source = elements.get(i).getConfigNode();
          MutablePreferences target = t.getConfigNode();
          ConfigUtil.copyPreferences(source, target);
          // delete source
          preferences.removeChildNode(elements.get(i).getConfigNodeName(elements.get(i).getId()));
        }
      }
      maxId = elements.size() - 1;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }