All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.fge.jsonpatch.Iterables Maven / Gradle / Ivy

Go to download

JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7386) implementation in Java

The newest version!
package com.github.fge.jsonpatch;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * @author {@literal @}soberich on 30-Nov-18
 */
public final class Iterables {

    private Iterables() {}

    /**
     * Returns the last element of {@code iterable}.
     *
     * @param  underlying type being iterated
     * @param iterable type of iterable
     * @return the last element of {@code iterable}
     * @throws NoSuchElementException if the iterable is empty
     */
    public static  T getLast(Iterable iterable) {
        Iterator iterator = iterable.iterator();
        while (true) {
            T current = iterator.next();
            if (!iterator.hasNext()) {
                return current;
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy