private SublimeBaseMenuItem addInternal(int pivotID,Positioned positioned,SublimeBaseMenuItem newItem){
  int newItemGroupId=newItem.getGroupId();
  checkExistenceOfGroup(newItemGroupId);
  int pivotIndex=findItemIndex(pivotID);
  SublimeBaseMenuItem pivot=mItems.get(pivotIndex);
  if (newItem.getItemType() == SublimeBaseMenuItem.ItemType.GROUP_HEADER) {
    checkIfGroupHeaderAlreadyExistsForGroup(newItemGroupId);
    int index=findGroupIndex(newItemGroupId);
    if (index >= 0) {
      mItems.add(index,newItem);
    }
 else {
      if (positioned == Positioned.BEFORE) {
        if (pivot.getGroupId() == NO_GROUP_ID || pivot.getItemType() == SublimeBaseMenuItem.ItemType.GROUP_HEADER) {
          mItems.add(pivotIndex,newItem);
        }
 else {
          mItems.add(newItem);
        }
      }
 else       if (positioned == Positioned.AFTER) {
        if (pivot.getGroupId() == NO_GROUP_ID || pivotIndex == findLastGroupIndex(newItemGroupId)) {
          mItems.add(pivotIndex + 1,newItem);
        }
 else {
          mItems.add(newItem);
        }
      }
    }
  }
 else {
    if (newItemGroupId != NO_GROUP_ID) {
      int lastGroupIndex=findLastGroupIndex(newItemGroupId);
      if (lastGroupIndex == mItems.size()) {
        if (positioned == Positioned.BEFORE) {
          if (pivot.getGroupId() == NO_GROUP_ID || pivotIndex == findGroupIndex(pivot.getGroupId())) {
            mItems.add(pivotIndex,newItem);
          }
 else {
            mItems.add(newItem);
          }
        }
 else         if (positioned == Positioned.AFTER) {
          if (pivot.getGroupId() == NO_GROUP_ID || pivotIndex == findLastGroupIndex(pivot.getGroupId())) {
            mItems.add(pivotIndex + 1,newItem);
          }
 else {
            mItems.add(newItem);
          }
        }
      }
 else {
        if (newItemGroupId == pivot.getGroupId()) {
          if (positioned == Positioned.BEFORE) {
            if (pivot.getItemType() != SublimeBaseMenuItem.ItemType.GROUP_HEADER) {
              mItems.add(pivotIndex,newItem);
            }
 else {
              mItems.add(lastGroupIndex + 1,newItem);
            }
          }
 else           if (positioned == Positioned.AFTER) {
            mItems.add(pivotIndex + 1,newItem);
          }
        }
 else {
          mItems.add(lastGroupIndex + 1,newItem);
        }
      }
    }
 else {
      if (positioned == Positioned.BEFORE) {
        if (pivot.getGroupId() == NO_GROUP_ID || findGroupIndex(pivot.getGroupId()) == pivotIndex) {
          mItems.add(pivotIndex,newItem);
        }
 else {
          mItems.add(newItem);
        }
      }
 else       if (positioned == Positioned.AFTER) {
        if (pivot.getGroupId() == NO_GROUP_ID || pivotIndex == findLastGroupIndex(pivot.getGroupId())) {
          mItems.add(pivotIndex + 1,newItem);
        }
 else {
          mItems.add(newItem);
        }
      }
    }
  }
  onItemsChanged();
  return newItem;
}

private SublimeBaseMenuItem addInternal ( int pivotID , Positioned positioned , SublimeBaseMenuItem newItem ) { int newItemGroupId = newItem . getGroupId ( ) ; checkExistenceOfGroup ( newItemGroupId ) ; int pivotIndex = findItemIndex ( pivotID ) ; SublimeBaseMenuItem pivot = mItems . get ( pivotIndex ) ; if ( newItem . getItemType ( ) == SublimeBaseMenuItem . ItemType . GROUP_HEADER ) { checkIfGroupHeaderAlreadyExistsForGroup ( newItemGroupId ) ; int index = findGroupIndex ( newItemGroupId ) ; if ( index >= 0 ) { mItems . add ( index , newItem ) ; } else { if ( positioned == Positioned . BEFORE ) { if ( pivot . getGroupId ( ) == NO_GROUP_ID || pivot . getItemType ( ) == SublimeBaseMenuItem . ItemType . GROUP_HEADER ) { mItems . add ( pivotIndex , newItem ) ; } else { mItems . add ( newItem ) ; } } else if ( positioned == Positioned . AFTER ) { if ( pivot . getGroupId ( ) == NO_GROUP_ID || pivotIndex == findLastGroupIndex ( newItemGroupId ) ) { mItems . add ( pivotIndex + 1 , newItem ) ; } else { mItems . add ( newItem ) ; } } } } else { if ( newItemGroupId != NO_GROUP_ID ) { int lastGroupIndex = findLastGroupIndex ( newItemGroupId ) ; if ( lastGroupIndex == mItems . size ( ) ) { if ( positioned == Positioned . BEFORE ) { if ( pivot . getGroupId ( ) == NO_GROUP_ID || pivotIndex == findGroupIndex ( pivot . getGroupId ( ) ) ) { mItems . add ( pivotIndex , newItem ) ; } else { mItems . add ( newItem ) ; } } else if ( positioned == Positioned . AFTER ) { if ( pivot . getGroupId ( ) == NO_GROUP_ID || pivotIndex == findLastGroupIndex ( pivot . getGroupId ( ) ) ) { mItems . add ( pivotIndex + 1 , newItem ) ; } else { mItems . add ( newItem ) ; } } } else { if ( newItemGroupId == pivot . getGroupId ( ) ) { if ( positioned == Positioned . BEFORE ) { if ( pivot . getItemType ( ) != SublimeBaseMenuItem . ItemType . GROUP_HEADER ) { mItems . add ( pivotIndex , newItem ) ; } else { mItems . add ( lastGroupIndex + 1 , newItem ) ; } } else if ( positioned == Positioned . AFTER ) { mItems . add ( pivotIndex + 1 , newItem ) ; } } else { mItems . add ( lastGroupIndex + 1 , newItem ) ; } } } else { if ( positioned == Positioned . BEFORE ) { if ( pivot . getGroupId ( ) == NO_GROUP_ID || findGroupIndex ( pivot . getGroupId ( ) ) == pivotIndex ) { mItems . add ( pivotIndex , newItem ) ; } else { mItems . add ( newItem ) ; } } else if ( positioned == Positioned . AFTER ) { if ( pivot . getGroupId ( ) == NO_GROUP_ID || pivotIndex == findLastGroupIndex ( pivot . getGroupId ( ) ) ) { mItems . add ( pivotIndex + 1 , newItem ) ; } else { mItems . add ( newItem ) ; } } } } onItemsChanged ( ) ; return newItem ; }
adds an item to the menu and positions it using the given ` pivot ` .
