No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArcFilterFactory.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package org.insa.algo;
  2. import java.util.ArrayList;
  3. import java.util.EnumSet;
  4. import java.util.List;
  5. import org.insa.algo.AbstractInputData.ArcFilter;
  6. import org.insa.graph.AccessRestrictions.AccessMode;
  7. import org.insa.graph.AccessRestrictions.AccessRestriction;
  8. import org.insa.graph.Arc;
  9. public class ArcFilterFactory {
  10. /**
  11. * @return List of all arc filters in this factory.
  12. */
  13. public static List<ArcFilter> getAllFilters() {
  14. List<ArcFilter> filters = new ArrayList<>();
  15. // Common filters:
  16. // 1. No filter (all arcs allowed):
  17. filters.add(new ArcFilter() {
  18. @Override
  19. public boolean isAllowed(Arc arc) {
  20. return true;
  21. }
  22. @Override
  23. public String toString() {
  24. return "All roads are allowed.";
  25. }
  26. });
  27. // 2. Only road allowed for cars:
  28. filters.add(new ArcFilter() {
  29. @Override
  30. public boolean isAllowed(Arc arc) {
  31. return arc.getRoadInformation().getAccessRestrictions()
  32. .isAllowedForAny(AccessMode.MOTORCAR, EnumSet.complementOf(EnumSet
  33. .of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
  34. }
  35. @Override
  36. public String toString() {
  37. return "Only roads open for cars.";
  38. }
  39. });
  40. // 3. Non-private roads for pedestrian and bicycle:
  41. filters.add(new ArcFilter() {
  42. @Override
  43. public boolean isAllowed(Arc arc) {
  44. return arc.getRoadInformation().getAccessRestrictions()
  45. .isAllowedForAny(AccessMode.FOOT, EnumSet.complementOf(EnumSet
  46. .of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
  47. }
  48. @Override
  49. public String toString() {
  50. return "Non-private roads for pedestrian.";
  51. }
  52. });
  53. // 3. Add your own filters here (do not forget to implement toString() to get an
  54. // understandable output!):
  55. return filters;
  56. }
  57. }