meerkat-java/voting-station-gui/src/polling_station_dashboard/search/VotersFetcher/DummyVotersFetcher.java

61 lines
2.0 KiB
Java
Raw Normal View History

package polling_station_dashboard.search.votersFetcher;
import java.util.*;
/**
* Created by Vladimir Eliezer Tokarev on 18/06/2016.
* This object used for receiving empty list of object for the logic of add voter could be tested
* is implemented in this dummy way for testing the normal gui flow
*/
public class DummyVotersFetcher implements VotersFetcher {
private List<HashMap<String,String>> dummyVoters;
public DummyVotersFetcher()
{
this.dummyVoters = new ArrayList<>();
// voter that cant vote
HashMap<String, String> voter1 = new HashMap<>();
voter1.put("IDNumber", "123123123");
voter1.put("EligibleToVote", "no");
voter1.put("Status", "HasNotVoted");
voter1.put("Channel", "IDCMaths");
// voter that can vote
HashMap<String, String> voter2 = new HashMap<>();
voter2.put("IDNumber", "234234234");
voter2.put("EligibleToVote", "yes");
voter2.put("Status", "HasNotVoted");
voter2.put("Channel", "IDCPhysics");
this.dummyVoters.add(voter1);
this.dummyVoters.add(voter2);
}
/**
* Gets list of filters and return all the voters from dummy voters that have those filters
* @param filters list of strings
*/
@Override
public List<HashMap<String,String>> FetchVoters(List<String> filters)
{
List<HashMap<String,String>> votersWithFilters = new ArrayList<>();
for (String filter : filters) {
for (HashMap<String, String> voter: this.dummyVoters) {
Iterator it = voter.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
if (((String) pair.getKey()).contains(filter) || ((String) pair.getValue()).contains(filter)) {
votersWithFilters.add(voter);
break;
}
}
}
}
return votersWithFilters;
}
}