From c248ed30047a0525bf792730a0fbd4de0c89ad8e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 18 Jun 2022 10:00:52 -0700 Subject: Refactor attribute lookup --- src/main/java/org/traccar/config/ConfigKey.java | 73 +++++++++++++++++++++---- 1 file changed, 61 insertions(+), 12 deletions(-) (limited to 'src/main/java/org/traccar/config/ConfigKey.java') diff --git a/src/main/java/org/traccar/config/ConfigKey.java b/src/main/java/org/traccar/config/ConfigKey.java index c046a46a5..b8151392c 100644 --- a/src/main/java/org/traccar/config/ConfigKey.java +++ b/src/main/java/org/traccar/config/ConfigKey.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 - 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2019 - 2022 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,30 +15,34 @@ */ package org.traccar.config; +import java.util.HashSet; import java.util.List; +import java.util.Set; -public class ConfigKey { +public abstract class ConfigKey { private final String key; - private final List types; + private final Set types = new HashSet<>(); + private final Class valueClass; private final T defaultValue; - ConfigKey(String key, List types) { - this(key, types, null); - } - - ConfigKey(String key, List types, T defaultValue) { + ConfigKey(String key, List types, Class valueClass, T defaultValue) { this.key = key; - this.types = types; + this.types.addAll(types); + this.valueClass = valueClass; this.defaultValue = defaultValue; } - String getKey() { + public String getKey() { return key; } - public List getTypes() { - return types; + public boolean hasType(KeyType type) { + return types.contains(type); + } + + public Class getValueClass() { + return valueClass; } public T getDefaultValue() { @@ -46,3 +50,48 @@ public class ConfigKey { } } + +class StringConfigKey extends ConfigKey { + StringConfigKey(String key, List types) { + super(key, types, String.class, null); + } + StringConfigKey(String key, List types, String defaultValue) { + super(key, types, String.class, defaultValue); + } +} + +class BooleanConfigKey extends ConfigKey { + BooleanConfigKey(String key, List types) { + super(key, types, Boolean.class, null); + } + BooleanConfigKey(String key, List types, Boolean defaultValue) { + super(key, types, Boolean.class, defaultValue); + } +} + +class IntegerConfigKey extends ConfigKey { + IntegerConfigKey(String key, List types) { + super(key, types, Integer.class, null); + } + IntegerConfigKey(String key, List types, Integer defaultValue) { + super(key, types, Integer.class, defaultValue); + } +} + +class LongConfigKey extends ConfigKey { + LongConfigKey(String key, List types) { + super(key, types, Long.class, null); + } + LongConfigKey(String key, List types, Long defaultValue) { + super(key, types, Long.class, defaultValue); + } +} + +class DoubleConfigKey extends ConfigKey { + DoubleConfigKey(String key, List types) { + super(key, types, Double.class, null); + } + DoubleConfigKey(String key, List types, Double defaultValue) { + super(key, types, Double.class, defaultValue); + } +} -- cgit v1.2.3