Removes values from the array that meet the criteria for removal via the supplied Predicate value
(T[] values, Predicate<T> shouldRemove, Class<T> type)
| 144 | * Predicate} value |
| 145 | */ |
| 146 | @SuppressWarnings("unchecked") |
| 147 | public static <T> T[] removeValues(T[] values, Predicate<T> shouldRemove, Class<T> type) { |
| 148 | Collection<T> collection = new ArrayList<>(values.length); |
| 149 | for (T value : values) { |
| 150 | if (shouldRemove.negate().test(value)) { |
| 151 | collection.add(value); |
| 152 | } |
| 153 | } |
| 154 | T[] array = (T[]) Array.newInstance(type, collection.size()); |
| 155 | return collection.toArray(array); |
| 156 | } |
| 157 | |
| 158 | /** Adapted from {@code com.google.common.base.Strings#emptyToNull}. */ |
| 159 | @SuppressWarnings("unchecked") |