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

net.sourceforge.plantuml.nwdiag.next.NTetris Maven / Gradle / Ivy

There is a newer version: 1.2025.0
Show newest version
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.nwdiag.next;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

public class NTetris {

	private final Map all = new LinkedHashMap<>();
	private final BooleanGrid grid = new BooleanGrid();

	@Override
	public String toString() {
		return all.toString();
	}

	public void add(S element) {
		int x = 0;
		while (true) {
			if (grid.isSpaceAvailable(element, x)) {
				all.put(element, x);
				grid.useSpace(element, x);
				return;
			}
			x++;
			if (x > 100)
				throw new IllegalStateException();

		}
	}

	public final Map getPositions() {
		return Collections.unmodifiableMap(all);
	}

	public int getNWidth() {
		int max = 0;
		for (Entry ent : all.entrySet())
			max = Math.max(max, ent.getValue() + ent.getKey().getNWidth());

		return max;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy