1 | package vishnu.testvis.visual;
|
---|
2 | /** This class is maps the display array of keywords onto the stored.
|
---|
3 | * array
|
---|
4 | * @author Matthew Carey</a>
|
---|
5 | */
|
---|
6 | public class MapKeyWords
|
---|
7 | {
|
---|
8 | /** array map for display to stored */
|
---|
9 | protected int nodesToWord[] = null;
|
---|
10 | /** array map for stored to display */
|
---|
11 | protected int wordsToNodes[] = null;
|
---|
12 | /**
|
---|
13 | * map for display to stored
|
---|
14 | * @param display index
|
---|
15 | * @return stored index
|
---|
16 | */
|
---|
17 | public int mapNodesToWords(int index)
|
---|
18 | {
|
---|
19 | return nodesToWord[index];
|
---|
20 | }
|
---|
21 | /**
|
---|
22 | * map for stored to display
|
---|
23 | * @param stored index
|
---|
24 | * @return the display index
|
---|
25 | */
|
---|
26 | public int mapWordsToNodes(int index)
|
---|
27 | {
|
---|
28 | return wordsToNodes[index];
|
---|
29 | }
|
---|
30 | /**
|
---|
31 | * constructor
|
---|
32 | * @param keywordarray instance containing list of key words and states
|
---|
33 | */
|
---|
34 | public MapKeyWords(KeyWordArray keyWordArray)
|
---|
35 | {
|
---|
36 | int c, n=0;
|
---|
37 | nodesToWord = null;
|
---|
38 | wordsToNodes = null;
|
---|
39 | nodesToWord = new int [keyWordArray.getNumEnabled()];
|
---|
40 | wordsToNodes = new int [keyWordArray.getNumWords()];
|
---|
41 | int totalKeyWord=keyWordArray.getNumWords();
|
---|
42 | for (c=0;c < totalKeyWord; c++)
|
---|
43 | {
|
---|
44 | if (keyWordArray.getState(c))
|
---|
45 | {
|
---|
46 | wordsToNodes[c]=n;
|
---|
47 | nodesToWord[n]=c;
|
---|
48 | n++;
|
---|
49 | }
|
---|
50 | else
|
---|
51 | wordsToNodes[c]=-1;
|
---|
52 | }
|
---|
53 | }
|
---|
54 | /**
|
---|
55 | * re-Map the KeyWords with a new vector
|
---|
56 | * @param array the new vector
|
---|
57 | * @param keywordarray instance containing list of key words and states
|
---|
58 | */
|
---|
59 | public void reMapKeyWords(int array[],KeyWordArray keyWordArray)
|
---|
60 | {
|
---|
61 | if (array.length != keyWordArray.getNumEnabled())
|
---|
62 | return;
|
---|
63 | int c;
|
---|
64 | for (c=0;c<array.length;c++)
|
---|
65 | {
|
---|
66 | if (!keyWordArray.getState(array[c]))
|
---|
67 | return;
|
---|
68 | }
|
---|
69 |
|
---|
70 | for (c=0;c<array.length;c++)
|
---|
71 | {
|
---|
72 | wordsToNodes[array[c]]=c;
|
---|
73 | nodesToWord[c]=array[c];
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | }
|
---|