2016-06-18 08:13:04 -04:00
|
|
|
package polling_station_dashboard.search.VotersFetcher;
|
|
|
|
|
2016-06-18 08:35:00 -04:00
|
|
|
import java.util.*;
|
2016-06-18 08:13:04 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2016-06-18 08:35:00 -04:00
|
|
|
* is implemented in this dummy way for testing the normal gui flow
|
2016-06-18 08:13:04 -04:00
|
|
|
*/
|
|
|
|
public class DummyVotersFetcher implements VotersFetcher {
|
|
|
|
|
2016-06-18 08:35:00 -04:00
|
|
|
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
|
|
|
|
*/
|
2016-06-18 08:13:04 -04:00
|
|
|
@Override
|
2016-06-18 08:35:00 -04:00
|
|
|
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;
|
2016-06-18 08:13:04 -04:00
|
|
|
}
|
|
|
|
}
|