Advertisement
Guest User

assignment

a guest
Oct 22nd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package prob2;
  2.  
  3. import java.util.List;
  4. import java.util.function.Function;
  5. import java.util.stream.Collectors;
  6. import java.util.stream.IntStream;
  7.  
  8. public class LambdaLibrary {
  9. public final static String IMPLEMENT = "implement!";
  10.  
  11. // sample query
  12. public final static TriFunction<List<Employee>, Integer, Integer, List<Employee>> SAMPLE = (
  13. list, namelength, year) -> list.stream()
  14. .filter(e -> e.getName().length() > namelength)
  15. .filter(e -> e.getYearOfBirth() > year)
  16. .collect(Collectors.toList());
  17.  
  18.  
  19. // int[] testItem1 = {-351, 2342, 46, 17, 14, 4002, 12};
  20. //Extract subarray of even integers from an array of integers
  21.  
  22. public final static Function<int[],List<Integer>> CHANGE_TO_LIST = x->IntStream.of(x).boxed().collect(Collectors.toList());
  23.  
  24. public final static Function<List<Integer>,List<Integer>> GET_SUBSTRING = (x)-> x.stream()
  25. .filter(y->{return y%2==0;}).collect(Collectors.toList());
  26.  
  27. // int[] testItem2 = {-1, -3, 5, 11, 213};
  28. // //Compute sum of squares of an input array of integers
  29.  
  30. public final static Function<List<Integer>, Integer> SUM_OF_SQUARE = x->x.stream()
  31. .mapToInt(y->(int)Math.pow(y, 2)).sum();
  32.  
  33. // //Find all transactions from year 2011 and sort them by value (small to high).
  34. public final static Function<List<Transaction>,List<Transaction>> FOR_YEAR_2011= (List<Transaction> x)-> x.stream()
  35. .filter(x-((Transaction) x).getYear()==2011)
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement