All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.skjolberg.packing.Level Maven / Gradle / Ivy

There is a newer version: 1.2.5
Show newest version
package com.github.skjolberg.packing;

import java.util.ArrayList;

/**
 * A level within a container
 *
 */
public class Level extends ArrayList{

	private static final long serialVersionUID = 1L;

	public int getHeight() {
		int height = 0;

		for(Placement placement : this) {
			Box box = placement.getBox();
			if(box.getHeight() > height) {
				height = box.getHeight();
			}
		}

		return height;
	}

	public int getWeight() {
		int weight = 0;

		for(Placement placement : this) {
			weight += placement.getBox().getWeight();
		}

		return weight;
	}

	/**
	 *
	 * Check whether placement is valid, i.e. no overlaps.
	 *
	 */
	public void validate() {
		for(int i = 0; i < size(); i++) {
			for(int j = 0; j < size(); j++) {
				if(j == i) {
					if(!get(i).intersects(get(j))) {
						throw new IllegalArgumentException();
					}
				} else {
					if(get(i).intersects(get(j))) {
						throw new IllegalArgumentException(i + " vs " + j);
					}
				}
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy