public static boolean hasUniqueObject ( Collection < ? > collection ) { if ( isEmpty ( collection ) ) { return false ; } boolean hasCandidate = false ; Object candidate = null ; for ( Object elem : collection ) { if ( ! hasCandidate ) { hasCandidate = true ; candidate = elem ; } else if ( candidate != elem ) { return false ; } } return true ; }
Determine whether the given Collection only contains a single unique object .