Return the last element of an iterable, or empty if the iterable is empty.

@param iterable the iterable
@param <E>      type of the iterable elements
@return Optional of the last element, or empty if nothing in the iterable
336664
public static <E> Optional<E> last(final Iterable<E> iterable) {
        checkNotNull(iterable, "last requires a non null iterable");
        final Iterator<E> iterator = iterable.iterator();
        if (!iterator.hasNext()) {
            return Optional.empty();
        }

        E lastElement;
        do {
            lastElement = iterator.next();
        } while (iterator.hasNext());

        return Optional.of(lastElement);
    }
520634
@Nullable
  public static <T> T getOnlyElement(Iterable<? extends T> iterable, @Nullable T defaultValue) {
    return Iterators.getOnlyElement(iterable.iterator(), defaultValue);
  }
1239804
public int addLast(Iterable<? extends KTypeCursor<? extends KType>> iterable) {
    int size = 0;
    for (KTypeCursor<? extends KType> cursor : iterable) {
      addLast(cursor.value);
      size++;
    }
    return size;
  }
989337
public static <T> Stream<T> ofNullable(Iterable<T> iterable) {
        return null == iterable ? Stream.empty() : stream(iterable);
    }
616703
public static <E> Optional<E> maybeLast(Iterator<E> iterator) {
        return new MaybeLastElement<E>().apply(iterator);
    }
1134607
@Deprecated
  public static <T> boolean allTheSame(final Iterable<T> iterable) {
    if (Iterables.isEmpty(iterable)) {
      return true;
    }

    final T reference = Iterables.getFirst(iterable, null);

    for (final T x : iterable) {
      if (!x.equals(reference)) {
        return false;
      }
    }
    return true;
  }
1109511
public static JCTree innermostType(JCTree type) {
        JCTree lastAnnotatedType = null;
        JCTree cur = type;
        loop: while (true) {
            switch (cur.getTag()) {
            case TYPEARRAY:
                lastAnnotatedType = null;
                cur = ((JCArrayTypeTree)cur).elemtype;
                break;
            case WILDCARD:
                lastAnnotatedType = null;
                cur = ((JCWildcard)cur).inner;
                break;
            case ANNOTATED_TYPE:
                lastAnnotatedType = cur;
                cur = ((JCAnnotatedType)cur).underlyingType;
                break;
            default:
                break loop;
            }
        }
        if (lastAnnotatedType!=null) {
            return lastAnnotatedType;
        } else {
            return cur;
        }
    }
1255003
public static <T> Iterable<T> nullSafeIterable(T[] iterable) {
        return (iterable != null) ? Arrays.asList(iterable) : Collections.EMPTY_LIST;
    }
809283
public static <E> E one(Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot call one with a null iterable");
        return new OneElement<E>().apply(iterable.iterator());
    }
522891
public static <T> int count(Iterable<T> iterable) {
        int count = 0;

        if (iterable != null) {
            Iterator<T> iter = iterable.iterator();
            while (iter.hasNext()) {
                iter.next();
                count++;
            }
        }

        return count;
    }
396394
public static <T> T detectIfNone(Iterable<T> iterable, Predicate<? super T> predicate, T ifNone)
    {
        T result = Iterate.detect(iterable, predicate);
        return result == null ? ifNone : result;
    }
593395
public static <T> CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type) {
        return wrap(Iterators.filter(iterator, type), iterator);
    }
853652
public static <T> T getLast(List<T> list)
    {
        if (list == null)
        {
            return null;
        }
        if (list instanceof RandomAccess)
        {
            return RandomAccessListIterate.getLast(list);
        }
        ListIterator<T> iterator = list.listIterator(list.size());
        if (iterator.hasPrevious())
        {
            return iterator.previous();
        }
        return null;
    }
599757
@Deprecated
    public static <T> CloseableIterable<T> wrap(final Iterable<T> iterable) {
        return fromIterable(iterable);
    }
556998
public static <E> Optional<E> maybeOne(Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot call maybeOne with a null iterable");
        return new MaybeOneElement<E>().apply(iterable.iterator());
    }
1270127
@Override
  public <T> Iterable<Binding<T>> bindings(Class<T> type)
  {
    BindingSet<T> set = (BindingSet) _bindingSetMap.get(type);

    if (set != null) {
      return (Iterable) set;
    }
    else {
      return Collections.EMPTY_LIST;
    }
  }
1284662
public static <E> Optional<E> maybeAt(long index, Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot call maybeAt with a null iterable");
        final Iterator<E> filtered = new FilteringIterator<E>(iterable.iterator(), new AtIndex<E>(index));
        return new MaybeFirstElement<E>().apply(filtered);
    }