Constrain.java 1.3 KB

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