[*] Generalize the entry system by introducing "structured entries"
This commit is contained in:
@@ -4,14 +4,11 @@ import de.siphalor.tweed5.construct.api.ConstructParameter;
|
||||
import de.siphalor.tweed5.core.api.container.ConfigContainer;
|
||||
import de.siphalor.tweed5.core.api.entry.BaseConfigEntry;
|
||||
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
||||
import de.siphalor.tweed5.core.api.entry.ConfigEntryValueVisitor;
|
||||
import de.siphalor.tweed5.core.api.entry.ConfigEntryVisitor;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCollectionConfigEntry;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.IntFunction;
|
||||
@@ -21,7 +18,7 @@ import java.util.function.IntFunction;
|
||||
@ToString(callSuper = true)
|
||||
public class CollectionConfigEntryImpl<E, T extends Collection<E>> extends BaseConfigEntry<T> implements WeavableCollectionConfigEntry<E, T> {
|
||||
private final IntFunction<T> constructor;
|
||||
private final @Nullable ConfigEntry<E> elementEntry;
|
||||
private final ConfigEntry<E> elementEntry;
|
||||
|
||||
public CollectionConfigEntryImpl(
|
||||
ConfigContainer<?> configContainer,
|
||||
@@ -43,24 +40,6 @@ public class CollectionConfigEntryImpl<E, T extends Collection<E>> extends BaseC
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInOrder(ConfigEntryVisitor visitor) {
|
||||
if (visitor.enterCollectionEntry(this)) {
|
||||
elementEntry.visitInOrder(visitor);
|
||||
visitor.leaveCollectionEntry(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInOrder(ConfigEntryValueVisitor visitor, T value) {
|
||||
if (visitor.enterCollectionEntry(this, value)) {
|
||||
for (E element : value) {
|
||||
elementEntry.visitInOrder(visitor, element);
|
||||
}
|
||||
visitor.leaveCollectionEntry(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull T deepCopy(T value) {
|
||||
T copy = instantiateCollection(value.size());
|
||||
|
||||
@@ -86,22 +86,22 @@ public class StaticPojoCompoundConfigEntry<T> extends BaseConfigEntry<T> impleme
|
||||
|
||||
@Override
|
||||
public void visitInOrder(ConfigEntryVisitor visitor) {
|
||||
if (visitor.enterCompoundEntry(this)) {
|
||||
if (visitor.enterStructuredEntry(this)) {
|
||||
subConfigEntries.forEach((key, entry) -> {
|
||||
if (visitor.enterCompoundSubEntry(key)) {
|
||||
if (visitor.enterStructuredSubEntry(key)) {
|
||||
entry.visitInOrder(visitor);
|
||||
visitor.leaveCompoundSubEntry(key);
|
||||
visitor.leaveStructuredSubEntry(key);
|
||||
}
|
||||
});
|
||||
visitor.leaveCompoundEntry(this);
|
||||
visitor.leaveStructuredEntry(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInOrder(ConfigEntryValueVisitor visitor, @Nullable T value) {
|
||||
if (visitor.enterCompoundEntry(this, value)) {
|
||||
if (visitor.enterStructuredEntry(this, value)) {
|
||||
subEntries.forEach((key, entry) -> {
|
||||
if (visitor.enterCompoundSubEntry(key)) {
|
||||
if (visitor.enterStructuredSubEntry(key, key)) {
|
||||
try {
|
||||
Object subValue = entry.getter().invoke(value);
|
||||
//noinspection unchecked
|
||||
|
||||
Reference in New Issue
Block a user