com.softicar.platform.common.container.schedule.DoubleSchedule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.container.schedule;
import com.softicar.platform.common.container.matrix.traits.DoubleMatrixTraits;
import java.util.Comparator;
import java.util.Map;
/**
* A {@link SimpleSchedule} for values of type {@link Double}.
*
* @author Oliver Richers
*/
public class DoubleSchedule, C extends Comparable> extends SimpleSchedule
implements IDoubleSchedule {
public DoubleSchedule(C backorderColumn) {
super(new DoubleMatrixTraits(), backorderColumn, null, null);
}
public DoubleSchedule(C backorderColumn, Comparator rowComparator, Comparator colComparator) {
super(new DoubleMatrixTraits(), backorderColumn, rowComparator, colComparator);
}
public void substractValue(R row, double value) {
Map map = getRowMap(row);
for (C key: map.keySet()) {
Double keyValue = map.get(key);
if (value == 0.0) {
break;
}
if (keyValue == null || keyValue.doubleValue() == 0.0) {
continue;
}
//
if (keyValue.doubleValue() < 0.0) {
value += Math.abs(keyValue);
map.put(key, 0.0);
} else {
if (value <= keyValue.doubleValue()) {
map.put(key, map.get(key) - value);
value = 0;
} else {
value -= map.get(key);
map.put(key, 0.0);
}
}
//
}
}
public void substractValue(Map keyValueMap) {
for (Map.Entry entry: keyValueMap.entrySet()) {
substractValue(entry.getKey(), entry.getValue());
}
}
}