LardaX

not working

Feb 9th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import java.util.function.*;
  7. import java.util.stream.Collectors;
  8.  
  9. public class PredicateParty {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.         List<String> guestList = Arrays.stream(reader.readLine().split(" ")).collect(Collectors.toList());
  13.  
  14.         String[] commandLine = reader.readLine().split(" ");
  15.  
  16.         while (!"Party!".equals(commandLine[0])) {
  17.             String command = commandLine[0];
  18.             Predicate<String> validate = getPredicate(commandLine);
  19.  
  20.             switch (command) {
  21.                 case "Remove":
  22.                     guestList.removeIf(validate);
  23.                     break;
  24.                 case "Double":
  25.                     guestList.forEach(guest -> {
  26.                         if (validate.test(guest)) {
  27.                             guestList.add(guest);
  28.                         }
  29.                     });
  30.                     break;
  31.             }
  32.  
  33.             commandLine = reader.readLine().split(" ");
  34.         }
  35.  
  36.         System.out.println(String.join(", ", guestList) + " are going to the party!");
  37.     }
  38.  
  39.     public static Predicate<String> getPredicate(String[] commandLine) {
  40.         String command = commandLine[1];
  41.         switch (command) {
  42.             case "StartsWith":
  43.                 return x -> x.indexOf(commandLine[2]) == 0;
  44.             case "EndsWith":
  45.                 return x -> x.lastIndexOf(commandLine[2]) == x.length() - commandLine[2].length();
  46.             case "Length":
  47.                 return x -> x.length() == Integer.parseInt(commandLine[2]);
  48.             default:
  49.                 return null;
  50.         }
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment