/**
   * return true if the two items seems equals
   *
   * @param elt1 an AbstractElement
   * @param elt2 an AbstractElement
   * @return a boolean
   */
  private boolean equalsAbstractElts(AbstractElement elt1, AbstractElement elt2) {
    boolean seemsSame = false;

    if (elt1 == null) {
      if (elt2 == null) {
        seemsSame = true;
      }
    } else {
      seemsSame =
          this.equalsAbstractElts(
              elt1,
              (elt2 == null ? null : elt2.getLabel()),
              (elt2 == null ? null : elt2.getI18Nref()));
    }

    return seemsSame;
  }
  /**
   * return true if the two items seems equals
   *
   * @param elt an AbstractElement
   * @param label the label of an element
   * @param i18nRef the internationalization reference of an element
   * @return a boolean
   */
  private boolean equalsAbstractElts(AbstractElement elt, String label, String i18nRef) {
    boolean seemsSame = false;

    if (elt != null) {
      if (elt.getLabel() != null) {
        seemsSame = elt.getLabel().equals(label);
      }

      if (!seemsSame) {
        if (elt.getI18Nref() != null) {
          seemsSame = elt.getI18Nref().equals(i18nRef);
        }
      }
    }

    return seemsSame;
  }
  /**
   * merge two menu into master one
   *
   * @param masterMenu the master menu non null
   * @param servantMenu the servant menu non null
   */
  protected void merge(MenuType masterMenu, MenuType servantMenu) {
    if (logger.isDebugEnabled()) {
      logger.debug("entering merge(MenuType, MenuType)");
    }

    boolean seemsSame = this.equalsAbstractElts(masterMenu, servantMenu);

    if (seemsSame) {
      /* loop on all first elements of the servantMenu */

      List subItems = servantMenu.getMenuOrItemOrCheck();
      if (subItems != null) {
        Iterator it = subItems.iterator();
        while (it.hasNext()) {
          Object o = it.next();

          if (o != null) {
            if (o instanceof MenuType) {
                /* search for a menu in the master sub items */
              MenuType servantSubMenu = (MenuType) o;
              MenuType masterSubMenu =
                  (MenuType)
                      this.getItem(
                          masterMenu,
                          servantMenu.getLabel(),
                          servantMenu.getI18Nref(),
                          MenuType.class);
              if (masterSubMenu != null) {
                this.merge(masterSubMenu, servantSubMenu);
              } else {
                masterMenu.getMenuOrItemOrCheck().add(servantSubMenu);
                this.assignShortcuts(servantSubMenu, true);
              }
            } else if (o instanceof SeparatorElement) {
              masterMenu.getMenuOrItemOrCheck().add((OrderedElement) o);
            } else if (o instanceof AbstractElement) {
              AbstractElement subItem = (AbstractElement) o;
              /* search for a sub item in the servant list that is named like subItem
               *
               * if we find a checkItem named 't' and if tmaster already contains a comboItem named 't'
               *  then the checkItem won't be added to the resulting structure
               */
              AbstractElement masterSubItem =
                  (AbstractElement)
                      this.getItem(
                          masterMenu,
                          subItem.getLabel(),
                          subItem.getI18Nref(),
                          AbstractElement.class);
              if (masterSubItem == null) {
                masterMenu.getMenuOrItemOrCheck().add((OrderedElement) o);
                this.assignShortcuts(o, false);
              }
            }
          }
        }
      }
    }
    if (logger.isDebugEnabled()) {
      logger.debug("exiting merge(MenuType, MenuType)");
    }
  }