@@ -204,4 +204,90 @@ default String defaultValueDisplay() {
204204
205205 Map <String , Object > valueProvider ();
206206 }
207+
208+ public static abstract class MapSettings implements Settings {
209+ protected final Map <String , Object > map ;
210+
211+ protected MapSettings (Map <String , Object > map ) {
212+ this .map = map ;
213+ }
214+
215+ @ Override
216+ public ValueWrapper <Double > defaultValue () {
217+ Object value = map .get ("default-value" );
218+ if (value == null ) {
219+ return ValueWrapper .notHandled ();
220+ }
221+
222+ try {
223+ double numberValue = Double .parseDouble (Objects .toString (value ));
224+ return ValueWrapper .handled (numberValue );
225+ } catch (Exception e ) {
226+ return ValueWrapper .error ("Invalid number: \" " + value + "\" . Fallback to null" , e );
227+ }
228+ }
229+
230+ @ Override
231+ public String defaultValueDisplay () {
232+ return Optional .ofNullable (map .get ("default-value-display" ))
233+ .map (Object ::toString )
234+ .orElse (Settings .super .defaultValueDisplay ());
235+ }
236+
237+ @ Override
238+ public String displayNullName () {
239+ return Optional .ofNullable (map .get ("null-name" ))
240+ .map (Object ::toString )
241+ .orElse ("---" );
242+ }
243+
244+ @ Override
245+ public String displayNullUuid () {
246+ return Optional .ofNullable (map .get ("null-uuid" ))
247+ .map (Object ::toString )
248+ .orElse ("---" );
249+ }
250+
251+ @ Override
252+ public String displayNullValue () {
253+ return Optional .ofNullable (map .get ("null-value" ))
254+ .map (Object ::toString )
255+ .orElse ("---" );
256+ }
257+
258+ @ Override
259+ public boolean showErrors () {
260+ return Optional .ofNullable (map .get ("show-errors" ))
261+ .map (Object ::toString )
262+ .map (String ::toLowerCase )
263+ .map (Boolean ::parseBoolean )
264+ .orElse (false );
265+ }
266+
267+ @ Override
268+ public boolean resetOnError () {
269+ return Optional .ofNullable (map .get ("reset-on-error" ))
270+ .map (Object ::toString )
271+ .map (String ::toLowerCase )
272+ .map (Boolean ::parseBoolean )
273+ .orElse (true );
274+ }
275+
276+ @ Override
277+ public boolean reverse () {
278+ return Optional .ofNullable (map .get ("reverse" ))
279+ .map (String ::valueOf )
280+ .map (Boolean ::parseBoolean )
281+ .orElse (false );
282+ }
283+
284+ @ Override
285+ public Map <String , Object > valueProvider () {
286+ return map ;
287+ }
288+
289+ public Map <String , Object > map () {
290+ return map ;
291+ }
292+ }
207293}
0 commit comments