(int l, int h, Rectangle rectangle)
| 77 | * column is a word in the dictionary. |
| 78 | */ |
| 79 | private Rectangle makePartialRectangle(int l, int h, Rectangle rectangle) { |
| 80 | |
| 81 | // Check if we have formed a complete rectangle by seeing if each column |
| 82 | // is in the dictionary |
| 83 | if (rectangle.height == h) { |
| 84 | if (rectangle.isComplete(l, h, groupList[h - 1])) { |
| 85 | return rectangle; |
| 86 | } else { |
| 87 | return null; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // If the rectangle is not empty, validate that each column is a |
| 92 | // substring of a word of length h in the dictionary using the |
| 93 | // trie of words of length h. |
| 94 | if (!rectangle.isPartialOK(l, trieList[h - 1])) { |
| 95 | return null; |
| 96 | } |
| 97 | |
| 98 | // For each word of length l, try to make a new rectangle by adding |
| 99 | // the word to the existing rectangle. |
| 100 | for (int i = 0; i < groupList[l-1].length(); i++) { |
| 101 | Rectangle orgPlus = rectangle.append(groupList[l-1].getWord(i)); |
| 102 | Rectangle rect = makePartialRectangle(l, h, orgPlus); |
| 103 | if (rect != null) { |
| 104 | return rect; |
| 105 | } |
| 106 | } |
| 107 | return null; |
| 108 | } |
| 109 | |
| 110 | // Test harness. |
| 111 | public static void main(String[] args) { |
no test coverage detected