Skip to content

Commit

Permalink
fix missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Sep 12, 2024
1 parent 604560c commit 9a65672
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 146 deletions.
4 changes: 4 additions & 0 deletions api/src/main/java/com/github/skjolber/packing/api/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public Box clone() {
}
return new Box(id, description, volume, weight, stackValues);
}

public StackValue getStackValue(int index) {
return stackValues[index];
}

@Override
public long getMinimumArea() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public ContainerStackValue[] getStackValues() {
public Stack getStack() {
return stack;
}

public ContainerStackValue getStackValue(int index) {
return stackValues[index];
}

@Override
public DefaultContainer clone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public List<StackValue> fitsInside(Dimension bound) {

return list;
}

public abstract StackValue getStackValue(int index);

@Override
public abstract Stackable clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class StackableItem implements Serializable {

private static final long serialVersionUID = 1L;

private final int count;
private final Stackable stackable;
protected int count;
protected final Stackable stackable;

public StackableItem(Stackable box) {
this(box, 1);
Expand All @@ -36,5 +36,18 @@ public Stackable getStackable() {
public String toString() {
return String.format("%dx%s", count, stackable);
}

public void decrement() {
count--;
}

public boolean isEmpty() {
return count == 0;
}

public void decrement(int value) {
this.count = this.count - value;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public class StackableItemGroup {

private List<StackableItem> items;

public StackableItemGroup(String id, List<StackableItem> items) {
super();
this.id = id;
this.items = items;
}

public String getId() {
return id;
}
Expand All @@ -37,4 +43,33 @@ public int size() {
public StackableItem get(int i) {
return items.get(i);
}

public int loadableItemsCount() {
int count = 0;
for (StackableItem loadableItem : items) {
count += loadableItem.getCount();
}
return count;
}

public boolean isEmpty() {
for (StackableItem loadableItem : items) {
if(!loadableItem.isEmpty()) {
return false;
}
}

return true;
}

public void removeEmpty() {
for (int j = 0; j < items.size(); j++) {
StackableItem loadableItem = items.get(j);

if(loadableItem.isEmpty()) {
items.remove(j);
j--;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.skjolber.packing.api.packager;

import java.util.List;

import com.github.skjolber.packing.api.StackValue;
import com.github.skjolber.packing.api.Stackable;

Expand Down Expand Up @@ -27,6 +29,10 @@ public BoundedStackable(Stackable stackable, StackValue[] stackValues) {
this.maximumArea = getMinimumArea(stackValues);
}

public BoundedStackable(Stackable stackable, List<StackValue> stackValues) {
this(stackable, stackValues.toArray(new StackValue[stackValues.size()]));
}

public Stackable getStackable() {
return stackable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import com.github.skjolber.packing.api.StackableItem;
import com.github.skjolber.packing.api.StackableItemGroup;
import com.github.skjolber.packing.api.packager.BoundedStackable;
import com.github.skjolber.packing.api.packager.BoundedStackableItem;
import com.github.skjolber.packing.api.packager.BoundedStackableItemGroup;

/**
* Builder scaffold.
Expand Down Expand Up @@ -57,16 +55,16 @@ public B withStackableItemGroups(List<StackableItemGroup> stackableItems) {
return (B)this;
}

protected List<BoundedStackableItemGroup> toMatrix() {
List<BoundedStackableItemGroup> results = new ArrayList<>(stackableItemGroups.size());
protected List<StackableItemGroup> toMatrix() {
List<StackableItemGroup> results = new ArrayList<>(stackableItemGroups.size());

int offset = 0;

for (int i = 0; i < stackableItemGroups.size(); i++) {

StackableItemGroup group = stackableItemGroups.get(i);

List<BoundedStackableItem> loadableItems = new ArrayList<>(group.size());
List<StackableItem> loadableItems = new ArrayList<>(group.size());
for (int k = 0; k < group.size(); k++) {
StackableItem item = group.get(k);

Expand Down Expand Up @@ -94,12 +92,12 @@ protected List<BoundedStackableItemGroup> toMatrix() {

BoundedStackable loadable = new BoundedStackable(stackable, boundRotations);

loadableItems.add(new BoundedStackableItem(loadable, item.getCount(), offset));
loadableItems.add(new IndexedStackableItem(loadable, item.getCount(), offset));

offset++;
}
if(!loadableItems.isEmpty()) {
results.add(new BoundedStackableItemGroup(group.getId(), loadableItems));
results.add(new StackableItemGroup(group.getId(), loadableItems));
}
}
return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.github.skjolber.packing.api.Stackable;
import com.github.skjolber.packing.api.StackableItem;
import com.github.skjolber.packing.api.packager.BoundedStackable;
import com.github.skjolber.packing.api.packager.BoundedStackableItem;
import com.github.skjolber.packing.api.packager.StackableItems;

/**
Expand Down Expand Up @@ -55,8 +54,8 @@ public B withStackableItems(List<StackableItem> stackableItems) {
return (B)this;
}

protected BoundedStackableItem[] toMatrix() {
BoundedStackableItem[] results = new BoundedStackableItem[stackableItems.size()];
protected IndexedStackableItem[] toMatrix() {
IndexedStackableItem[] results = new IndexedStackableItem[stackableItems.size()];

for (int i = 0; i < stackableItems.size(); i++) {
StackableItem item = stackableItems.get(i);
Expand Down Expand Up @@ -85,7 +84,7 @@ protected BoundedStackableItem[] toMatrix() {

BoundedStackable loadable = new BoundedStackable(stackable, boundRotations);

results[i] = new BoundedStackableItem(loadable, item.getCount(), i);
results[i] = new IndexedStackableItem(loadable, item.getCount(), i);
}
return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@

import com.github.skjolber.packing.api.StackValue;
import com.github.skjolber.packing.api.StackableItem;
import com.github.skjolber.packing.api.packager.BoundedStackableItem;

public abstract class AbstractLoadablePermutationRotationIterator implements LoadableItemPermutationRotationIterator {

protected final BoundedStackableItem[] loadableItems; // by index
protected final IndexedStackableItem[] loadableItems; // by index
protected int[] reset;

public AbstractLoadablePermutationRotationIterator(BoundedStackableItem[] matrix) {
public AbstractLoadablePermutationRotationIterator(IndexedStackableItem[] matrix) {
this.loadableItems = matrix;
}

public BoundedStackableItem[] getMatrix() {
public IndexedStackableItem[] getMatrix() {
return loadableItems;
}

Expand Down Expand Up @@ -63,7 +62,7 @@ public List<StackValue> get(PermutationRotationState state, int length) {

List<StackValue> results = new ArrayList<StackValue>(length);
for (int i = 0; i < length; i++) {
results.add(loadableItems[permutations[i]].getLoadable().getStackValue(rotations[i]));
results.add(loadableItems[permutations[i]].getStackable().getStackValue(rotations[i]));
}
return results;
}
Expand Down
Loading

0 comments on commit 9a65672

Please sign in to comment.