1 | /** Class to store the keywords and their visible states
|
---|
2 | * @author Matthew Carey
|
---|
3 | */
|
---|
4 | package vishnu.testvis.visual;
|
---|
5 |
|
---|
6 | public class KeyWordArray
|
---|
7 | {
|
---|
8 | /** constant default number enabled */
|
---|
9 | public static final int DEFAULT_ENABLED = 12;
|
---|
10 | /** the word array */
|
---|
11 | private String words[];
|
---|
12 | /** the enabled array */
|
---|
13 | private boolean enabled[];
|
---|
14 | /** the count */
|
---|
15 | private int count;
|
---|
16 | /**
|
---|
17 | * constructor
|
---|
18 | * @param word array
|
---|
19 | * @param count size
|
---|
20 | * @param number enabled
|
---|
21 | */
|
---|
22 | public KeyWordArray(String words[],int count,int numEnabled)
|
---|
23 | {
|
---|
24 | this.words = words;
|
---|
25 | this.count = count;
|
---|
26 | enabled = new boolean[count];
|
---|
27 | int theNumEnabled = count<numEnabled?count:numEnabled;
|
---|
28 | for (int c = 0; c < numEnabled && c < count; c++)
|
---|
29 | enabled[c]=true;
|
---|
30 | if (count > theNumEnabled)
|
---|
31 | for (int c = theNumEnabled; c < count; c++)
|
---|
32 | enabled[c]=false;
|
---|
33 | }
|
---|
34 | /**
|
---|
35 | * constructor
|
---|
36 | * @param word array
|
---|
37 | * @param count size
|
---|
38 | */
|
---|
39 | public KeyWordArray(String words[],int count)
|
---|
40 | {
|
---|
41 | this(words,count,DEFAULT_ENABLED);
|
---|
42 | }
|
---|
43 |
|
---|
44 | public KeyWordArray()
|
---|
45 | {
|
---|
46 | this.count = 0;
|
---|
47 | this.words = null;
|
---|
48 | this.enabled = null;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Find the size of the array
|
---|
53 | * @return size of the array
|
---|
54 | */
|
---|
55 | public int getNumWords()
|
---|
56 | {
|
---|
57 | return count;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Find the word at index
|
---|
62 | * @param index of word
|
---|
63 | * @return word at index
|
---|
64 | */
|
---|
65 | public String getWord(int index)
|
---|
66 | {
|
---|
67 | if (index >=0 && index < count)
|
---|
68 | return this.words[index];
|
---|
69 | return "Error out of index";
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Get state of word at index
|
---|
74 | * @param index of word
|
---|
75 | * @return state of word
|
---|
76 | */
|
---|
77 | public boolean getState(int index)
|
---|
78 | {
|
---|
79 | if (index >=0 && index < count)
|
---|
80 | return this.enabled[index];
|
---|
81 | return false;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Set state of word at index
|
---|
86 | * @param index of word
|
---|
87 | * @param new state of word
|
---|
88 | */
|
---|
89 | public void setState(int index, boolean state)
|
---|
90 | {
|
---|
91 | if (index >=0 && index < count)
|
---|
92 | this.enabled[index]=state;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Get number of enabled words
|
---|
97 | * @return number of enabled words
|
---|
98 | */
|
---|
99 | public int getNumEnabled()
|
---|
100 | {
|
---|
101 | int result = 0;
|
---|
102 | for (int c = 0; c < count; c++)
|
---|
103 | if (enabled[c]) result++;
|
---|
104 | return result;
|
---|
105 | }
|
---|
106 | }
|
---|