Lortseam 4 роки тому
батько
коміт
32e9606001

+ 9 - 10
lib/src/main/java/me/lortseam/completeconfig/data/BaseCollection.java

@@ -15,7 +15,6 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Modifier;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.stream.Collectors;
 
 abstract class BaseCollection implements ParentDataPart {
 
@@ -41,7 +40,7 @@ abstract class BaseCollection implements ParentDataPart {
         return Collections.unmodifiableCollection(collections);
     }
 
-    void resolve(ConfigContainer container) {
+    void resolveContainer(ConfigContainer container) {
         entries.resolve(container);
         for (Class<? extends ConfigContainer> clazz : container.getConfigClasses()) {
             resolve(Arrays.stream(clazz.getDeclaredFields()).filter(field -> {
@@ -61,7 +60,7 @@ abstract class BaseCollection implements ParentDataPart {
                 } catch (IllegalAccessException e) {
                     throw new RuntimeException(e);
                 }
-            }).collect(Collectors.toList()));
+            }).toArray(ConfigContainer[]::new));
             Class<?>[] nestedClasses = clazz.getDeclaredClasses();
             ArrayUtils.reverse(nestedClasses);
             resolve(Arrays.stream(nestedClasses).filter(nestedClass -> {
@@ -81,17 +80,17 @@ abstract class BaseCollection implements ParentDataPart {
                 } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
                     throw new RuntimeException("Failed to instantiate nested class " + nestedClass, e);
                 }
-            }).collect(Collectors.toList()));
+            }).toArray(ConfigContainer[]::new));
         }
-        resolve(Arrays.asList(container.getTransitives()));
+        resolve(container.getTransitives());
     }
 
