MCPcopy Index your code
hub / github.com/OpenFeign/feign / toArray

Method toArray

core/src/main/java/feign/Util.java:159–172  ·  view source on GitHub ↗

Adapted from com.google.common.base.Strings#emptyToNull.

(Iterable<? extends T> iterable, Class<T> type)

Source from the content-addressed store, hash-verified

157
158 /** Adapted from {@code com.google.common.base.Strings#emptyToNull}. */
159 @SuppressWarnings("unchecked")
160 public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type) {
161 Collection<T> collection;
162 if (iterable instanceof Collection) {
163 collection = (Collection<T>) iterable;
164 } else {
165 collection = new ArrayList<>();
166 for (T element : iterable) {
167 collection.add(element);
168 }
169 }
170 T[] array = (T[]) Array.newInstance(type, collection.size());
171 return collection.toArray(array);
172 }
173
174 /** Returns an unmodifiable collection which may be empty, but is never null. */
175 public static <T> Collection<T> valuesOrEmpty(Map<String, Collection<T>> map, String key) {

Callers 5

hasHeadersMethod · 0.80
enrichMethod · 0.80
removeValuesMethod · 0.80
readInternalMethod · 0.80
asStringMethod · 0.80

Calls 3

addMethod · 0.45
newInstanceMethod · 0.45
sizeMethod · 0.45

Tested by 1

hasHeadersMethod · 0.64