Constrain.java 1023 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package holeg.model;
  2. import java.util.function.Predicate;
  3. import com.google.gson.annotations.Expose;
  4. public class Constrain {
  5. private final Predicate<Flexibility> constrainFunction;
  6. private final 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. }