Skip to content

Commit

Permalink
Remove generics, various prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Aug 14, 2024
1 parent 6839759 commit 805e3df
Show file tree
Hide file tree
Showing 105 changed files with 1,844 additions and 2,824 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.skjolber.packing.api;

import java.util.List;

public abstract class AbstractStackScopeConstraintBuilder<B extends AbstractStackScopeConstraintBuilder<B>> {

protected List<Stackable> stackables;
protected Container container;
protected ContainerStackValue containerStackValue;
protected Stack stack;

public B withContainer(Container container) {
this.container = container;
return (B)this;
}

public B withStack(Stack stack) {
this.stack = stack;
return (B)this;
}

public B withContainerStackValue(ContainerStackValue containerStackValue) {
this.containerStackValue = containerStackValue;
return (B)this;
}

public B withStackables(List<Stackable> stackables) {
this.stackables = stackables;
return (B)this;
}

public abstract StackScopeConstraint build();
}
8 changes: 8 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 @@ -60,6 +60,10 @@ public Box(String id, String name, long volume, int weight, BoxStackValue[] stac

this.minimumArea = getMinimumArea(stackValues);
this.maximumArea = getMinimumArea(stackValues);

for (BoxStackValue boxStackValue : stackValues) {
boxStackValue.setStackable(this);
}
}

