Home | History | Annotate | Download | only in widget

Lines Matching refs:items

28  * A Sorted list implementation that can keep items in order and also notify for changes in the
33 * It keeps items ordered using the {@link Callback#compare(Object, Object)} method and uses
34 * binary search to retrieve items. If the sorting criteria of your items may change, make sure you
37 * You can control the order of items and change notifications via the {@link Callback} parameter.
99 * @param initialCapacity The initial capacity to hold items.
109 * The number of items in the list.
111 * @return The number of items in the list.
123 * {@link Callback#areItemsTheSame(Object, Object)} to check if two items are the same item
148 * Adds the given items to the list. Equivalent to calling {@link SortedList#add} in a loop,
156 * @param items Array of items to be added into the list.
159 * @see SortedList#addAll(T[] items)
161 public void addAll(@NonNull T[] items, boolean mayModifyInput) {
163 if (items.length == 0) {
168 addAllInternal(items);
170 addAllInternal(copyArray(items));
175 * Adds the given items to the list. Does not modify or retain the input.
177 * @see SortedList#addAll(T[] items, boolean mayModifyInput)
179 * @param items Array of items to be added into the list.
181 public void addAll(@NonNull T... items) {
182 addAll(items, false);
186 * Adds the given items to the list. Does not modify or retain the input.
188 * @see SortedList#addAll(T[] items, boolean mayModifyInput)
190 * @param items Collection of items to be added into the list.
192 public void addAll(@NonNull Collection<T> items) {
193 T[] copy = (T[]) Array.newInstance(mTClass, items.size());
194 addAll(items.toArray(copy), true);
198 * Replaces the current items with the new items, dispatching {@link ListUpdateCallback} events
211 * @param items Array of items to replace current items.
216 public void replaceAll(@NonNull T[] items, boolean mayModifyInput) {
220 replaceAllInternal(items);
222 replaceAllInternal(copyArray(items));
227 * Replaces the current items with the new items, dispatching {@link ListUpdateCallback} events
232 * @param items Array of items to replace current items.
234 public void replaceAll(@NonNull T... items) {
235 replaceAll(items, false);
239 * Replaces the current items with the new items, dispatching {@link ListUpdateCallback} events
244 * @param items Array of items to replace current items.
246 public void replaceAll(@NonNull Collection<T> items) {
247 T[] copy = (T[]) Array.newInstance(mTClass, items.size());
248 replaceAll(items.toArray(copy), true);
308 // The items aren't the same even though they were supposed to occupy the same
347 * Sorts and removes duplicate items, leaving only the last item from each group of "same"
348 * items. Move the remaining items to the beginning of the array.
350 * @return Number of deduplicated items at the beginning of the array.
352 private int sortAndDedup(@NonNull T[] items) {
353 if (items.length == 0) {
358 Arrays.sort(items, mCallback);
360 // Keep track of the range of equal items at the end of the output.
365 for (int i = 1; i < items.length; ++i) {
366 T currentItem = items[i];
368 int compare = mCallback.compare(items[rangeStart], currentItem);
371 // The range of equal items continues, update it.
372 final int sameItemPos = findSameItem(currentItem, items, rangeStart, rangeEnd);
375 items[sameItemPos] = currentItem;
379 items[rangeEnd] = currentItem;
386 items[rangeEnd] = currentItem;
395 private int findSameItem(T item, T[] items, int from, int to) {
397 if (mCallback.areItemsTheSame(items[pos], item)) {
424 // No more old items, copy the remaining new items.
434 // No more new items, copy the remaining old items.
451 // Items are the same. Output the new item, but consume both.
487 * {@link #endBatchedUpdates()}. For example, if you add multiple items in a loop
636 // different items, we can use comparison and may avoid lookup
671 * item.incrementPriority(); // assume items are sorted by priority
812 private T[] copyArray(T[] items) {
813 T[] copy = (T[]) Array.newInstance(mTClass, items.length);
814 System.arraycopy(items, 0, copy, 0, items.length);
819 * Removes all items from the SortedList.
835 * It defines how items should be sorted and how duplicates should be handled.
860 * @param count The number of items which has changed.
870 * Called by the SortedList when it wants to check whether two items have the same data
880 * return whether the items
885 * @return True if the contents of the items are the same or false if they are different.
892 * For example, if your items have unique ids, this method should check their equality.
897 * @return True if the two items represent the same object or false if they are different.
902 * When {@link #areItemsTheSame(T2, T2)} returns {@code true} for two items and
916 * @return A payload object that represents the changes between the two items.
930 * For example, if you are going to add multiple items to a SortedList, BatchedCallback call
932 * <code>onInserted(index, N)</code> if items are added into consecutive indices. This change