public static < T > Decision < T > unique ( ) { return new Decision < T > ( ) { private Set < T > seen = Sets . newHashSet ( ) ; private boolean sawNull = false ; @ Override public boolean apply ( T arg ) { if ( arg == null ) { boolean result = ! sawNull ; sawNull = true ; return result ; } else if ( seen . contains ( arg ) ) { return false ; } else { seen . add ( arg ) ; return true ; } } } ; }
Returns a stateful decision that returns true if its argument has been passed to the decision before else false .