Advertisement
vladimirVenkov

Wildcards44.

Jun 17th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1.  static int goNextChar(String input) {
  2.         for (int i = 0; i < input.length(); i++) {
  3.             char temp = input.charAt(i);
  4.             if (Character.isAlphabetic(temp)) {
  5.                 return i;
  6.             }
  7.         }
  8.         return - 1;
  9.     }
  10.  
  11.     static boolean compare(String inp, String expr) {
  12.         if(inp.length() == 0 && expr.length() == 0) return true;
  13.         int counter = 0;
  14.         for (int i = 0; i < expr.length(); i++) {
  15.             if(expr.charAt(i)== '?') counter ++;
  16.             }
  17.             if(counter == inp.length()) return true;
  18.             else if (counter > inp.length()) return false;
  19.             if(expr.contains("*")) return true;
  20.  
  21.             return false;
  22.     }
  23.  
  24.     static boolean ifEquals(String inp, String expr) {
  25.         if(inp.equals(expr)) return true;
  26.         return false;
  27.     }
  28.  
  29.     static boolean isSame(String inp, String expr) {
  30.         int indexNextChar = goNextChar(expr);
  31.         if (indexNextChar < 0 ) {
  32.             return compare(inp, expr);
  33.         }
  34.         char nextChar = expr.charAt(indexNextChar);
  35.         for (int i = 0; i < inp.length(); i++) {
  36.             if (inp.charAt(i) == nextChar) {
  37.                 if(isSame(inp.substring(0,i),
  38.                         expr.substring(0, indexNextChar))
  39.                     &&
  40.                 isSame(trimarator(inp, i + 1 , inp.length()),
  41.                         trimarator(expr, indexNextChar + 1, expr.length()))) return true;
  42.             }
  43.         }
  44.         return false;
  45.     }
  46.  
  47.     static String trimarator(String word, int inOne, int twoInd) {
  48.         if (inOne >= twoInd || inOne < 0 ) return "";
  49.         return word.substring(inOne,twoInd);
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement