Skip to content

Commit

Permalink
various prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Aug 30, 2024
1 parent 58a0aa1 commit 0de73c9
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.skjolber.packing.api;

import com.github.skjolber.packing.api.packager.LoadableFilterBuilder;

/**
*
* Interface for handling which Stackables, or combinations of Stackables go into a Container.
*
*/

public interface ContainerConstraint {

LoadableFilterBuilder<?> newLoadableFilterBuilder();

}

This file was deleted.

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

public interface GravitySupport {

void update(StackPlacement stackPlacement);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.skjolber.packing.api;

/**
* Builder scaffold.
*
* @see <a href=
* "https://www.sitepoint.com/self-types-with-javas-generics/">https://www.sitepoint.com/self-types-with-javas-generics/</a>
*/

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

protected Container container;
protected ContainerStackValue stackValue;
protected Stack stack;
protected StackPlacement stackPlacement;

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

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

public B withStackValue(ContainerStackValue stackValue) {
this.stackValue = stackValue;
return (B)this;
}

public abstract GravitySupport build();



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

public interface StackValueConstraint {

GravitySupportBuilder<?> newGravitySupportBuilder();

}

This file was deleted.

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

public class DefaultLoadableItemScope implements LoadableItemScope {
public class DefaultLoadableItemFilter implements LoadableItemFilter {

protected final List<LoadableItem> loadableItems;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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;

/**
*
* Stackable item which fit within certain bounds, i.e. load dimensions of a container.
*
*/

public class Loadable {

protected final List<StackValue> values;
protected final Stackable stackable;

protected final long minVolumeLimit;
protected final long minAreaLimit;

public Loadable(Stackable stackable, List<StackValue> stackValues, int count) {
this.values = stackValues;
this.stackable = stackable;

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

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

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

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

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

public List<StackValue> getValues() {
return values;
}

public long getMinAreaLimit() {
return minAreaLimit;
}

public long getMinVolumeLimit() {
return minVolumeLimit;
}

public Stackable getStackable() {
return stackable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.github.skjolber.packing.api.packager;

import java.util.List;

import com.github.skjolber.packing.api.Container;
import com.github.skjolber.packing.api.ContainerStackValue;
import com.github.skjolber.packing.api.Stack;

/**
* Builder scaffold.
*
* @see <a href=
* "https://www.sitepoint.com/self-types-with-javas-generics/">https://www.sitepoint.com/self-types-with-javas-generics/</a>
*/

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

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

public B withLoadableItems(List<LoadableItem> loadableItems) {
this.loadableItems = loadableItems;
return (B)this;
}

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

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

public B withStackValue(ContainerStackValue stackValue) {
this.stackValue = stackValue;
return (B)this;
}

public abstract LoadableItemFilter build();



}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
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;

/**
*
* Stackable item which fit within certain bounds, i.e. load dimensions of a container.
Expand All @@ -13,54 +8,22 @@

public class LoadableItem {

protected final List<StackValue> values;
protected final Stackable stackable;

private int count;
protected Loadable loadable;
protected int count;

protected final long minVolumeLimit;
protected final long minAreaLimit;

public LoadableItem(Stackable stackable, List<StackValue> stackValues, int count) {
this.values = stackValues;
this.stackable = stackable;
public LoadableItem(Loadable loadable, int count) {
this.loadable = loadable;
this.count = count;

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

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

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

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

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

public List<StackValue> getValues() {
return values;
public Loadable getLoadable() {
return loadable;
}

public long getMinAreaLimit() {
return minAreaLimit;
}

public long getMinVolumeLimit() {
return minVolumeLimit;
}

public Stackable getStackable() {
return stackable;

public void setLoadable(Loadable loadable) {
this.loadable = loadable;
}

public int getCount() {
return count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
*
*/

public interface LoadableItemScope {
public interface LoadableItemFilter {

List<LoadableItem> getLoadableItems();

/**
*
* Notify item was loaded
* Notify stackable from item was loaded
*
* @param index
* @return true if some loadable item was excluded due to this
* @return true if some loadable item was excluded due to this loaded item
*/

boolean loaded(int index);
Expand Down

0 comments on commit 0de73c9

Please sign in to comment.