-    protected void resolve(Iterable<ConfigContainer> containers) {
-        for (ConfigContainer c : containers) {
-            if (c instanceof ConfigGroup) {
-                collections.resolve((ConfigGroup) c);
+    protected void resolve(ConfigContainer... containers) {
+        for (ConfigContainer container : containers) {
+            if (container instanceof ConfigGroup) {
+                collections.resolve((ConfigGroup) container);
             } else {
-                resolve(c);
+                resolveContainer(container);
             }
         }
     }

+ 1 - 1
lib/src/main/java/me/lortseam/completeconfig/data/CollectionSet.java

@@ -14,7 +14,7 @@ public class CollectionSet extends DataSet<Collection> {
     void resolve(ConfigGroup group) {
         String groupID = group.getID();
         Collection collection = new Collection(groupID, translation.append(groupID), group.getTooltipTranslationKeys(), group.getComment());
-        collection.resolve(group);
+        collection.resolveContainer(group);
         if (collection.isEmpty()) {
             logger.warn("[CompleteConfig] Group " + groupID + " is empty");
             return;

+ 2 - 2
lib/src/main/java/me/lortseam/completeconfig/data/Config.java

@@ -42,7 +42,7 @@ public final class Config extends BaseCollection {
 
     private final ConfigSource source;
 
-    private Config(ConfigSource source, LinkedHashSet<ConfigContainer> children) {
+    private Config(ConfigSource source, ConfigContainer[] children) {
         super(TranslationIdentifier.from(source));
         this.source = source;
         resolve(children);
@@ -142,7 +142,7 @@ public final class Config extends BaseCollection {
                 logger.warn("[CompleteConfig] Mod " + modID + " tried to create an empty config");
                 return null;
             }
-            Config config = new Config(new ConfigSource(modID, branch), children);
+            Config config = new Config(new ConfigSource(modID, branch), children.toArray(new ConfigContainer[0]));
             if (config.isEmpty()) {
                 logger.warn("[CompleteConfig] Config of " + config.source + " is empty");
                 return null;

+ 15 - 21
lib/src/test/java/me/lortseam/completeconfig/data/BaseCollectionTest.java

@@ -13,8 +13,6 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import java.util.Arrays;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.*;
 import static org.mockito.Mockito.mock;
@@ -34,95 +32,91 @@ public class BaseCollectionTest {
         logCaptor.clearLogs();
     }
 
-    private void resolve(ConfigContainer... containers) {
-        baseCollection.resolve(Arrays.asList(containers));
-    }
-
     @Test
     public void resolve_includeFieldIfAnnotated() {
-        resolve(new ContainerWithEntry(), new ContainerWithContainerWithEntry(), new ContainerWithGroupWithEntry());
+        baseCollection.resolve(new ContainerWithEntry(), new ContainerWithContainerWithEntry(), new ContainerWithGroupWithEntry());
         assertEquals(2, baseCollection.getEntries().size());
         assertEquals(1, baseCollection.getCollections().size());
     }
 
     @Test
     public void resolve_excludeFieldIfNotAnnotated() {
-        resolve(new ContainerWithField());
+        baseCollection.resolve(new ContainerWithField());
         assertTrue(baseCollection.isEmpty());
     }
 
     @Test
     public void resolve_includeFieldInEntries() {
-        resolve(new EntriesContainerWithEntry());
+        baseCollection.resolve(new EntriesContainerWithEntry());
         assertEquals(1, baseCollection.getEntries().size());
     }
 
     @Test
     public void resolve_excludeFieldInEntriesIfContainer() {
-        resolve(new EntriesContainerWithEmptyContainer());
+        baseCollection.resolve(new EntriesContainerWithEmptyContainer());
         assertTrue(baseCollection.isEmpty());
     }
 
     @Test
     public void resolve_excludeFieldInEntriesIfIgnoreAnnotated() {
-        resolve(new EntriesContainerWithIgnoredField());
+        baseCollection.resolve(new EntriesContainerWithIgnoredField());
         assertTrue(baseCollection.isEmpty());
     }
 
     @Test
     public void resolve_excludeFieldInEntriesIfTransient() {
-        resolve(new EntriesContainerWithTransientField());
+        baseCollection.resolve(new EntriesContainerWithTransientField());
         assertTrue(baseCollection.isEmpty());
     }
 
     @Test
     public void resolve_includeSuperclassFieldIfNonStatic() {
-        resolve(new SubclassOfContainerWithEntry(), new SubclassOfContainerWithContainerWithEntry());
+        baseCollection.resolve(new SubclassOfContainerWithEntry(), new SubclassOfContainerWithContainerWithEntry());
         assertEquals(2, baseCollection.getEntries().size());
     }
 
     @Test
     public void resolve_excludeSuperclassFieldIfStatic() {
-        resolve(new SubclassOfContainerWithStaticEntry());
+        baseCollection.resolve(new SubclassOfContainerWithStaticEntry());
         // TODO: Add container test
         assertTrue(baseCollection.isEmpty());
     }
 
     @Test
     public void resolve_includeFromMethod() {
-        resolve(new ContainerIncludingContainerWithEntry(), new ContainerIncludingGroupWithEntry());
+        baseCollection.resolve(new ContainerIncludingContainerWithEntry(), new ContainerIncludingGroupWithEntry());
         assertEquals(1, baseCollection.getEntries().size());
         assertEquals(1, baseCollection.getCollections().size());
     }
 
     @Test
     public void resolve_includeNestedIfStatic() {
-        resolve(new ContainerNestingStaticContainerWithEntry());
+        baseCollection.resolve(new ContainerNestingStaticContainerWithEntry());
         assertEquals(1, baseCollection.getEntries().size());
     }
 
     @Test
     public void resolve_throwIfNestedNonContainer() {
-        IllegalAnnotationTargetException exception = assertThrows(IllegalAnnotationTargetException.class, () -> resolve(new ContainerNestingStaticClass()));
+        IllegalAnnotationTargetException exception = assertThrows(IllegalAnnotationTargetException.class, () -> baseCollection.resolve(new ContainerNestingStaticClass()));
         assertEquals("Transitive " + ContainerNestingStaticClass.Class.class + " must implement " + ConfigContainer.class.getSimpleName(), exception.getMessage());
     }
 
     @Test
     public void resolve_throwIfNestedNonStatic() {
-        IllegalAnnotationTargetException exception = assertThrows(IllegalAnnotationTargetException.class, () -> resolve(new ContainerNestingContainerWithEntry()));
+        IllegalAnnotationTargetException exception = assertThrows(IllegalAnnotationTargetException.class, () -> baseCollection.resolve(new ContainerNestingContainerWithEntry()));
         assertEquals("Transitive " + ContainerNestingContainerWithEntry.ContainerWithEntry.class + " must be static", exception.getMessage());
     }
 
     @Test
     public void resolve_logWarningIfEmpty() {
-        resolve(new EmptyGroup());
+        baseCollection.resolve(new EmptyGroup());
         assertThat(logCaptor.getWarnLogs()).contains("[CompleteConfig] Group emptyGroup is empty");
     }
 
     @Test
     public void resolve_listenSetter() {
         SetterListener listener = new SetterListener();
-        resolve(listener);
+        baseCollection.resolve(listener);
         boolean value = !listener.getValue();
         Iterables.getOnlyElement(baseCollection.getEntries()).setValue(value);
         assertEquals(value, listener.getValue());
@@ -131,7 +125,7 @@ public class BaseCollectionTest {
     @Test
     public void resolve_doNotUpdateListenerField() {
         EmptyListener listener = new EmptyListener();
-        resolve(listener);
+        baseCollection.resolve(listener);
         boolean oldValue = listener.getValue();
         Iterables.getOnlyElement(baseCollection.getEntries()).setValue(!oldValue);
         assertEquals(oldValue, listener.getValue());