Skip to content

Commit

Permalink
Adjust filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Sep 1, 2024
1 parent 0de73c9 commit 1fc2fa2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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;

/**
*
Expand All @@ -10,6 +10,6 @@

public interface ContainerConstraint {

LoadableFilterBuilder<?> newLoadableFilterBuilder();
LoadableItemFilterBuilder<?> newLoadableFilterBuilder();

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
package com.github.skjolber.packing.api.packager;
import java.util.List;

public class DefaultLoadableItemFilter implements LoadableItemFilter {

protected final List<LoadableItem> loadableItems;
protected final LoadableItems loadableItems;

public DefaultLoadableItemFilter(List<LoadableItem> loadableItems) {
public DefaultLoadableItemFilter(LoadableItems loadableItems) {
this.loadableItems = loadableItems;
}

@Override
public List<LoadableItem> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -10,15 +8,14 @@

public interface LoadableItemFilter {

List<LoadableItem> 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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
*/

@SuppressWarnings("unchecked")
public abstract class LoadableFilterBuilder<B extends LoadableFilterBuilder<B>> {
public abstract class LoadableItemFilterBuilder<B extends LoadableItemFilterBuilder<B>> {

protected Stack stack;
protected Container container;
protected ContainerStackValue stackValue;
protected List<LoadableItem> loadableItems;
protected LoadableItems loadableItems;

public B withLoadableItems(List<LoadableItem> loadableItems) {
public B withLoadableItems(LoadableItems loadableItems) {
this.loadableItems = loadableItems;
return (B)this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<LoadableItem>{

}

0 comments on commit 1fc2fa2

Please sign in to comment.