|
20 | 20 |
|
21 | 21 | package com.noahhusby.lib.application.config;
|
22 | 22 |
|
23 |
| -import com.google.gson.JsonElement; |
24 | 23 | import com.noahhusby.lib.application.config.exception.ClassNotConfigException;
|
25 | 24 | import com.noahhusby.lib.application.config.provider.ConfigurationProvider;
|
26 | 25 | import com.noahhusby.lib.application.config.source.FileConfigurationSource;
|
|
34 | 33 | import java.lang.reflect.Field;
|
35 | 34 | import java.lang.reflect.InvocationTargetException;
|
36 | 35 | import java.lang.reflect.Type;
|
37 |
| -import java.util.HashMap; |
38 | 36 | import java.util.LinkedHashMap;
|
39 | 37 | import java.util.Map;
|
40 | 38 |
|
@@ -125,44 +123,6 @@ public void load() {
|
125 | 123 | provider.load();
|
126 | 124 | }
|
127 | 125 |
|
128 |
| - /** |
129 |
| - * Gets a config class object from the config file. |
130 |
| - * |
131 |
| - * @param clazz Config class. |
132 |
| - * @param <T> Config class type. |
133 |
| - * @return T class |
134 |
| - * @deprecated As of 0.1.60, replaced by {@link #sync(Class)} |
135 |
| - */ |
136 |
| - @SneakyThrows |
137 |
| - public <T> T bind(Class<T> clazz) { |
138 |
| - provider.load(); |
139 |
| - Map<String, Object> members = new HashMap<>(); |
140 |
| - for (Map.Entry<?, ?> entry : getProvider().getEntries().entrySet()) { |
141 |
| - members.put((String) entry.getKey(), entry.getValue()); |
142 |
| - } |
143 |
| - |
144 |
| - Map<String, Field> fields = new HashMap<>(); |
145 |
| - for (Field field : clazz.getDeclaredFields()) { |
146 |
| - if (field.isAnnotationPresent(Config.Ignore.class)) { |
147 |
| - continue; |
148 |
| - } |
149 |
| - Config.Name nameAnnotation = field.getAnnotation(Config.Name.class); |
150 |
| - String name = nameAnnotation == null ? field.getName() : nameAnnotation.value(); |
151 |
| - field.setAccessible(true); |
152 |
| - fields.put(name, field); |
153 |
| - } |
154 |
| - |
155 |
| - T instance = clazz.newInstance(); |
156 |
| - for (Map.Entry<String, Field> entry : fields.entrySet()) { |
157 |
| - Field field = entry.getValue(); |
158 |
| - JsonElement jsonElement = HusbyUtil.GSON.toJsonTree(members.get(entry.getKey())); |
159 |
| - Object value = HusbyUtil.GSON.fromJson(jsonElement, field.getType()); |
160 |
| - field.setAccessible(true); |
161 |
| - field.set(instance, value); |
162 |
| - } |
163 |
| - return instance; |
164 |
| - } |
165 |
| - |
166 | 126 | /**
|
167 | 127 | * Updates config file from class, and updates config instance with values from config.
|
168 | 128 | *
|
|
0 commit comments