public static List<byte[]> getUtf8ByteArrays(List<String> strings) { if (CollectionUtils.isEmpty(strings)) { return Collections.emptyList(); } List<byte[]> byteArrays = new ArrayList<>(strings.size()); strings.forEach(s -> byteArrays.add(Bytes.toBytes(s))); return byteArrays; }
@VisibleForTesting public synchronized void closeAndArchiveCompactedFiles(boolean storeClosing) throws IOException { // ensure other threads do not attempt to archive the same files on close() archiveLock.lock(); try { lock.readLock().lock(); Collection<HStoreFile> copyCompactedfiles = null; try { Collection<HStoreFile> compactedfiles = this.getStoreEngine().getStoreFileManager().getCompactedfiles(); if (CollectionUtils.isNotEmpty(compactedfiles)) { // Do a copy under read lock copyCompactedfiles = new ArrayList<>(compactedfiles); } else { LOG.trace("No compacted files to archive"); } } finally { lock.readLock().unlock(); } if (CollectionUtils.isNotEmpty(copyCompactedfiles)) { removeCompactedfiles(copyCompactedfiles, storeClosing); } } finally { archiveLock.unlock(); } }
/** * Returns the <code>index</code>-th <code>Map.Entry</code> in the <code>map</code>'s <code>entrySet</code>, * throwing <code>IndexOutOfBoundsException</code> if there is no such element. * * @param <K> the key type in the {@link Map} * @param <V> the key type in the {@link Map} * @param map the object to get a value from * @param index the index to get * @return the object at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public static <K,V> Map.Entry<K, V> get(final Map<K,V> map, final int index) { checkIndexBounds(index); return get(map.entrySet(), index); }
/** * Copies the contents of this view into the provided set. * * @param <S> the set type * @param set the set for copying the contents */ public <S extends Set<E>> void copyInto(final S set) { CollectionUtils.addAll(set, this); }
return isEqualCollection(collect(a, transformer), collect(b, transformer));
/** * Transforms all elements from the input iterator with the given transformer * and adds them to the output collection. * <p> * If the input iterator or transformer is null, the result is an empty list. * * @param <I> the type of object in the input collection * @param <O> the type of object in the output collection * @param inputIterator the iterator to get the input from, may be null * @param transformer the transformer to use, may be null * @return the transformed result (new list) */ public static <I, O> Collection<O> collect(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer) { return collect(inputIterator, transformer, new ArrayList<O>()); }
/** * Merges two sorted Collections, a and b, into a single, sorted List * such that the ordering of the elements according to Comparator c is retained. * <p> * Uses the standard O(n) merge algorithm for combining two sorted lists. * * @param <O> the element type * @param a the first collection, must not be null * @param b the second collection, must not be null * @param c the comparator to use for the merge. * @return a new sorted List, containing the elements of Collection a and b * @throws NullPointerException if either collection or the comparator is null * @since 4.0 */ public static <O> List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final Comparator<? super O> c) { return collate(a, b, c, true); }
/** * Returns the <code>index</code>-th value in {@link Iterator}, throwing * <code>IndexOutOfBoundsException</code> if there is no such element. * <p> * The Iterator is advanced to <code>index</code> (or to the end, if * <code>index</code> exceeds the number of entries) as a side effect of this method. * * @param <E> the type of object in the {@link Iterator} * @param iterator the iterator to get a value from * @param index the index to get * @return the object at the specified index * @throws IndexOutOfBoundsException if the index is invalid * @since 4.1 */ public static <E> E get(final Iterator<E> iterator, final int index) { int i = index; CollectionUtils.checkIndexBounds(i); while (iterator.hasNext()) { i--; if (i == -1) { return iterator.next(); } iterator.next(); } throw new IndexOutOfBoundsException("Entry does not exist: " + i); }
/** * Traverses an iterator of this iterable and adds all elements * to the provided collection. * * @param collection the collection to add the elements * @throws NullPointerException if collection is null */ public void copyInto(final Collection<? super E> collection) { if (collection == null) { throw new NullPointerException("Collection must not be null"); } CollectionUtils.addAll(collection, iterable); }
/** * Transforms all elements from input collection with the given transformer * and adds them to the output collection. * <p> * If the input collection or transformer is null, there is no change to the * output collection. * * @param <I> the type of object in the input collection * @param <O> the type of object in the output collection * @param <R> the type of the output collection * @param inputCollection the collection to get the input from, may be null * @param transformer the transformer to use, may be null * @param outputCollection the collection to output into, may not be null if inputCollection * and transformer are not null * @return the output collection with the transformed input added * @throws NullPointerException if the outputCollection is null and both, inputCollection and * transformer are not null */ public static <I, O, R extends Collection<? super O>> R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection) { if (inputCollection != null) { return collect(inputCollection.iterator(), transformer, outputCollection); } return outputCollection; }
/** * Merges two sorted Collections, a and b, into a single, sorted List * such that the natural ordering of the elements is retained. * <p> * Uses the standard O(n) merge algorithm for combining two sorted lists. * * @param <O> the element type * @param a the first collection, must not be null * @param b the second collection, must not be null * @return a new sorted List, containing the elements of Collection a and b * @throws NullPointerException if either collection is null * @since 4.0 */ public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); }
/** * Returns the <code>index</code>-th value in the {@link Enumeration}, throwing * <code>IndexOutOfBoundsException</code> if there is no such element. * <p> * The Enumeration is advanced to <code>index</code> (or to the end, if * <code>index</code> exceeds the number of entries) as a side effect of this method. * * @param e the enumeration to get a value from * @param index the index to get * @param <T> the type of object in the {@link Enumeration} * @return the object at the specified index * @throws IndexOutOfBoundsException if the index is invalid * @throws IllegalArgumentException if the object type is invalid * @since 4.1 */ public static <T> T get(final Enumeration<T> e, final int index) { int i = index; CollectionUtils.checkIndexBounds(i); while (e.hasMoreElements()) { i--; if (i == -1) { return e.nextElement(); } else { e.nextElement(); } } throw new IndexOutOfBoundsException("Entry does not exist: " + i); }
public static boolean isSorted(Collection<byte[]> arrays) { if (!CollectionUtils.isEmpty(arrays)) { byte[] previous = new byte[0]; for (byte[] array : arrays) { if (Bytes.compareTo(previous, array) > 0) { return false; } previous = array; } } return true; }
storeEngine.getStoreFileManager().clearCompactedFiles(); if (CollectionUtils.isNotEmpty(compactedfiles)) { removeCompactedfiles(compactedfiles, true);
/** * Create a new set operation helper from the two collections. * @param a the first collection * @param b the second collection */ public SetOperationCardinalityHelper(final Iterable<? extends O> a, final Iterable<? extends O> b) { super(a, b); elements = new HashSet<O>(); addAll(elements, a); addAll(elements, b); // the resulting list must contain at least each unique element, but may grow newList = new ArrayList<O>(elements.size()); }
/** * Returns a new Collection containing all elements of the input collection * transformed by the given transformer. * <p> * If the input collection or transformer is null, the result is an empty list. * * @param <I> the type of object in the input collection * @param <O> the type of object in the output collection * @param inputCollection the collection to get the input from, may not be null * @param transformer the transformer to use, may be null * @return the transformed result (new list) * @throws NullPointerException if the input collection is null */ public static <I, O> Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return collect(inputCollection, transformer, answer); }
/** * Merges two sorted Collections, a and b, into a single, sorted List * such that the natural ordering of the elements is retained. * <p> * Uses the standard O(n) merge algorithm for combining two sorted lists. * * @param <O> the element type * @param a the first collection, must not be null * @param b the second collection, must not be null * @param includeDuplicates if {@code true} duplicate elements will be retained, otherwise * they will be removed in the output collection * @return a new sorted List, containing the elements of Collection a and b * @throws NullPointerException if either collection is null * @since 4.0 */ public static <O extends Comparable<? super O>> List<O> collate(final Iterable<? extends O> a, final Iterable<? extends O> b, final boolean includeDuplicates) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), includeDuplicates); }
/** * Returns the <code>index</code>-th value in the <code>iterable</code>'s {@link Iterator}, throwing * <code>IndexOutOfBoundsException</code> if there is no such element. * <p> * If the {@link Iterable} is a {@link List}, then it will use {@link List#get(int)}. * * @param <T> the type of object in the {@link Iterable}. * @param iterable the {@link Iterable} to get a value from, may be null * @param index the index to get * @return the object at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public static <T> T get(final Iterable<T> iterable, final int index) { CollectionUtils.checkIndexBounds(index); if (iterable instanceof List<?>) { return ((List<T>) iterable).get(index); } return IteratorUtils.get(emptyIteratorIfNull(iterable), index); }
@VisibleForTesting static Set<byte[]> collectFamilies(List<Cell> cells) { if (CollectionUtils.isEmpty(cells)) { return Collections.emptySet(); } else { return cells.stream() .filter(v -> !CellUtil.matchingFamily(v, WALEdit.METAFAMILY)) .collect(toCollection(() -> new TreeSet<>(CellComparator.getInstance()::compareFamilies))) .stream() .map(CellUtil::cloneFamily) .collect(toCollection(() -> new TreeSet<>(Bytes.BYTES_COMPARATOR))); } }
/** * @return null if failed to report progress * @throws IOException */ @Override public List<Path> finishWritingAndClose() throws IOException { boolean isSuccessful = false; List<Path> result = null; try { isSuccessful = finishWriting(false); } finally { result = close(); List<IOException> thrown = closeLogWriters(null); if (CollectionUtils.isNotEmpty(thrown)) { throw MultipleIOException.createIOException(thrown); } } if (isSuccessful) { splits = result; } return splits; }