Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Hashtable colorsTable(){
- Hashtable candidateInfo = new Hashtable();
- DBFTable candTable = dataModel.getCandidates();
- DBFTable partyTable = dataModel.getParties();
- //partyTable indexes
- // These indexes are to find the field index of the colors in the party DBFTable
- int partyIndex = partyTable.getFieldIndex("PARTY");
- int redIndex = partyTable.getFieldIndex(dataModel.RED_FIELD);
- int greenIndex = partyTable.getFieldIndex(dataModel.GREEN_FIELD);
- int blueIndex = partyTable.getFieldIndex(dataModel.BLUE_FIELD);
- //candTable indexes
- int candPartyIndex = candTable.getFieldIndex("PARTY");
- int candidateIndex = candTable.getFieldIndex(dataModel.CANDIDATE_FIELD);
- Iterator<DBFRecord> candIt = candTable.recordsIterator();
- while (candIt.hasNext())
- {
- //this goes through the candidate's table and gets their name and their party
- DBFRecord candRecord = candIt.next();
- String candidate = (String)candRecord.getData(candidateIndex);
- String party = (String)candRecord.getData(candPartyIndex);
- //this goes through the party table to get the colors to store into the hashtable
- Iterator<DBFRecord> partyIt = partyTable.recordsIterator();
- while (partyIt.hasNext()){
- DBFRecord partyRecord = partyIt.next();
- String currentParty = (String)partyRecord.getData(0);
- if(party.equals(currentParty)){
- ArrayList colors = new ArrayList(3);
- colors.add(0,partyRecord.getData(redIndex));
- colors.add(1,partyRecord.getData(greenIndex));
- colors.add(2,partyRecord.getData(blueIndex));
- candidateInfo.put(candidate, colors);
- }
- }
- }
- return candidateInfo;
- }
Add Comment
Please, Sign In to add comment