Source:
<code>public void setItems(Iterable value) { if (items != value) { IVdcQueryable lastSelectedItem = (IVdcQueryable) getSelectedItem(); ArrayList<IVdcQueryable> lastSelectedItems = new ArrayList<IVdcQueryable>(); if (getSelectedItems() != null) { for (Object item : getSelectedItems()) { lastSelectedItems.add((IVdcQueryable) item); } } <START> if (comparator == null || value instanceof SortedSet) { <END> itemsChanging(value, items); items = value; } else { TreeSet sortedValue = null; if (value != null) { sortedValue = new TreeSet(comparator); for (Object item : value) { sortedValue.add(item); } } itemsChanging(sortedValue, items); items = sortedValue; } updatePagingAvailability(); getItemsChangedEvent().raise(this, EventArgs.Empty); onPropertyChanged(new PropertyChangedEventArgs("Items")); selectedItem = null; if (getSelectedItems() != null) { getSelectedItems().clear(); } if (lastSelectedItem != null && items != null) { IVdcQueryable newSelectedItem = null; ArrayList<IVdcQueryable> newItems = new ArrayList<IVdcQueryable>(); for (Object item : items) { newItems.add((IVdcQueryable) item); } if (newItems != null) { for (IVdcQueryable newItem : newItems) { if (newItem.getQueryableId().equals(lastSelectedItem.getQueryableId())) { newSelectedItem = newItem; } else { for (IVdcQueryable item : lastSelectedItems) { if (newItem.getQueryableId().equals(item.getQueryableId())) { selectedItems.add(newItem); } } } } } if (newSelectedItem != null) { selectedItem = newSelectedItem; if (selectedItems != null) { selectedItems.add(newSelectedItem); } } } onSelectedItemChanged(); } }</code><technical_language>if is instanceof SortedSet set is sorted desired comparator</technical_language>

Target:
public void setItems(Iterable value) { if (items != value) { IVdcQueryable lastSelectedItem = (IVdcQueryable) getSelectedItem(); ArrayList<IVdcQueryable> lastSelectedItems = new ArrayList<IVdcQueryable>(); if (getSelectedItems() != null) { for (Object item : getSelectedItems()) { lastSelectedItems.add((IVdcQueryable) item); } } if (comparator == null || ((value instanceof SortedSet) && (((SortedSet) value).comparator() == comparator))) { itemsChanging(value, items); items = value; } else { TreeSet sortedValue = null; if (value != null) { sortedValue = new TreeSet(comparator); for (Object item : value) { sortedValue.add(item); } } itemsChanging(sortedValue, items); items = sortedValue; } updatePagingAvailability(); getItemsChangedEvent().raise(this, EventArgs.Empty); onPropertyChanged(new PropertyChangedEventArgs("Items")); selectedItem = null; if (getSelectedItems() != null) { getSelectedItems().clear(); } if (lastSelectedItem != null && items != null) { IVdcQueryable newSelectedItem = null; ArrayList<IVdcQueryable> newItems = new ArrayList<IVdcQueryable>(); for (Object item : items) { newItems.add((IVdcQueryable) item); } if (newItems != null) { for (IVdcQueryable newItem : newItems) { if (newItem.getQueryableId().equals(lastSelectedItem.getQueryableId())) { newSelectedItem = newItem; } else { for (IVdcQueryable item : lastSelectedItems) { if (newItem.getQueryableId().equals(item.getQueryableId())) { selectedItems.add(newItem); } } } } } if (newSelectedItem != null) { selectedItem = newSelectedItem; if (selectedItems != null) { selectedItems.add(newSelectedItem); } } } onSelectedItemChanged(); } }