Java Iterable getUnique(Iterable iterable)

Here you can find the source of getUnique(Iterable iterable)

Description

get Unique

License

Open Source License

Declaration

public static <T> T getUnique(Iterable<T> iterable) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.util.Iterator;

public class Main {
    public static <T> T getUnique(Iterable<T> iterable) {
        final Iterator<? extends T> iter = iterable.iterator();
        if (!iter.hasNext()) {
            throw new IllegalArgumentException("No element in " + iterable);
        }/*  w w w .ja  v  a 2 s.  com*/
        final T result = iter.next();
        if (iter.hasNext()) {
            throw new IllegalArgumentException("More than (expected) one element in " + iterable);
        }
        return result;
    }
}

Related

  1. getByIndex(Iterable iterable, int index)
  2. getElement(final Iterable iterable, int index)
  3. getIdenticalElement(Iterable iterable)
  4. getLongestCommonToken(Iterable iterable, char tokenSeparatorChar)
  5. getMessageString(Iterable msgs)
  6. implodeStrings(Iterable strings, String glue)
  7. indexOfSame(Iterable iterable, T obj)
  8. internalSeparate(StringBuilder buff, Iterable args, String separator, String useWhenNone)
  9. isEmpty(Iterable iterable)