fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.Pattern;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. private static long nano;
  12. private static Pattern p = Pattern.compile("\\w+(?:\\.\\*)?$");
  13.  
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16. String original = "testing.asd.five";
  17.  
  18. // your code goes here
  19. ts();
  20. System.out.println(test1(original));
  21. te();
  22.  
  23. ts();
  24. System.out.println(test2(original));
  25. te();
  26.  
  27. ts();
  28. System.out.println(test3(original));
  29. te();
  30. }
  31.  
  32. private static void ts () {
  33. nano = System.nanoTime();
  34. }
  35.  
  36. private static void te () {
  37. System.out.println("Time: "+(System.nanoTime()-nano));
  38. System.out.println();
  39. }
  40.  
  41. static String test1(String s) {
  42. if (s.endsWith(".*")) {
  43. s = s.substring(0, s.length() - 2);
  44. }
  45.  
  46. int pos = s.lastIndexOf('.') + 1;
  47. return s.substring(0, pos) + '*';
  48. }
  49.  
  50. protected static String test2 (String permission) {
  51. return permission.replaceAll("\\w+(?:\\.\\*)?$", "*");
  52. }
  53.  
  54. protected static String test3 (String permission) {
  55. return p.matcher(permission).replaceFirst("*");
  56. }
  57. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
testing.asd.*
Time: 455091

testing.asd.*
Time: 964303

testing.asd.*
Time: 237979