Guest User

Untitled

a guest
Jun 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. public Hashtable colorsTable(){
  2. Hashtable candidateInfo = new Hashtable();
  3.  
  4. DBFTable candTable = dataModel.getCandidates();
  5. DBFTable partyTable = dataModel.getParties();
  6. //partyTable indexes
  7. // These indexes are to find the field index of the colors in the party DBFTable
  8. int partyIndex = partyTable.getFieldIndex("PARTY");
  9. int redIndex = partyTable.getFieldIndex(dataModel.RED_FIELD);
  10. int greenIndex = partyTable.getFieldIndex(dataModel.GREEN_FIELD);
  11. int blueIndex = partyTable.getFieldIndex(dataModel.BLUE_FIELD);
  12.  
  13. //candTable indexes
  14. int candPartyIndex = candTable.getFieldIndex("PARTY");
  15. int candidateIndex = candTable.getFieldIndex(dataModel.CANDIDATE_FIELD);
  16.  
  17. Iterator<DBFRecord> candIt = candTable.recordsIterator();
  18. while (candIt.hasNext())
  19. {
  20. //this goes through the candidate's table and gets their name and their party
  21. DBFRecord candRecord = candIt.next();
  22. String candidate = (String)candRecord.getData(candidateIndex);
  23. String party = (String)candRecord.getData(candPartyIndex);
  24.  
  25. //this goes through the party table to get the colors to store into the hashtable
  26. Iterator<DBFRecord> partyIt = partyTable.recordsIterator();
  27. while (partyIt.hasNext()){
  28. DBFRecord partyRecord = partyIt.next();
  29. String currentParty = (String)partyRecord.getData(0);
  30. if(party.equals(currentParty)){
  31. ArrayList colors = new ArrayList(3);
  32. colors.add(0,partyRecord.getData(redIndex));
  33. colors.add(1,partyRecord.getData(greenIndex));
  34. colors.add(2,partyRecord.getData(blueIndex));
  35. candidateInfo.put(candidate, colors);
  36. }
  37. }
  38. }
  39. return candidateInfo;
  40. }
Add Comment
Please, Sign In to add comment