aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/config/ConfigSuffix.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-18 10:00:52 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-18 10:00:52 -0700
commitc248ed30047a0525bf792730a0fbd4de0c89ad8e (patch)
tree750adc33654a4f8947e09528cfb85534cfceb8f1 /src/main/java/org/traccar/config/ConfigSuffix.java
parent68826cdc767bae6b8b39e88667372f0c6161efa9 (diff)
downloadtrackermap-server-c248ed30047a0525bf792730a0fbd4de0c89ad8e.tar.gz
trackermap-server-c248ed30047a0525bf792730a0fbd4de0c89ad8e.tar.bz2
trackermap-server-c248ed30047a0525bf792730a0fbd4de0c89ad8e.zip
Refactor attribute lookup
Diffstat (limited to 'src/main/java/org/traccar/config/ConfigSuffix.java')
-rw-r--r--src/main/java/org/traccar/config/ConfigSuffix.java81
1 files changed, 70 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/config/ConfigSuffix.java b/src/main/java/org/traccar/config/ConfigSuffix.java
index ede4c107d..aac3219c6 100644
--- a/src/main/java/org/traccar/config/ConfigSuffix.java
+++ b/src/main/java/org/traccar/config/ConfigSuffix.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.
@@ -17,15 +17,11 @@ package org.traccar.config;
import java.util.List;
-public class ConfigSuffix<T> {
+public abstract class ConfigSuffix<T> {
- private final String keySuffix;
- private final List<KeyType> types;
- private final T defaultValue;
-
- ConfigSuffix(String keySuffix, List<KeyType> types) {
- this(keySuffix, types, null);
- }
+ protected final String keySuffix;
+ protected final List<KeyType> types;
+ protected final T defaultValue;
ConfigSuffix(String keySuffix, List<KeyType> types, T defaultValue) {
this.keySuffix = keySuffix;
@@ -33,8 +29,71 @@ public class ConfigSuffix<T> {
this.defaultValue = defaultValue;
}
- public ConfigKey<T> withPrefix(String prefix) {
- return new ConfigKey<>(prefix + keySuffix, types, defaultValue);
+ public abstract ConfigKey<T> withPrefix(String prefix);
+
+}
+
+class StringConfigSuffix extends ConfigSuffix<String> {
+ StringConfigSuffix(String key, List<KeyType> types) {
+ super(key, types, null);
+ }
+ StringConfigSuffix(String key, List<KeyType> types, String defaultValue) {
+ super(key, types, defaultValue);
+ }
+ @Override
+ public ConfigKey<String> withPrefix(String prefix) {
+ return new StringConfigKey(prefix + keySuffix, types, defaultValue);
+ }
+}
+
+class BooleanConfigSuffix extends ConfigSuffix<Boolean> {
+ BooleanConfigSuffix(String key, List<KeyType> types) {
+ super(key, types, null);
+ }
+ BooleanConfigSuffix(String key, List<KeyType> types, Boolean defaultValue) {
+ super(key, types, defaultValue);
+ }
+ @Override
+ public ConfigKey<Boolean> withPrefix(String prefix) {
+ return new BooleanConfigKey(prefix + keySuffix, types, defaultValue);
+ }
+}
+
+class IntegerConfigSuffix extends ConfigSuffix<Integer> {
+ IntegerConfigSuffix(String key, List<KeyType> types) {
+ super(key, types, null);
+ }
+ IntegerConfigSuffix(String key, List<KeyType> types, Integer defaultValue) {
+ super(key, types, defaultValue);
+ }
+ @Override
+ public ConfigKey<Integer> withPrefix(String prefix) {
+ return new IntegerConfigKey(prefix + keySuffix, types, defaultValue);
}
+}
+class LongConfigSuffix extends ConfigSuffix<Long> {
+ LongConfigSuffix(String key, List<KeyType> types) {
+ super(key, types, null);
+ }
+ LongConfigSuffix(String key, List<KeyType> types, Long defaultValue) {
+ super(key, types, defaultValue);
+ }
+ @Override
+ public ConfigKey<Long> withPrefix(String prefix) {
+ return new LongConfigKey(prefix + keySuffix, types, defaultValue);
+ }
+}
+
+class DoubleConfigSuffix extends ConfigSuffix<Double> {
+ DoubleConfigSuffix(String key, List<KeyType> types) {
+ super(key, types, null);
+ }
+ DoubleConfigSuffix(String key, List<KeyType> types, Double defaultValue) {
+ super(key, types, defaultValue);
+ }
+ @Override
+ public ConfigKey<Double> withPrefix(String prefix) {
+ return new DoubleConfigKey(prefix + keySuffix, types, defaultValue);
+ }
}