Constrain.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package holeg.model;
  2. import java.util.function.Predicate;
  3. import com.google.gson.annotations.Expose;
  4. public class Constrain {
  5. private Predicate<Flexibility> constrainFunction;
  6. private String name;
  7. public Constrain(Predicate<Flexibility> constrainFunction,String name) {
  8. this.constrainFunction = constrainFunction;
  9. this.name = name;
  10. }
  11. public Predicate<Flexibility> getConstrainFunction() {
  12. return constrainFunction;
  13. }
  14. public String getName() {
  15. return name;
  16. }
  17. //Example Constrains:
  18. /** Flexibility should be offered when Element is active.*/
  19. public static Predicate<Flexibility> onConstrain = f -> f.getElement().active;
  20. /** Flexibility should be offered when Element is inactive.*/
  21. public static Predicate<Flexibility> offConstrain = f -> !f.getElement().active;
  22. public static Constrain createOnConstrain() {
  23. return new Constrain( onConstrain, "onConstrain");
  24. }
  25. public static Constrain createOffConstrain() {
  26. return new Constrain( offConstrain, "offConstrain");
  27. }
  28. /**
  29. * TODO(Tom2022-01-25): Delete me ....
  30. * @return
  31. */
  32. public boolean fixJson() {
  33. if(name.equals("onConstrain")) {
  34. constrainFunction = onConstrain;
  35. return false;
  36. }else if(name.equals("offConstrain")){
  37. constrainFunction = offConstrain;
  38. return false;
  39. }else {
  40. return false;
  41. }
  42. }
  43. }