@@ -785,6 +785,14 @@ public Integer apply(Integer item) {
785785 }
786786 });
787787 assertEquals ("[5, 4, 6, 3, 1, 2]" , resultObj .toString ());
788+ final List <Integer > resultChain =
789+ $ .chain (asList (1 , 2 , 3 , 4 , 5 , 6 )).sortBy (
790+ new Function1 <Integer , Integer >() {
791+ public Integer apply (Integer item ) {
792+ return Double .valueOf (Math .sin (item ) * 1000 ).intValue ();
793+ }
794+ }).value ();
795+ assertEquals ("[5, 4, 6, 3, 1, 2]" , resultChain .toString ());
788796 }
789797
790798/*
@@ -836,6 +844,14 @@ public Double apply(Double num) {
836844 }
837845 });
838846 assertEquals ("{1.0=[1.3], 2.0=[2.1, 2.4]}" , resultObj .toString ());
847+ final Map <Double , List <Double >> resultChain =
848+ (Map <Double , List <Double >>) $ .chain (asList (1.3 , 2.1 , 2.4 )).groupBy (
849+ new Function1 <Double , Double >() {
850+ public Double apply (Double num ) {
851+ return Math .floor (num );
852+ }
853+ }).item ();
854+ assertEquals ("{1.0=[1.3], 2.0=[2.1, 2.4]}" , resultChain .toString ());
839855 }
840856
841857/*
@@ -866,6 +882,10 @@ public String toString() {
866882 final Map <String , List <Person >> resultObj =
867883 new $ (asList (new Person ("moe" , 40 ), new Person ("larry" , 50 ), new Person ("curly" , 60 ))).indexBy ("age" );
868884 assertEquals ("{40=[moe, 40], 50=[larry, 50], 60=[curly, 60]}" , resultObj .toString ());
885+ final Map <String , List <Person >> resultChain =
886+ (Map <String , List <Person >>) $ .chain (asList (new Person ("moe" , 40 ), new Person ("larry" , 50 ),
887+ new Person ("curly" , 60 ))).indexBy ("age" ).item ();
888+ assertEquals ("{40=[moe, 40], 50=[larry, 50], 60=[curly, 60]}" , resultChain .toString ());
869889 final Map <String , List <Person >> result2 =
870890 $ .indexBy (asList (new Person ("moe" , 40 ), new Person ("larry" , 50 ), new Person ("curly" , 60 )), "age2" );
871891 assertEquals ("{null=[moe, 40, larry, 50, curly, 60]}" , result2 .toString ());
@@ -905,6 +925,15 @@ public String apply(Person person) {
905925 }
906926 });
907927 assertEquals ("{moe=2, curly=1}" , resultObj .toString ());
928+ final Map <String , Integer > resultChain =
929+ (Map <String , Integer >) $ .chain (asList (new Person ("moe" , 40 ), new Person ("moe" , 50 ),
930+ new Person ("curly" , 60 ))).countBy (
931+ new Function1 <Person , String >() {
932+ public String apply (Person person ) {
933+ return person .name ;
934+ }
935+ }).item ();
936+ assertEquals ("{moe=2, curly=1}" , resultChain .toString ());
908937 }
909938
910939/*
0 commit comments