From 1fc2fa262d8f5a01685c628e1e5785f729cd8704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Skj=C3=B8lberg?= Date: Sun, 1 Sep 2024 14:49:41 +0200 Subject: [PATCH] Adjust filtering --- .../skjolber/packing/api/ContainerConstraint.java | 4 ++-- .../api/packager/DefaultLoadableItemFilter.java | 13 +++---------- .../skjolber/packing/api/packager/LoadableItem.java | 4 +++- .../packing/api/packager/LoadableItemFilter.java | 9 +++------ ...rBuilder.java => LoadableItemFilterBuilder.java} | 6 +++--- .../packing/api/packager/LoadableItems.java | 13 +++++++++++++ 6 files changed, 27 insertions(+), 22 deletions(-) rename api/src/main/java/com/github/skjolber/packing/api/packager/{LoadableFilterBuilder.java => LoadableItemFilterBuilder.java} (83%) create mode 100644 api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItems.java diff --git a/api/src/main/java/com/github/skjolber/packing/api/ContainerConstraint.java b/api/src/main/java/com/github/skjolber/packing/api/ContainerConstraint.java index c6c67d45..c11a04c1 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/ContainerConstraint.java +++ b/api/src/main/java/com/github/skjolber/packing/api/ContainerConstraint.java @@ -1,6 +1,6 @@ package com.github.skjolber.packing.api; -import com.github.skjolber.packing.api.packager.LoadableFilterBuilder; +import com.github.skjolber.packing.api.packager.LoadableItemFilterBuilder; /** * @@ -10,6 +10,6 @@ public interface ContainerConstraint { - LoadableFilterBuilder newLoadableFilterBuilder(); + LoadableItemFilterBuilder newLoadableFilterBuilder(); } diff --git a/api/src/main/java/com/github/skjolber/packing/api/packager/DefaultLoadableItemFilter.java b/api/src/main/java/com/github/skjolber/packing/api/packager/DefaultLoadableItemFilter.java index 2c075055..9e9d0283 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/packager/DefaultLoadableItemFilter.java +++ b/api/src/main/java/com/github/skjolber/packing/api/packager/DefaultLoadableItemFilter.java @@ -1,27 +1,20 @@ package com.github.skjolber.packing.api.packager; -import java.util.List; public class DefaultLoadableItemFilter implements LoadableItemFilter { - protected final List loadableItems; + protected final LoadableItems loadableItems; - public DefaultLoadableItemFilter(List loadableItems) { + public DefaultLoadableItemFilter(LoadableItems loadableItems) { this.loadableItems = loadableItems; } @Override - public List getLoadableItems() { - return loadableItems; - } - - @Override - public boolean loaded(int index) { + public void loaded(int index) { LoadableItem loadableItem = loadableItems.get(index); loadableItem.decrement(); if(loadableItem.isEmpty()) { loadableItems.remove(index); } - return false; } } \ No newline at end of file diff --git a/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItem.java b/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItem.java index 5d08fc8d..08faa6fb 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItem.java +++ b/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItem.java @@ -10,10 +10,12 @@ public class LoadableItem { protected Loadable loadable; protected int count; + protected int index; - public LoadableItem(Loadable loadable, int count) { + public LoadableItem(Loadable loadable, int count, int index) { this.loadable = loadable; this.count = count; + this.index = index; } public Loadable getLoadable() { diff --git a/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItemFilter.java b/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItemFilter.java index 19e829f4..70d98d34 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItemFilter.java +++ b/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItemFilter.java @@ -1,7 +1,5 @@ package com.github.skjolber.packing.api.packager; -import java.util.List; - /** * * The items which are available for load into some particular container. @@ -10,15 +8,14 @@ public interface LoadableItemFilter { - List getLoadableItems(); - /** * - * Notify stackable from item was loaded + * Notify loadable was loaded * * @param index * @return true if some loadable item was excluded due to this loaded item */ - boolean loaded(int index); + void loaded(int index); + } diff --git a/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableFilterBuilder.java b/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItemFilterBuilder.java similarity index 83% rename from api/src/main/java/com/github/skjolber/packing/api/packager/LoadableFilterBuilder.java rename to api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItemFilterBuilder.java index 18c3f90e..f86c668c 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableFilterBuilder.java +++ b/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItemFilterBuilder.java @@ -14,14 +14,14 @@ */ @SuppressWarnings("unchecked") -public abstract class LoadableFilterBuilder> { +public abstract class LoadableItemFilterBuilder> { protected Stack stack; protected Container container; protected ContainerStackValue stackValue; - protected List loadableItems; + protected LoadableItems loadableItems; - public B withLoadableItems(List loadableItems) { + public B withLoadableItems(LoadableItems loadableItems) { this.loadableItems = loadableItems; return (B)this; } diff --git a/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItems.java b/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItems.java new file mode 100644 index 00000000..3c4a78f1 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItems.java @@ -0,0 +1,13 @@ +package com.github.skjolber.packing.api.packager; + +import java.util.List; + +/** + * + * The items which are available for load into some particular container. + * + */ + +public interface LoadableItems extends List{ + +}