| 4 | |
| 5 | /* A class that represents a rectangular array of letters. */ |
| 6 | public class Rectangle { |
| 7 | |
| 8 | // Rectangle data. |
| 9 | public int height; |
| 10 | public int length; |
| 11 | public char [][] matrix; |
| 12 | |
| 13 | public Rectangle(int len) { |
| 14 | this.length = len; |
| 15 | } |
| 16 | |
| 17 | /* Construct a rectangular array of letters of the specified length |
| 18 | * and height, and backed by the specified matrix of letters. (It is |
| 19 | * assumed that the length and height specified as arguments are |
| 20 | * consistent with the array argument's dimensions.) |
| 21 | */ |
| 22 | public Rectangle(int length, int height, char[][] letters) { |
| 23 | this.height = letters.length; |
| 24 | this.length = letters[0].length; |
| 25 | matrix = letters; |
| 26 | } |
| 27 | |
| 28 | /* Return the letter present at the specified location in the array. |
| 29 | */ |
| 30 | public char getLetter (int i, int j) { |
| 31 | return matrix[i][j]; |
| 32 | } |
| 33 | |
| 34 | public String getColumn(int i) { |
| 35 | char[] column = new char[height]; |
| 36 | for (int j = 0; j < height; j++) { |
| 37 | column[j] = getLetter(j, i); |
| 38 | } |
| 39 | return new String(column); |
| 40 | } |
| 41 | |
| 42 | public boolean isComplete(int l, int h, WordGroup groupList) { |
| 43 | // Check if we have formed a complete rectangle. |
| 44 | if (height == h) { |
| 45 | // Check if each column is a word in the dictionary. |
| 46 | for (int i = 0; i < l; i++) { |
| 47 | String col = getColumn(i); |
| 48 | if (!groupList.containsWord(col)) { |
| 49 | return false; // Invalid rectangle. |
| 50 | } |
| 51 | } |
| 52 | return true; // Valid Rectangle! |
| 53 | } |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | public boolean isPartialOK(int l, Trie trie) { |
| 58 | if (height == 0) { |
| 59 | return true; |
| 60 | } |
| 61 | for (int i = 0; i < l ; i++ ) { |
| 62 | String col = getColumn(i); |
| 63 | if (!trie.contains(col)) { |
nothing calls this directly
no outgoing calls
no test coverage detected