获取集合的第一个元素

@param <T> 集合元素类型
@param iterable {@link Iterable}
@return 第一个元素
543070
public static <T> T getFirst(Iterable<T> iterable) {
		if (null != iterable) {
			return getFirst(iterable.iterator());
		}
		return null;
	}
911090
@SuppressWarnings("unchecked")
  public static Iterator<Object> iterator(Object iterable) {
    Assert.state(isIterable(iterable.getClass()));
    return iterable.getClass().isArray() ? new ArrayIterator(iterable)
        : ((Iterable<Object>) iterable).iterator();
  }
140209
public static <E> Object result(final Iterable<E> iterable, final Predicate<E> pred) {
        for (E element : iterable) {
            if (pred.test(element)) {
                if (element instanceof Map.Entry) {
                    if (((Map.Entry) element).getValue() instanceof Supplier) {
                        return ((Supplier) ((Map.Entry) element).getValue()).get();
                    }
                    return ((Map.Entry) element).getValue();
                }
                return element;
            }
        }
        return null;
    }
269669
@Override
    public <R> ListT<W,R> unitIterable(final Iterable<R> it) {
        return of(run.unitIterable(it)
                     .map(i -> ListX.of(i)));
    }
604358
public static <K, V> Map<K, V> toMap(final Iterable<Map.Entry<K, V>> iterable) {
        final Map<K, V> result = newLinkedHashMap();
        for (Map.Entry<K, V> entry : iterable) {
            result.put(entry.getKey(), entry.getValue());
        }
        return result;
    }
1097984
public static <T> Predicate<T> contains(final Iterable<T> iterable) {
        return new Predicate<T>() {
            @Override
            public boolean test(final T testValue) {
                return Iterables.contains(iterable, testValue);
            }
        };
    }
647040
@SuppressWarnings("unchecked")
	static <T> List<T> toList(final Iterable<? extends T> iterable)
	{
		if (iterable instanceof List)
		{
			return (List<T>) iterable;
		}
		return ImmutableList.copyOf(iterable);
	}
344200
@SuppressWarnings("unchecked")
  public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type) {
    Collection<T> collection;
    if (iterable instanceof Collection) {
      collection = (Collection<T>) iterable;
    } else {
      collection = new ArrayList<T>();
      for (T element : iterable) {
        collection.add(element);
      }
    }
    T[] array = (T[]) Array.newInstance(type, collection.size());
    return collection.toArray(array);
  }
1113349
public static <E> Iterator<E> cycle(Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot cycle a null iterable");
        return new CyclicIterator<E>(iterable.iterator());
    }
1010614
public static <T> boolean isEmpty(final Iterable<T> iterable) {
        return iterable == null || !iterable.iterator().hasNext();
    }
107385
public static <T> Set<T> asSet(final Iterable<T> iterable)
   {
      Set<T> result = new HashSet<T>();
      for (T t : iterable)
      {
         result.add(t);
      }
      return result;
   }
97381
public static <E> List<E> shuffle(final Iterable<E> iterable) {
        final List<E> shuffled = newArrayList(iterable);
        Collections.shuffle(shuffled);
        return shuffled;
    }
889662
public static <R> Stream<R> of(Iterable<R> iterable) {
        return new Stream<R>(iterable.iterator());
    }
829629
public static <T> C.List<T> toList(Iterable<? extends T> iterable) {
        if (iterable instanceof Collection) {
            return toList((Collection<T>) iterable);
        }
        ListBuilder<T> lb = new ListBuilder<T>(10);
        for (T t : iterable) {
            lb.add(t);
        }
        return lb.toList();
    }
768088
public static <E> long count(Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot call count with a null iterable");
        return count(iterable.iterator());
    }
128983
public static <T> HashSet<T> newHashSet(final Iterable<? extends T> iterable) {
    final HashSet<T> set = newHashSet();
    for (final T t : iterable) {
      set.add(t);
    }
    return set;
  }
833364
public static <T> CloseableIterable<T> fromIterable(Iterable<T> iterable) {
        requireNonNull(iterable);
        if (iterable instanceof CloseableIterable) return (CloseableIterable<T>) iterable;

        return new FluentCloseableIterable<T>() {
            @Override
            protected void doClose() {
                if (iterable instanceof AutoCloseable) {
                    try {
                        ((AutoCloseable) iterable).close();
                    } catch (RuntimeException re) {
                        throw re;
                    } catch (Exception e) {
                        throw new IllegalStateException(e);
                    }
                }
            }

            @Override
            protected Iterator<T> retrieveIterator() {
                return iterable.iterator();
            }
        };
    }