From a65c3e3991f91b32b69c623494829e6989109798 Mon Sep 17 00:00:00 2001 From: "natan.nascimento" Date: Sun, 10 Dec 2023 17:47:50 -0300 Subject: [PATCH] Delete ComponentFactory from API --- .../component/ComponentFactory.java | 17 ----------------- .../inventoryframework/internal/LayoutSlot.java | 10 +++++----- .../component/PaginationImpl.java | 9 +++------ .../pipeline/LayoutRenderInterceptor.java | 8 ++++---- .../context/PlatformRenderContext.java | 5 ++--- 5 files changed, 14 insertions(+), 35 deletions(-) delete mode 100644 inventory-framework-api/src/main/java/me/devnatan/inventoryframework/component/ComponentFactory.java diff --git a/inventory-framework-api/src/main/java/me/devnatan/inventoryframework/component/ComponentFactory.java b/inventory-framework-api/src/main/java/me/devnatan/inventoryframework/component/ComponentFactory.java deleted file mode 100644 index 098ea0744..000000000 --- a/inventory-framework-api/src/main/java/me/devnatan/inventoryframework/component/ComponentFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -package me.devnatan.inventoryframework.component; - -import org.jetbrains.annotations.NotNull; - -/** - * Factory for {@link Component} interface. - */ -public interface ComponentFactory { - - /** - * Creates a new component. - * - * @return A new component instance. - */ - @NotNull - Component create(); -} diff --git a/inventory-framework-api/src/main/java/me/devnatan/inventoryframework/internal/LayoutSlot.java b/inventory-framework-api/src/main/java/me/devnatan/inventoryframework/internal/LayoutSlot.java index 00a384295..15ef8bce3 100644 --- a/inventory-framework-api/src/main/java/me/devnatan/inventoryframework/internal/LayoutSlot.java +++ b/inventory-framework-api/src/main/java/me/devnatan/inventoryframework/internal/LayoutSlot.java @@ -3,7 +3,7 @@ import java.util.Arrays; import java.util.Objects; import java.util.function.IntFunction; -import me.devnatan.inventoryframework.component.ComponentFactory; +import me.devnatan.inventoryframework.component.ComponentBuilder; import org.jetbrains.annotations.Nullable; public final class LayoutSlot { @@ -11,10 +11,10 @@ public final class LayoutSlot { public static final char DEFAULT_SLOT_FILL_CHAR = 'O'; private final char character; - private final IntFunction factory; + private final IntFunction factory; private final int[] positions; - public LayoutSlot(char character, @Nullable IntFunction factory, int[] positions) { + public LayoutSlot(char character, @Nullable IntFunction factory, int[] positions) { this.character = character; this.factory = factory; this.positions = positions; @@ -24,11 +24,11 @@ public char getCharacter() { return character; } - public IntFunction getFactory() { + public IntFunction getFactory() { return factory; } - public LayoutSlot withFactory(@Nullable IntFunction factory) { + public LayoutSlot withFactory(@Nullable IntFunction factory) { return new LayoutSlot(character, factory, positions); } diff --git a/inventory-framework-core/src/main/java/me/devnatan/inventoryframework/component/PaginationImpl.java b/inventory-framework-core/src/main/java/me/devnatan/inventoryframework/component/PaginationImpl.java index 343721fa9..0030beffe 100644 --- a/inventory-framework-core/src/main/java/me/devnatan/inventoryframework/component/PaginationImpl.java +++ b/inventory-framework-core/src/main/java/me/devnatan/inventoryframework/component/PaginationImpl.java @@ -34,10 +34,6 @@ @VisibleForTesting public class PaginationImpl extends AbstractComponent implements Pagination, StateValue { - { - setHandle(new Handle(this)); - } - private List components = new ArrayList<>(); // --- User provided --- @@ -86,6 +82,7 @@ public PaginationImpl( boolean isAsync, boolean isComputed) { super(key, root, reference, watchingStates, displayCondition); + setHandle(new Handle(this)); this.internalStateId = internalStateId; this.layoutTarget = layoutTarget; this.sourceProvider = sourceProvider; @@ -649,7 +646,7 @@ public boolean equals(Object o) { PaginationImpl that = (PaginationImpl) o; return getLayoutTarget() == that.getLayoutTarget() && currPageIndex == that.currPageIndex - && getPageSize() == that.getPageSize() + && pageSize == that.pageSize && isLazy() == that.isLazy() && pageWasChanged == that.pageWasChanged && Objects.equals(sourceProvider, that.sourceProvider) @@ -663,7 +660,7 @@ public int hashCode() { sourceProvider, pageSwitchHandler, currPageIndex, - getPageSize(), + pageSize, isLazy(), pageWasChanged); } diff --git a/inventory-framework-core/src/main/java/me/devnatan/inventoryframework/pipeline/LayoutRenderInterceptor.java b/inventory-framework-core/src/main/java/me/devnatan/inventoryframework/pipeline/LayoutRenderInterceptor.java index 6ef8a2525..aad08f8c6 100644 --- a/inventory-framework-core/src/main/java/me/devnatan/inventoryframework/pipeline/LayoutRenderInterceptor.java +++ b/inventory-framework-core/src/main/java/me/devnatan/inventoryframework/pipeline/LayoutRenderInterceptor.java @@ -4,7 +4,7 @@ import me.devnatan.inventoryframework.InventoryFrameworkException; import me.devnatan.inventoryframework.VirtualView; import me.devnatan.inventoryframework.component.Component; -import me.devnatan.inventoryframework.component.ComponentFactory; +import me.devnatan.inventoryframework.component.ComponentBuilder; import me.devnatan.inventoryframework.component.ItemComponentBuilder; import me.devnatan.inventoryframework.context.IFRenderContext; import me.devnatan.inventoryframework.internal.LayoutSlot; @@ -17,7 +17,7 @@ public void intercept(PipelineContext pipeline, VirtualView subject final IFRenderContext renderContext = (IFRenderContext) subject; for (final LayoutSlot layoutSlot : renderContext.getLayoutSlots()) { - final IntFunction factory = layoutSlot.getFactory(); + final IntFunction factory = layoutSlot.getFactory(); if (factory == null) { if (layoutSlot.isDefinedByTheUser()) throw new InventoryFrameworkException( @@ -27,11 +27,11 @@ public void intercept(PipelineContext pipeline, VirtualView subject int iterationIndex = 0; for (final int slot : layoutSlot.getPositions()) { - final ComponentFactory componentFactory = factory.apply(iterationIndex++); + final ComponentBuilder componentFactory = factory.apply(iterationIndex++); if (componentFactory instanceof ItemComponentBuilder) ((ItemComponentBuilder) componentFactory).setPosition(slot); - final Component component = componentFactory.create(); + final Component component = componentFactory.buildComponent(renderContext); renderContext.addComponent(component); } } diff --git a/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/context/PlatformRenderContext.java b/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/context/PlatformRenderContext.java index 1520cb0a8..6ded2b1e7 100644 --- a/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/context/PlatformRenderContext.java +++ b/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/context/PlatformRenderContext.java @@ -21,7 +21,6 @@ import me.devnatan.inventoryframework.component.AbstractComponentHandle; import me.devnatan.inventoryframework.component.Component; import me.devnatan.inventoryframework.component.ComponentBuilder; -import me.devnatan.inventoryframework.component.ComponentFactory; import me.devnatan.inventoryframework.component.ItemComponentBuilder; import me.devnatan.inventoryframework.component.PlatformComponentBuilder; import me.devnatan.inventoryframework.internal.LayoutSlot; @@ -196,7 +195,7 @@ public final void availableSlot(@NotNull BiConsumer facto .orElseThrow(() -> new InventoryFrameworkException("Missing layout character: " + character)); final ITEM_BUILDER builder = createBuilder(); - getLayoutSlots().add(layoutSlot.withFactory($ -> (ComponentFactory) builder)); + getLayoutSlots().add(layoutSlot.withFactory($ -> builder)); return builder; } @@ -219,7 +218,7 @@ public final void layoutSlot(char character, @NotNull BiConsumer { final ITEM_BUILDER builder = createBuilder(); factory.accept(index, builder); - return (ComponentFactory) builder; + return builder; })); }