88import lombok .Getter ;
99import lombok .Setter ;
1010
11- import java .util .ArrayList ;
12- import java .util .List ;
11+ import java .util .HashMap ;
12+ import java .util .Map ;
13+ import java .util .Objects ;
14+ import java .util .stream .Collectors ;
1315
16+ import static java .util .Map .entry ;
1417import static java .util .Optional .ofNullable ;
1518
1619@ Getter
1720@ Setter
1821@ JsonInclude (JsonInclude .Include .NON_NULL )
1922public class EncodedValuesProperties {
20- @ JsonProperty ("ford" )
23+ @ JsonProperty (Ford . KEY )
2124 private Boolean ford ;
22- @ JsonProperty ("highway" )
25+ @ JsonProperty (Highway . KEY )
2326 private Boolean highway ;
24- @ JsonProperty ("osm_way_id" )
27+ @ JsonProperty (OsmWayId . KEY )
2528 private Boolean osmWayId ;
26- @ JsonProperty ("way_surface" )
29+ @ JsonProperty (WaySurface . KEY )
2730 private Boolean waySurface ;
28- @ JsonProperty ("way_type" )
31+ @ JsonProperty (WayType . KEY )
2932 private Boolean wayType ;
30- @ JsonProperty ("agricultural_access" )
33+ @ JsonProperty (AgriculturalAccess . KEY )
3134 private Boolean agriculturalAccess ;
32- @ JsonProperty ("bus_access" )
35+ @ JsonProperty (BusAccess . KEY )
3336 private Boolean busAccess ;
34- @ JsonProperty ("delivery_access" )
37+ @ JsonProperty (DeliveryAccess . KEY )
3538 private Boolean deliveryAccess ;
36- @ JsonProperty ("forestry_access" )
39+ @ JsonProperty (ForestryAccess . KEY )
3740 private Boolean forestryAccess ;
38- @ JsonProperty ("goods_access" )
41+ @ JsonProperty (GoodsAccess . KEY )
3942 private Boolean goodsAccess ;
40- @ JsonProperty ("hgv_access" )
43+ @ JsonProperty (HgvAccess . KEY )
4144 private Boolean hgvAccess ;
42- @ JsonProperty ("hazmat_access" )
45+ @ JsonProperty (HazmatAccess . KEY )
4346 private Boolean hazmatAccess ;
44- @ JsonProperty ("max_axle_load" )
47+ @ JsonProperty (MaxAxleLoad . KEY )
4548 private Boolean maxAxleLoad ;
46- @ JsonProperty ("max_height" )
49+ @ JsonProperty (MaxHeight . KEY )
4750 private Boolean maxHeight ;
48- @ JsonProperty ("max_length" )
51+ @ JsonProperty (MaxLength . KEY )
4952 private Boolean maxLength ;
50- @ JsonProperty ("max_weight" )
53+ @ JsonProperty (MaxWeight . KEY )
5154 private Boolean maxWeight ;
52- @ JsonProperty ("max_width" )
55+ @ JsonProperty (MaxWidth . KEY )
5356 private Boolean maxWidth ;
5457
5558 public EncodedValuesProperties () {
@@ -59,71 +62,40 @@ public EncodedValuesProperties(String ignored) {
5962 // This constructor is used to create an empty object for the purpose of ignoring it in the JSON serialization.
6063 }
6164
65+ @ JsonIgnore
66+ private Map <String , Boolean > getProperties () {
67+ return new HashMap <>() {{
68+ put (Ford .KEY , ford );
69+ put (Highway .KEY , highway );
70+ put (OsmWayId .KEY , osmWayId );
71+ put (WaySurface .KEY , waySurface );
72+ put (WayType .KEY , wayType );
73+ put (AgriculturalAccess .KEY , agriculturalAccess );
74+ put (BusAccess .KEY , busAccess );
75+ put (DeliveryAccess .KEY , deliveryAccess );
76+ put (ForestryAccess .KEY , forestryAccess );
77+ put (GoodsAccess .KEY , goodsAccess );
78+ put (HgvAccess .KEY , hgvAccess );
79+ put (HazmatAccess .KEY , hazmatAccess );
80+ put (MaxAxleLoad .KEY , maxAxleLoad );
81+ put (MaxHeight .KEY , maxHeight );
82+ put (MaxLength .KEY , maxLength );
83+ put (MaxWeight .KEY , maxWeight );
84+ put (MaxWidth .KEY , maxWidth );
85+ }};
86+ }
87+
6288 @ JsonIgnore
6389 public boolean isEmpty () {
64- return osmWayId == null &&
65- ford == null && highway == null &&
66- waySurface == null && wayType == null &&
67- agriculturalAccess == null && busAccess == null && deliveryAccess == null && forestryAccess == null && goodsAccess == null && hgvAccess == null &&
68- hazmatAccess == null &&
69- maxAxleLoad == null && maxHeight == null && maxLength == null && maxWeight == null && maxWidth == null ;
90+ return !getProperties ().values ().stream ().anyMatch (Objects ::nonNull );
7091 }
7192
7293 @ JsonIgnore
7394 public String toString () {
74- List <String > out = new ArrayList <>();
75- if (Boolean .TRUE .equals (ford )) {
76- out .add (Ford .KEY );
77- }
78- if (Boolean .TRUE .equals (highway )) {
79- out .add (Highway .KEY );
80- }
81- if (Boolean .TRUE .equals (osmWayId )) {
82- out .add (OsmWayId .KEY );
83- }
84- if (Boolean .TRUE .equals (waySurface )) {
85- out .add (WaySurface .KEY );
86- }
87- if (Boolean .TRUE .equals (wayType )) {
88- out .add (WayType .KEY );
89- }
90- if (Boolean .TRUE .equals (agriculturalAccess )) {
91- out .add (AgriculturalAccess .KEY );
92- }
93- if (Boolean .TRUE .equals (busAccess )) {
94- out .add (BusAccess .KEY );
95- }
96- if (Boolean .TRUE .equals (deliveryAccess )) {
97- out .add (DeliveryAccess .KEY );
98- }
99- if (Boolean .TRUE .equals (forestryAccess )) {
100- out .add (ForestryAccess .KEY );
101- }
102- if (Boolean .TRUE .equals (goodsAccess )) {
103- out .add (GoodsAccess .KEY );
104- }
105- if (Boolean .TRUE .equals (hgvAccess )) {
106- out .add (HgvAccess .KEY );
107- }
108- if (Boolean .TRUE .equals (hazmatAccess )) {
109- out .add (HazmatAccess .KEY );
110- }
111- if (Boolean .TRUE .equals (maxAxleLoad )) {
112- out .add (MaxAxleLoad .KEY );
113- }
114- if (Boolean .TRUE .equals (maxHeight )) {
115- out .add (MaxHeight .KEY );
116- }
117- if (Boolean .TRUE .equals (maxLength )) {
118- out .add (MaxLength .KEY );
119- }
120- if (Boolean .TRUE .equals (maxWeight )) {
121- out .add (MaxWeight .KEY );
122- }
123- if (Boolean .TRUE .equals (maxWidth )) {
124- out .add (MaxWidth .KEY );
125- }
126- return String .join ("," , out );
95+ return getProperties ().entrySet ().stream ()
96+ .filter (e -> Boolean .TRUE .equals (e .getValue ()))
97+ .map (Map .Entry ::getKey )
98+ .collect (Collectors .joining ("," ));
12799 }
128100
129101 public void merge (EncodedValuesProperties other ) {
@@ -146,5 +118,3 @@ public void merge(EncodedValuesProperties other) {
146118 maxWidth = ofNullable (this .maxWidth ).orElse (other .maxWidth );
147119 }
148120}
149-
150-
0 commit comments