1212
1313import java .util .List ;
1414import java .util .Map ;
15+ import java .util .Objects ;
16+
17+ import org .eclipse .emf .ecore .EcorePackage ;
18+ import org .eclipse .emf .ecore .util .ExtendedMetaData ;
1519
1620import com .fasterxml .jackson .annotation .JsonInclude ;
1721import com .fasterxml .jackson .annotation .JsonInclude .Include ;
1822
1923@ JsonInclude (Include .NON_NULL )
2024public class EMFFacetConstraints {
21-
2225 public static final String WHITESPACE = "whiteSpace" ;
2326 public static final String ENUMERATION = "enumeration" ;
2427 public static final String PATTERN = "pattern" ;
@@ -32,25 +35,54 @@ public class EMFFacetConstraints {
3235 public static final String MININCLUSIVE = "minInclusive" ;
3336 public static final String MAXINCLUSIVE = "maxInclusive" ;
3437
38+ public static final int WHITESPACE_DEFAULT = ExtendedMetaData .INSTANCE
39+ .getWhiteSpaceFacet (EcorePackage .Literals .EBOOLEAN );
40+ public static final List <String > ENUMERATION_DEFAULT = ExtendedMetaData .INSTANCE
41+ .getEnumerationFacet (EcorePackage .Literals .EBOOLEAN );
42+ public static final List <String > PATTERN_DEFAULT = ExtendedMetaData .INSTANCE
43+ .getPatternFacet (EcorePackage .Literals .EBOOLEAN );
44+ public static final int TOTALDIGITS_DEFAULT = ExtendedMetaData .INSTANCE
45+ .getTotalDigitsFacet (EcorePackage .Literals .EBOOLEAN );
46+ public static final int FRACTIONDIGITS_DEFAULT = ExtendedMetaData .INSTANCE
47+ .getFractionDigitsFacet (EcorePackage .Literals .EBOOLEAN );
48+ public static final int LENGTH_DEFAULT = ExtendedMetaData .INSTANCE
49+ .getLengthFacet (EcorePackage .Literals .EBOOLEAN );
50+ public static final int MINLENGTH_DEFAULT = ExtendedMetaData .INSTANCE
51+ .getMinLengthFacet (EcorePackage .Literals .EBOOLEAN );
52+ public static final int MAXLENGTH_DEFAULT = ExtendedMetaData .INSTANCE
53+ .getMaxLengthFacet (EcorePackage .Literals .EBOOLEAN );
54+ public static final String MINEXCLUSIVE_DEFAULT = ExtendedMetaData .INSTANCE
55+ .getMinExclusiveFacet (EcorePackage .Literals .EBOOLEAN );
56+ public static final String MAXEXCLUSIVE_DEFAULT = ExtendedMetaData .INSTANCE
57+ .getMaxExclusiveFacet (EcorePackage .Literals .EBOOLEAN );
58+ public static final String MININCLUSIVE_DEFAULT = ExtendedMetaData .INSTANCE
59+ .getMinInclusiveFacet (EcorePackage .Literals .EBOOLEAN );
60+ public static final String MAXINCLUSIVE_DEFAULT = ExtendedMetaData .INSTANCE
61+ .getMaxInclusiveFacet (EcorePackage .Literals .EBOOLEAN );
62+
3563 @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = WhiteSpaceFilter .class )
3664 private Integer whiteSpace ;
37- @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = StringListFilter .class )
65+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = EnumerationFilter .class )
3866 private List <String > enumeration ;
39- @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = StringListFilter .class )
67+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = PatternFilter .class )
4068 private List <String > pattern ;
41- @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = IntegerFilter .class )
69+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = TotalDigitsFilter .class )
4270 private Integer totalDigits ;
43- @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = IntegerFilter .class )
71+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = FractionDigitsFilter .class )
4472 private Integer fractionDigits ;
45- @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = IntegerFilter .class )
73+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = LengthFilter .class )
4674 private Integer length ;
47- @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = IntegerFilter .class )
75+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = MinLengthFilter .class )
4876 private Integer minLength ;
49- @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = IntegerFilter .class )
77+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = MaxLengthFilter .class )
5078 private Integer maxLength ;
79+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = MinExclusiveFilter .class )
5180 private String minExclusive ;
81+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = MaxExclusiveFilter .class )
5282 private String maxExclusive ;
83+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = MinInclusiveFilter .class )
5384 private String minInclusive ;
85+ @ JsonInclude (value = JsonInclude .Include .CUSTOM , valueFilter = MaxInclusiveFilter .class )
5486 private String maxInclusive ;
5587
5688 public Integer getWhiteSpace () { return whiteSpace ; }
@@ -117,19 +149,35 @@ public EMFFacetConstraints(final Map<String, Object> facetMap) {
117149 this .maxInclusive = (String ) facetMap .getOrDefault (MAXINCLUSIVE , null );
118150 }
119151
120- public EMFFacetConstraints () {
121-
152+ public EMFFacetConstraints () {}
153+
154+ @ SuppressWarnings ({ "CyclomaticComplexity" , "BooleanExpressionComplexity" })
155+ public boolean hasConstraints () {
156+ return !(Objects .equals (this .whiteSpace , WHITESPACE_DEFAULT )
157+ && Objects .equals (this .enumeration , ENUMERATION_DEFAULT )
158+ && Objects .equals (this .pattern , PATTERN_DEFAULT )
159+ && Objects .equals (this .totalDigits , TOTALDIGITS_DEFAULT )
160+ && Objects .equals (this .fractionDigits , FRACTIONDIGITS_DEFAULT )
161+ && Objects .equals (this .length , LENGTH_DEFAULT )
162+ && Objects .equals (this .minLength , MINLENGTH_DEFAULT )
163+ && Objects .equals (this .maxLength , MAXLENGTH_DEFAULT )
164+ && Objects .equals (this .minExclusive , MINEXCLUSIVE_DEFAULT )
165+ && Objects .equals (this .maxExclusive , MAXEXCLUSIVE_DEFAULT )
166+ && Objects .equals (this .minInclusive , MININCLUSIVE_DEFAULT )
167+ && Objects .equals (this .maxInclusive , MAXINCLUSIVE_DEFAULT ));
122168 }
123-
124169}
125170
126- class WhiteSpaceFilter {
171+ class DefaultValueFilter {
172+ protected Object defaultValue ;
173+
174+ DefaultValueFilter (final Object defaultValue ) {
175+ this .defaultValue = defaultValue ;
176+ }
177+
127178 @ Override
128179 public boolean equals (final Object obj ) {
129- if (obj instanceof Integer ) {
130- return obj == Integer .valueOf (0 );
131- }
132- return true ;
180+ return Objects .equals (defaultValue , obj );
133181 }
134182
135183 @ Override
@@ -138,32 +186,74 @@ public int hashCode() {
138186 }
139187}
140188
141- class IntegerFilter {
142- @ Override
143- public boolean equals (final Object obj ) {
144- if (obj instanceof Integer ) {
145- return obj == Integer .valueOf (-1 );
146- }
147- return true ;
189+ class WhiteSpaceFilter extends DefaultValueFilter {
190+ WhiteSpaceFilter () {
191+ super (EMFFacetConstraints .WHITESPACE_DEFAULT );
148192 }
193+ }
149194
150- @ Override
151- public int hashCode () {
152- return super . hashCode ( );
195+ class EnumerationFilter extends DefaultValueFilter {
196+ EnumerationFilter () {
197+ super ( EMFFacetConstraints . ENUMERATION_DEFAULT );
153198 }
154199}
155200
156- class StringListFilter {
157- @ Override
158- public boolean equals (final Object obj ) {
159- if (obj instanceof List ) {
160- return ((List <?>) obj ).isEmpty ();
161- }
162- return true ;
201+ class PatternFilter extends DefaultValueFilter {
202+ PatternFilter () {
203+ super (EMFFacetConstraints .PATTERN_DEFAULT );
163204 }
205+ }
164206
165- @ Override
166- public int hashCode () {
167- return super .hashCode ();
207+ class TotalDigitsFilter extends DefaultValueFilter {
208+ TotalDigitsFilter () {
209+ super (EMFFacetConstraints .TOTALDIGITS_DEFAULT );
210+ }
211+ }
212+
213+ class FractionDigitsFilter extends DefaultValueFilter {
214+ FractionDigitsFilter () {
215+ super (EMFFacetConstraints .FRACTIONDIGITS_DEFAULT );
216+ }
217+ }
218+
219+ class LengthFilter extends DefaultValueFilter {
220+ LengthFilter () {
221+ super (EMFFacetConstraints .LENGTH_DEFAULT );
222+ }
223+ }
224+
225+ class MinLengthFilter extends DefaultValueFilter {
226+ MinLengthFilter () {
227+ super (EMFFacetConstraints .MINLENGTH_DEFAULT );
228+ }
229+ }
230+
231+ class MaxLengthFilter extends DefaultValueFilter {
232+ MaxLengthFilter () {
233+ super (EMFFacetConstraints .MAXLENGTH_DEFAULT );
234+ }
235+ }
236+
237+ class MinExclusiveFilter extends DefaultValueFilter {
238+ MinExclusiveFilter () {
239+ super (EMFFacetConstraints .MINEXCLUSIVE_DEFAULT );
240+ }
241+ }
242+
243+ class MaxExclusiveFilter extends DefaultValueFilter {
244+ MaxExclusiveFilter () {
245+ super (EMFFacetConstraints .MAXEXCLUSIVE_DEFAULT );
246+ }
247+ }
248+
249+ class MinInclusiveFilter extends DefaultValueFilter {
250+ MinInclusiveFilter () {
251+ super (EMFFacetConstraints .MININCLUSIVE_DEFAULT );
252+ }
253+ }
254+
255+ class MaxInclusiveFilter extends DefaultValueFilter {
256+ MaxInclusiveFilter () {
257+ super (EMFFacetConstraints .MAXINCLUSIVE_DEFAULT );
168258 }
169259}
0 commit comments