public static < C extends Comparable < ? > > List < Poset < C > > singletons ( final Collection < ? extends C > collection ) { List < Poset < C >> singletons = new ArrayList ( ) ; Poset previous = NULL ; for ( C element : collection ) { List < C > set = new ArrayList <> ( ) ; set . add ( element ) ; Poset poset = new Poset ( set ) ; if ( previous != NULL && poset . isComparableTo ( previous ) ) { throw new IllegalArgumentException ( "singletons must be disjoint" ) ; } singletons . add ( poset ) ; previous = poset ; } return singletons ; }
Calculate partially ordered singletons from a totally - ordered collection .