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

com.softicar.platform.common.container.schedule.coverage.ScheduleCellIterator Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.container.schedule.coverage;

import com.softicar.platform.common.container.matrix.IImmutableMatrix;
import com.softicar.platform.common.math.arithmetic.IArithmetic;
import java.util.Iterator;

class ScheduleCellIterator> {

	private final IImmutableMatrix schedule;
	private final IArithmetic arithmetic;
	private final Row row;
	private final Iterator columnIterator;
	private Quantity quantity;
	private Column column;

	public ScheduleCellIterator(IImmutableMatrix schedule, IArithmetic arithmetic, Row row) {

		this.schedule = schedule;
		this.arithmetic = arithmetic;
		this.row = row;
		this.columnIterator = schedule.getColumns().iterator();
		this.column = null;
		this.quantity = arithmetic.getZero();
	}

	public Row getRow() {

		return row;
	}

	public Quantity getQuantity() {

		return quantity;
	}

	public Column getColumn() {

		return column;
	}

	public boolean gatherQuantity() {

		while (arithmetic.isZero(quantity)) {
			if (columnIterator.hasNext()) {
				this.column = columnIterator.next();
				this.quantity = schedule.getValue(row, column);
			} else {
				return false;
			}
		}

		return true;
	}

	public void transferToCoverage(ScheduleCoverage coverage, Quantity quantity) {

		coverage.addUnassignedQuantity(row, column, quantity);
		subtract(quantity);
	}

	public void transferToCoverage(ScheduleCoverage coverage, Column targetColumn, Quantity quantity) {

		coverage.addQuantity(row, column, targetColumn, quantity);
		subtract(quantity);
	}

	public void subtract(Quantity quantity) {

		this.quantity = arithmetic.minus(this.quantity, quantity);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy