duration.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package java
  2. const durationConstTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
  3. {{- if $r.Const }}
  4. private final com.google.protobuf.Duration {{ constantName . "Const" }} = {{ durLit $r.GetConst }};
  5. {{- end -}}
  6. {{- if $r.Lt }}
  7. private final com.google.protobuf.Duration {{ constantName . "Lt" }} = {{ durLit $r.GetLt }};
  8. {{- end -}}
  9. {{- if $r.Lte }}
  10. private final com.google.protobuf.Duration {{ constantName . "Lte" }} = {{ durLit $r.GetLte }};
  11. {{- end -}}
  12. {{- if $r.Gt }}
  13. private final com.google.protobuf.Duration {{ constantName . "Gt" }} = {{ durLit $r.GetGt }};
  14. {{- end -}}
  15. {{- if $r.Gte }}
  16. private final com.google.protobuf.Duration {{ constantName . "Gte" }} = {{ durLit $r.GetGte }};
  17. {{- end -}}
  18. {{- if $r.In }}
  19. private final com.google.protobuf.Duration[] {{ constantName . "In" }} = new com.google.protobuf.Duration[]{
  20. {{- range $r.In }}
  21. {{ durLit . }},
  22. {{- end }}
  23. };
  24. {{- end -}}
  25. {{- if $r.NotIn }}
  26. private final com.google.protobuf.Duration[] {{ constantName . "NotIn" }} = new com.google.protobuf.Duration[]{
  27. {{- range $r.NotIn }}
  28. {{ durLit . }},
  29. {{- end }}
  30. };
  31. {{- end -}}`
  32. const durationTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
  33. {{- template "required" . -}}
  34. {{- if $r.Const }}
  35. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ConstantValidation.constant("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Const" }});
  36. {{- end -}}
  37. {{- if and (or $r.Lt $r.Lte) (or $r.Gt $r.Gte)}}
  38. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.range("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ if $r.Lt }}{{ constantName . "Lt" }}{{ else }}null{{ end }}, {{ if $r.Lte }}{{ constantName . "Lte" }}{{ else }}null{{ end }}, {{ if $r.Gt }}{{ constantName . "Gt" }}{{ else }}null{{ end }}, {{ if $r.Gte }}{{ constantName . "Gte" }}{{ else }}null{{ end }}, com.google.protobuf.util.Durations.comparator());
  39. {{- else -}}
  40. {{- if $r.Lt }}
  41. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.lessThan("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Lt" }}, com.google.protobuf.util.Durations.comparator());
  42. {{- end -}}
  43. {{- if $r.Lte }}
  44. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.lessThanOrEqual("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Lte" }}, com.google.protobuf.util.Durations.comparator());
  45. {{- end -}}
  46. {{- if $r.Gt }}
  47. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.greaterThan("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Gt" }}, com.google.protobuf.util.Durations.comparator());
  48. {{- end -}}
  49. {{- if $r.Gte }}
  50. if ({{ hasAccessor . }}) io.envoyproxy.pgv.ComparativeValidation.greaterThanOrEqual("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "Gte" }}, com.google.protobuf.util.Durations.comparator());
  51. {{- end -}}
  52. {{- end -}}
  53. {{- if $r.In }}
  54. if ({{ hasAccessor . }}) io.envoyproxy.pgv.CollectiveValidation.in("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "In" }});
  55. {{- end -}}
  56. {{- if $r.NotIn }}
  57. if ({{ hasAccessor . }}) io.envoyproxy.pgv.CollectiveValidation.notIn("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ constantName . "NotIn" }});
  58. {{- end -}}
  59. `