Skip to content

Commit 9b87732

Browse files
committed
Delete PreferencesInjector
1 parent 57db7a4 commit 9b87732

3 files changed

Lines changed: 10 additions & 729 deletions

File tree

lib/src/main/java/com/team2813/lib2813/preferences/PersistedConfiguration.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ public final class PersistedConfiguration {
125125
* @throws IllegalStateException If {@code preferenceName} was used for a different record class.
126126
*/
127127
public static <T extends Record> T fromPreferences(String preferenceName, T configWithDefaults) {
128-
return fromPreferences(preferenceName, configWithDefaults, PATH_SEPARATOR);
128+
@SuppressWarnings("unchecked")
129+
Class<T> recordClass = (Class<T>) configWithDefaults.getClass();
130+
return fromPreferences(preferenceName, recordClass, configWithDefaults);
129131
}
130132

131133
/**
@@ -151,24 +153,17 @@ public static <T extends Record> T fromPreferences(String preferenceName, T conf
151153
* @throws IllegalStateException If {@code preferenceName} was used for a different record class.
152154
*/
153155
public static <T extends Record> T fromPreferences(String preferenceName, Class<T> recordClass) {
154-
return fromPreferences(preferenceName, recordClass, null, PATH_SEPARATOR);
155-
}
156-
157-
static <T extends Record> T fromPreferences(
158-
String preferenceName, T configWithDefaults, char pathSeparator) {
159-
@SuppressWarnings("unchecked")
160-
Class<T> recordClass = (Class<T>) configWithDefaults.getClass();
161-
return fromPreferences(preferenceName, recordClass, configWithDefaults, pathSeparator);
156+
return fromPreferences(preferenceName, recordClass, null);
162157
}
163158

164159
private static <T extends Record> T fromPreferences(
165-
String preferenceName, Class<T> recordClass, T configWithDefaults, char pathSeparator) {
160+
String preferenceName, Class<T> recordClass, T configWithDefaults) {
166161
NetworkTableInstance ntInstance = NetworkTableInstance.getDefault();
167162
validatePreferenceName(preferenceName);
168163
verifyNotRegisteredToAnotherClass(ntInstance, preferenceName, recordClass);
169164

170165
try {
171-
return createFromPreferences(preferenceName, recordClass, configWithDefaults, pathSeparator);
166+
return createFromPreferences(preferenceName, recordClass, configWithDefaults);
172167
} catch (ReflectiveOperationException e) {
173168
if (throwExceptions) {
174169
throw new RuntimeException(e); // For self-tests.
@@ -197,8 +192,7 @@ private static void verifyNotRegisteredToAnotherClass(
197192
}
198193

199194
NetworkTable preferencesTable = ntInstance.getTable("Preferences");
200-
String key = String.format("%s%c.registeredTo", name, PATH_SEPARATOR);
201-
NetworkTableEntry entry = preferencesTable.getEntry(key);
195+
NetworkTableEntry entry = preferencesTable.getEntry(name + "/.registeredTo");
202196
if (!entry.exists()) {
203197
entry.setString(recordName);
204198
} else {
@@ -213,15 +207,15 @@ private static void verifyNotRegisteredToAnotherClass(
213207
}
214208

215209
private static <T> T createFromPreferences(
216-
String prefix, Class<? extends T> clazz, T configWithDefaults, char pathSeparator)
210+
String prefix, Class<? extends T> clazz, T configWithDefaults)
217211
throws ReflectiveOperationException {
218212
var components = clazz.getRecordComponents();
219213
Object[] params = new Object[components.length];
220214
Class<?>[] types = new Class[components.length];
221215
int i = 0;
222216
for (RecordComponent component : components) {
223217
String name = component.getName();
224-
String key = prefix + pathSeparator + name;
218+
String key = prefix + PATH_SEPARATOR + name;
225219
Class<?> type = component.getType();
226220
types[i] = type;
227221

@@ -250,7 +244,7 @@ private static <T> T createFromPreferences(
250244
}
251245

252246
if (isRecordField) {
253-
params[i] = createFromPreferences(key, type, componentValue, pathSeparator);
247+
params[i] = createFromPreferences(key, type, componentValue);
254248
} else if (factory == null) {
255249
warn("Cannot store '%s' in Preferences; type %s is unsupported", name, type);
256250
params[i] = componentValue;

lib/src/main/java/com/team2813/lib2813/preferences/PreferencesInjector.java

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)