Java Collection Unique uniqueResult(final Collection c)

Here you can find the source of uniqueResult(final Collection c)

Description

unique Result

License

BSD License

Declaration

public static <T> T uniqueResult(final Collection<T> c) 

Method Source Code


//package com.java2s;
//License from project: BSD License 

import java.util.Collection;

public class Main {
    public static <T> T uniqueResult(final Collection<T> c) {
        switch (c.size()) {
        case 0:/*  ww w . ja v  a 2s.  co  m*/
            return null;
        case 1:
            return c.iterator().next();
        default:
            throw new IllegalStateException("Unexpected number of elements in collection: " + c.size());
        }
    }
}

Related

  1. hasUniqueObject(Collection collection)
  2. unique(Collection c)
  3. unique(Collection c, Collection result)
  4. uniqueIdNotIn(String prefix, Collection exclusions)
  5. uniqueResult(Collection results)