use of org.onebusaway.admin.search.Filter in project onebusaway-application-modules by camsys.
the class VehicleSearchServiceImpl method buildFilters.
private List<Filter<VehicleStatus>> buildFilters(Map<VehicleSearchParameters, String> searchParameters) {
List<Filter<VehicleStatus>> filters = new ArrayList<Filter<VehicleStatus>>();
// Since all parameters are optional we have to look for each one
// To-do: there might be a better way of doing this
String vehicleId = searchParameters.get(VehicleSearchParameters.VEHICLE_ID);
if (StringUtils.isNotBlank(vehicleId)) {
filters.add(new VehicleIdFilter(vehicleId));
}
String route = searchParameters.get(VehicleSearchParameters.ROUTE);
if (StringUtils.isNotBlank(route)) {
filters.add(new RouteFilter(route));
}
String inferredPhase = searchParameters.get(VehicleSearchParameters.INFERRED_PHASE);
if (!inferredPhase.equalsIgnoreCase("All")) {
filters.add(new InferredPhaseFilter(inferredPhase));
}
String dsc = searchParameters.get(VehicleSearchParameters.DSC);
if (StringUtils.isNotBlank(dsc)) {
filters.add(new DSCFilter(dsc));
}
String depot = searchParameters.get(VehicleSearchParameters.DEPOT);
if (!depot.equalsIgnoreCase("All")) {
filters.add(new DepotFilter(depot));
}
String pulloutStatus = searchParameters.get(VehicleSearchParameters.PULLOUT_STATUS);
if (!pulloutStatus.equalsIgnoreCase("All")) {
filters.add(new PulloutStatusFilter());
}
String emergencyStatus = searchParameters.get(VehicleSearchParameters.EMERGENCY_STATUS);
if (emergencyStatus.equalsIgnoreCase("true")) {
filters.add(new EmergencyStatusFilter());
}
String formalInferrence = searchParameters.get(VehicleSearchParameters.FORMAL_INFERRENCE);
if (formalInferrence.equalsIgnoreCase("true")) {
filters.add(new FormalInferrenceFilter());
}
return filters;
}
use of org.onebusaway.admin.search.Filter in project onebusaway-application-modules by camsys.
the class VehicleSearchServiceImpl method search.
@Override
public List<VehicleStatus> search(List<VehicleStatus> vehicleStatusRecords, Map<VehicleSearchParameters, String> searchParameters) {
List<VehicleStatus> matchingRecords = new ArrayList<VehicleStatus>();
// Build filters corresponding to the search parameters
List<Filter<VehicleStatus>> filters = buildFilters(searchParameters);
// Since there are no filters specified, return all the records as matched records
if (filters.isEmpty()) {
matchingRecords.addAll(vehicleStatusRecords);
} else {
// Apply each filter to each record
for (VehicleStatus vehicleStatus : vehicleStatusRecords) {
boolean matches = applyFilters(vehicleStatus, filters);
if (matches) {
matchingRecords.add(vehicleStatus);
}
}
}
return matchingRecords;
}
Aggregations