/** * Returns the index of a specific tab or throws a {@link NoSuchElementException}, if the model * does not contain the given tab. * * @param tab * The tab, whose index should be returned, as an instance of the class {@link Tab}. The * tab may not be null * @return The index of the given tab as an {@link Integer} value */ private int indexOfOrThrowException(@NonNull final Tab tab) { int index = indexOf(tab); Condition.INSTANCE .ensureNotEqual(index, -1, "No such tab: " + tab, NoSuchElementException.class); return index; }
@Override public int compare(final AbstractItem o1, final AbstractItem o2) { if (o1 instanceof AddTabItem && o2 instanceof AddTabItem) { return 0; } else if (o1 instanceof AddTabItem) { return -1; } else if (o2 instanceof AddTabItem) { return 1; } else if (o1 instanceof TabItem && o2 instanceof TabItem) { TabItem item1 = (TabItem) o1; TabItem item2 = (TabItem) o2; Tab tab1 = item1.getTab(); Tab tab2 = item2.getTab(); int index1 = tabSwitcher.indexOf(tab1); index1 = index1 == -1 ? item1.getIndex() : index1; int index2 = tabSwitcher.indexOf(tab2); index2 = index2 == -1 ? item2.getIndex() : index2; Condition.INSTANCE .ensureNotEqual(index1, -1, "Tab " + tab1 + " not contained by tab switcher", RuntimeException.class); Condition.INSTANCE .ensureNotEqual(index2, -1, "Tab " + tab2 + " not contained by tab switcher", RuntimeException.class); return index1 < index2 ? -1 : 1; } else { throw new RuntimeException("Unknown item types"); } }
int index2 = getTabSwitcher().indexOf(tab2); index2 = index2 == -1 ? o2.getIndex() : index2; Condition.INSTANCE.ensureNotEqual(index1, -1, "Tab " + tab1 + " not contained by tab switcher", RuntimeException.class); Condition.INSTANCE.ensureNotEqual(index2, -1, "Tab " + tab2 + " not contained by tab switcher", RuntimeException.class); int selectedTabIndex = getTabSwitcher().getSelectedTabIndex();