/** * Indicates if it is the first time of usage of method or not (used in loops) * * @return 'true' if it is the first loop step, 'false' otherwise */ public boolean isFirstAndNext() { boolean result = index == 0; next(); return result; }
public ManyValuedHashMap<K, V> put2(K key, List<V> newValues) { put(key, newValues); return this; }
public static <T> void heapSort(@Nonnull T[] a, @Nonnull Comparator<? super T> c) { final ArrayBinaryHeap<? super T> heap = heapify(a, c); final int rootIndex = heap.getRootIndex(); for (int i = a.length - 1; i >= 1; i--) { swap(a, i, rootIndex); heap.decreaseSize(); heap.bubbleDown(rootIndex); } } }
@Override public T getById(@Nonnull final Integer id) { synchronized (this) { return find(entities, new JPredicate<T>() { @Override public boolean apply(@Nullable T t) { return t != null && t.getId().equals(id); } }); } }
@Nonnull static <T extends Comparable<T>> ArrayBinaryHeap<T> newArrayBinaryHeapWithHeight(int height) { return newArrayBinaryHeapWithHeight(height, Collections.<T>naturalComparator()); }
public static <T extends Comparable<? super T>> void quickSort(@Nonnull T[] a) { quickSort.sort(a, naturalComparator()); }
@Nonnull static <T extends Comparable<T>> ArrayBinaryHeap<T> heapify(@Nonnull T[] array) { return heapify(array, Collections.<T>naturalComparator()); }
@Override public void add(int index, T element) { this.list.add(index, element); sort(); }
@Override public void sort(@Nonnull Integer[] numbers) { if (numbers.length == 0 || numbers.length == 1) { return; } final int maxBitIndex = getMaxBitIndex(numbers); sortByBit(numbers, 0, numbers.length, maxBitIndex); }
public LoopData(@Nullable Object... objects) { if (Collections.isEmpty(objects)) { this.length = (long) 0; } else { this.length = (long) objects.length; } }
@Nonnull static <T> ArrayBinaryHeap<T> heapify(@Nonnull T[] array, @Nonnull Comparator<T> c) { final ArrayBinaryHeap<T> heap = new ArrayBinaryHeap<T>(array, c); for (int i = heap.size / 2; i >= 0; i--) { heap.bubbleDown(i); } return heap; }
public boolean isValidIndex(int index) { return index >= getRootIndex() && index < size; }
public static byte[] concat(byte[] first, byte[] second) { return Collections.concat(first, second); }
int getMaxBitIndex(@Nonnull Integer[] numbers) { int result = 32; final Integer maxAbsNumber = getMaxAbsNumber(numbers); for (int i = 0; i < BITS.length; i++) { final int bit = BITS[i]; if ((bit & maxAbsNumber) != 0) { result = i; break; } } return result; }
@Override public void sort(@Nonnull T[] a, @Nonnull Comparator<? super T> c) { heapSort(a, c); } }
public static <T> void addUnique(@Nonnull List<T> list, @Nonnull List<T> list2) { for (T t : list2) { addUnique(list, t); } }
@Override public T remove(int index) { T result = this.list.remove(index); sort(); return result; }
@Override public void remove() { it.remove(); sort(); }