map.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. package java
  2. const mapConstTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
  3. {{ if or (ne (.Elem "" "").Typ "none") (ne (.Key "" "").Typ "none") }}
  4. {{ renderConstants (.Key "key" "Key") }}
  5. {{ renderConstants (.Elem "value" "Value") }}
  6. {{- end -}}
  7. `
  8. const mapTpl = `{{ $f := .Field }}{{ $r := .Rules -}}
  9. {{- if $r.GetIgnoreEmpty }}
  10. if ( !{{ accessor . }}.isEmpty() ) {
  11. {{- end -}}
  12. {{- if $r.GetMinPairs }}
  13. io.envoyproxy.pgv.MapValidation.min("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ $r.GetMinPairs }});
  14. {{- end -}}
  15. {{- if $r.GetMaxPairs }}
  16. io.envoyproxy.pgv.MapValidation.max("{{ $f.FullyQualifiedName }}", {{ accessor . }}, {{ $r.GetMaxPairs }});
  17. {{- end -}}
  18. {{- if $r.GetNoSparse }}
  19. io.envoyproxy.pgv.MapValidation.noSparse("{{ $f.FullyQualifiedName }}", {{ accessor . }});
  20. {{- end -}}
  21. {{ if or (ne (.Elem "" "").Typ "none") (ne (.Key "" "").Typ "none") }}
  22. io.envoyproxy.pgv.MapValidation.validateParts({{ accessor . }}.keySet(), key -> {
  23. {{ render (.Key "key" "Key") }}
  24. });
  25. io.envoyproxy.pgv.MapValidation.validateParts({{ accessor . }}.values(), value -> {
  26. {{ render (.Elem "value" "Value") }}
  27. });
  28. {{- end -}}
  29. {{- if $r.GetIgnoreEmpty }}
  30. }
  31. {{- end -}}
  32. `