1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
   | public class PriorityTable {          private Map<Character, Map<Character, Character>> table = new HashMap<>();     private static Set<Producter> gs;     
 
 
 
 
 
 
      public PriorityTable(             Set<Producter> producterSet,             char start,             Map<Character, Set<Character>> firstVt,             Map<Character, Set<Character>> lastVt) {         gs = producterSet;         Map<Character, List<String>> map = GSBuilder.gsHelper(gs);         for(Character vn : GSBuilder.getVN(gs)) {             List<String> producters = map.get(vn);             for (int i = 0; i < producters.size(); i++) {                 String producter = producters.get(i);                 for (int j = 0; j < producter.length(); j++) {                     char ch = producter.charAt(j);                     if(ch<'A'||ch>'Z'){                         if(j+1 < producter.length()){                             char next = producter.charAt(j+1);                             if(next>='A' && next<='Z'){                                                              Set<Character> set = firstVt.get(next);                                 Map<Character,Character> tmp = table.containsKey(ch) ? table.get(ch) : new HashMap<>();                                 for(Character c : set){                                     tmp.put(c, '<');                                 }                                 table.put(ch, tmp);                                 if(j+2 < producter.length()) {                                     char nnext = producter.charAt(j + 2);                                     if (nnext <'A' || nnext > 'Z') {                                                      tmp = table.containsKey(ch) ? table.get(ch) : new HashMap<>();                                         tmp.put(nnext, '=');                                         table.put(ch, tmp);                                     }                                 }                             }else{                                                                                   Map<Character,Character> tmp = table.containsKey(ch) ? table.get(ch) : new HashMap<>();                                 tmp.put(next, '=');                                 table.put(ch, tmp);                             }                         }                     }else {                         if (j+1 < producter.length()) {                             char next = producter.charAt(j + 1);                             if(next < 'A' || next > 'Z'){                                                            Set<Character> set = lastVt.get(ch);                                 for(Character c : set){                                     if (table.containsKey(c)) {                                         table.get(c).put(next, '>');                                     } else {                                         Map<Character,Character> tmp = new HashMap<>();                                         tmp.put(next, '>');                                         table.put(c, tmp);                                     }                                 }                             }                         }                     }                 }             }         }         Set<Character> set = firstVt.get(start);         Map<Character,Character> tmp = new HashMap<>();         for(Character c : set){             tmp.put(c, '<');         }         table.put('#', tmp);
          set = lastVt.get(start);         for(Character c : set){             if (table.containsKey(c)) {                 table.get(c).put('#', '>');             } else {                 tmp = new HashMap<>();                 tmp.put('#', '>');                 table.put(c, tmp);             }         }
          tmp = table.containsKey('#') ? table.get('#') : new HashMap<>();         tmp.put('#', '=');         table.put('#',tmp);     }
      public void show(){         Set<Character> vt = getVT(gs);         vt.add('#');         int control = 0;         for (Character value : vt) {                 if (control == 0) {                 System.out.print("\t");             }             control++;             System.out.print(value);             if (control != vt.size()) {                 System.out.print("\t");             }         }         System.out.println();         for (Character value : vt) {             System.out.print(value);             for (Character value1 : vt) {                 Character ch = table.get(value).get(value1);                 if (ch != null) {                     System.out.print("\t" + ch);                 } else {                     System.out.print("\t" + " ");                 }             }             System.out.println();         }     }
           public char findTable(Character vt_row, Character vt_col){         if(table.get(vt_row) != null && table.get(vt_row).get(vt_col) != null){             return table.get(vt_row).get(vt_col);         }else{             return '?';         }     } }
  |