Skip to content

Commit

Permalink
Delete ComponentFactory from API
Browse files Browse the repository at this point in the history
  • Loading branch information
DevNatan committed Dec 10, 2023
1 parent 95ac7df commit 782a6fe
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 35 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
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 {

public static final char DEFAULT_SLOT_FILL_CHAR = 'O';

private final char character;
private final IntFunction<ComponentFactory> factory;
private final IntFunction<ComponentBuilder> factory;
private final int[] positions;

public LayoutSlot(char character, @Nullable IntFunction<ComponentFactory> factory, int[] positions) {
public LayoutSlot(char character, @Nullable IntFunction<ComponentBuilder> factory, int[] positions) {
this.character = character;
this.factory = factory;
this.positions = positions;
Expand All @@ -24,11 +24,11 @@ public char getCharacter() {
return character;
}

public IntFunction<ComponentFactory> getFactory() {
public IntFunction<ComponentBuilder> getFactory() {
return factory;
}

public LayoutSlot withFactory(@Nullable IntFunction<ComponentFactory> factory) {
public LayoutSlot withFactory(@Nullable IntFunction<ComponentBuilder> factory) {
return new LayoutSlot(character, factory, positions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
@VisibleForTesting
public class PaginationImpl extends AbstractComponent implements Pagination, StateValue {

{
setHandle(new Handle(this));
}

private List<Component> components = new ArrayList<>();

// --- User provided ---
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -663,7 +660,7 @@ public int hashCode() {
sourceProvider,
pageSwitchHandler,
currPageIndex,
getPageSize(),
pageSize,
isLazy(),
pageWasChanged);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +17,7 @@ public void intercept(PipelineContext<VirtualView> pipeline, VirtualView subject

final IFRenderContext renderContext = (IFRenderContext) subject;
for (final LayoutSlot layoutSlot : renderContext.getLayoutSlots()) {
final IntFunction<ComponentFactory> factory = layoutSlot.getFactory();
final IntFunction<ComponentBuilder> factory = layoutSlot.getFactory();
if (factory == null) {
if (layoutSlot.isDefinedByTheUser())
throw new InventoryFrameworkException(
Expand All @@ -27,11 +27,11 @@ public void intercept(PipelineContext<VirtualView> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -196,7 +195,7 @@ public final void availableSlot(@NotNull BiConsumer<Integer, ITEM_BUILDER> 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;
}

Expand All @@ -219,7 +218,7 @@ public final void layoutSlot(char character, @NotNull BiConsumer<Integer, ITEM_B
getLayoutSlots().add(layoutSlot.withFactory(index -> {
final ITEM_BUILDER builder = createBuilder();
factory.accept(index, builder);
return (ComponentFactory) builder;
return builder;
}));
}

Expand Down

0 comments on commit 782a6fe

Please sign in to comment.