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> dummyVoters; public DummyVotersFetcher() { this.dummyVoters = new ArrayList<>(); // voter that cant vote HashMap voter1 = new HashMap<>(); voter1.put("IDNumber", "123123123"); voter1.put("EligibleToVote", "no"); voter1.put("Status", "HasNotVoted"); voter1.put("Channel", "IDCMaths"); // voter that can vote HashMap 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> FetchVoters(List filters) { List> votersWithFilters = new ArrayList<>(); for (String filter : filters) { for (HashMap 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; } }