@Override
Expand All @@ -78,6 +82,10 @@ public long getVolume() {

@Override
public Box clone() {
BoxStackValue[] stackValues = new BoxStackValue[this.stackValues.length];
for(int i = 0; i < stackValues.length; i++) {
stackValues[i] = this.stackValues[i].clone();
}
return new Box(id, description, volume, weight, stackValues);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@
public class BoxStackValue extends StackValue {

private static final long serialVersionUID = 1L;

private Box stackable;

public BoxStackValue(int dx, int dy, int dz, StackConstraint constraint, List<Surface> surfaces) {
super(dx, dy, dz, constraint, surfaces);
}

public BoxStackValue(BoxStackValue boxStackValue) {
super(boxStackValue);

this.stackable = boxStackValue.stackable;
}

@Override
public BoxStackValue clone() {
return new BoxStackValue(this);
}

public void setStackable(Box stackable) {
this.stackable = stackable;
}

@Override
public Box getStackable() {
return stackable;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.skjolber.packing.api;

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

/**
*
* A {@linkplain Stackable} in a specific {@linkplain StackValue}.
*
*/

public class ContainerLoadStackValue {

private final Stackable stackable;
private final StackValue value;

public ContainerLoadStackValue(Stackable stackable, StackValue value) {
super();
this.stackable = stackable;
this.value = value;
}

public Stackable getStackable() {
return stackable;
}

public StackValue getValue() {
return value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.github.skjolber.packing.api;

import java.util.List;

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

public class ContainerLoadable {

protected final ContainerLoadStackValue[] values;
protected final Stackable stackable;

protected final long minVolumeLimit;
protected final long minAreaLimit;

public ContainerLoadable(Stackable stackable, List<StackValue> stackValues) {
this.values = new ContainerLoadStackValue[stackValues.size()];
this.stackable = stackable;

long minVolumeLimit = Long.MAX_VALUE;
long minAreaLimit = Long.MAX_VALUE;

for (int i = 0; i < values.length; i++) {
StackValue stackValue = stackValues.get(i);

values[i] = new ContainerLoadStackValue(stackable, stackValue);

if(minVolumeLimit > stackValue.getVolume()) {
minVolumeLimit = stackValue.getVolume();
}

if(minAreaLimit > stackValue.getArea()) {
minAreaLimit = stackValue.getArea();
}
}

this.minAreaLimit = minAreaLimit;
this.minVolumeLimit = minVolumeLimit;
}

public ContainerLoadable(ContainerLoadable clone) {
// clone working object in order to improve performance
this.values = new ContainerLoadStackValue[clone.values.length];
this.stackable = clone.stackable.clone();
for (int i = 0; i < values.length; i++) {
ContainerLoadStackValue permutationRotation = clone.values[i];
values[i] = new ContainerLoadStackValue(permutationRotation.getStackable().clone(), permutationRotation.getValue().clone());

}
this.minAreaLimit = clone.minAreaLimit;
this.minVolumeLimit = clone.minVolumeLimit;

}

public ContainerLoadStackValue[] getBoxes() {
return values;
}

public long getMinAreaLimit() {
return minAreaLimit;
}

public long getMinVolumeLimit() {
return minVolumeLimit;
}

public Stackable getStackable() {
return stackable;
}

public ContainerLoadable clone() {
return new ContainerLoadable(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ public abstract class ContainerStackValue extends StackValue {

private static final long serialVersionUID = 1L;

private Container stackable;

protected final int loadDx; // x
protected final int loadDy; // y
protected final int loadDz; // z

protected final int maxLoadWeight;
protected final long maxLoadVolume;

public ContainerStackValue(
int dx, int dy, int dz,
StackConstraint constraint,
Expand All @@ -19,14 +28,7 @@ public ContainerStackValue(
this.maxLoadVolume = (long)loadDx * (long)loadDy * (long)loadDz;
this.maxLoadWeight = maxLoadWeight;
}

protected final int loadDx; // x
protected final int loadDy; // y
protected final int loadDz; // z

protected final int maxLoadWeight;
protected final long maxLoadVolume;


protected ContainerStackValue(ContainerStackValue other) {
super(other);

Expand All @@ -36,6 +38,8 @@ protected ContainerStackValue(ContainerStackValue other) {

this.maxLoadVolume = other.maxLoadVolume;
this.maxLoadWeight = other.maxLoadWeight;

this.stackable = other.stackable;
}

public long getMaxLoadVolume() {
Expand Down Expand Up @@ -78,5 +82,17 @@ protected boolean canLoad(Stackable stackable) {
public String toString() {
return "ContainerStackValue [" + dx + "x" + dy + "x" + dz + " " + loadDx + "x" + loadDy + "x" + loadDz + "]";
}

public void setStackable(Container stackable) {
this.stackable = stackable;
}

@Override
public Container getStackable() {
return stackable;
}

@Override
public abstract ContainerStackValue clone();

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public DefaultContainer(String id, String description, long volume, int emptyWei

this.stackValues = stackValues;
this.stack = stack;

for (ContainerStackValue stackValue : stackValues) {
stackValue.setStackable(this);
}
}

@Override
Expand All @@ -28,6 +32,10 @@ public Stack getStack() {

@Override
public DefaultContainer clone() {
ContainerStackValue[] stackValues = new ContainerStackValue[this.stackValues.length];
for(int i = 0; i < stackValues.length; i++) {
stackValues[i] = this.stackValues[i].clone();
}
return new DefaultContainer(id, description, volume, emptyWeight, stackValues, new DefaultStack());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class DefaultContainerStackValue extends ContainerStackValue {

private static final long serialVersionUID = 1L;

public DefaultContainerStackValue(
int dx, int dy, int dz,
StackConstraint constraint,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.skjolber.packing.api;

import java.util.List;

public class DefaultStackScopeConstraint implements StackScopeConstraint {

protected final List<Stackable> stackables;
protected final Container container;
protected final ContainerStackValue containerStackValue;
protected final Stack stack;

public DefaultStackScopeConstraint(List<Stackable> stackables, Container container, ContainerStackValue containerStackValue, Stack stack) {
this.stackables = stackables;
this.container = container;
this.containerStackValue = containerStackValue;
this.stack = stack;
}

@Override
public List<Stackable> getStackScope() {
return stackables;
}

@Override
public void stacked(int index) {
stackables.remove(index);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.skjolber.packing.api;

public class DefaultStackScopeConstraintBuilder extends AbstractStackScopeConstraintBuilder<DefaultStackScopeConstraintBuilder> {

@Override
public StackScopeConstraint build() {
return new DefaultStackScopeConstraint(stackables, container, containerStackValue, stack);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.skjolber.packing.api;

import java.util.List;

public interface FixedOrderStackScopeConstraint {

List<Stackable> getStackScope();

void stacked(int index);

}

This file was deleted.

14 changes: 0 additions & 14 deletions api/src/main/java/com/github/skjolber/packing/api/Placement2D.java

This file was deleted.

11 changes: 0 additions & 11 deletions api/src/main/java/com/github/skjolber/packing/api/Placement3D.java

This file was deleted.

Loading

0 comments on commit 805e3df

Please sign in to comment.