2017-02-01 18:55:51 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2019-01-16 18:34:41 +00:00
|
|
|
* (C) Copyright 2009-2020, Arnaud Roques
|
2017-02-01 18:55:51 +00:00
|
|
|
*
|
|
|
|
* Project Info: http://plantuml.com
|
|
|
|
*
|
2017-03-15 19:13:31 +00:00
|
|
|
* If you like this project or if you find it useful, you can support us at:
|
|
|
|
*
|
|
|
|
* http://plantuml.com/patreon (only 1$ per month!)
|
|
|
|
* http://plantuml.com/paypal
|
|
|
|
*
|
2017-02-01 18:55:51 +00:00
|
|
|
* This file is part of PlantUML.
|
|
|
|
*
|
|
|
|
* PlantUML is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PlantUML distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.project3;
|
|
|
|
|
2018-04-06 20:36:30 +00:00
|
|
|
import java.util.Iterator;
|
2019-02-09 21:56:24 +00:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
2018-04-06 20:36:30 +00:00
|
|
|
|
|
|
|
public class TaskImpl implements Task, LoadPlanable {
|
2017-02-01 18:55:51 +00:00
|
|
|
|
|
|
|
private final TaskCode code;
|
2018-04-06 20:36:30 +00:00
|
|
|
private final Solver3 solver;
|
2019-02-09 21:56:24 +00:00
|
|
|
private final Map<Resource, Integer> resources2 = new LinkedHashMap<Resource, Integer>();
|
2018-04-06 20:36:30 +00:00
|
|
|
private final LoadPlanable defaultPlan;
|
2017-02-01 18:55:51 +00:00
|
|
|
|
2018-04-06 20:36:30 +00:00
|
|
|
public TaskImpl(TaskCode code, LoadPlanable defaultPlan) {
|
2017-02-01 18:55:51 +00:00
|
|
|
this.code = code;
|
2018-04-06 20:36:30 +00:00
|
|
|
this.defaultPlan = defaultPlan;
|
|
|
|
this.solver = new Solver3(this);
|
2017-02-01 18:55:51 +00:00
|
|
|
setStart(new InstantDay(0));
|
2018-04-06 20:36:30 +00:00
|
|
|
setLoad(LoadInDays.inDay(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getLoadAt(Instant instant) {
|
2019-02-09 21:56:24 +00:00
|
|
|
LoadPlanable result = defaultPlan;
|
|
|
|
if (resources2.size() > 0) {
|
|
|
|
result = PlanUtils.multiply(defaultPlan, getRessourcePlan());
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
2019-02-09 21:56:24 +00:00
|
|
|
return result.getLoadAt(instant);
|
|
|
|
// return PlanUtils.minOf(getLoad(), plan1).getLoadAt(instant);
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 21:56:24 +00:00
|
|
|
public int loadForResource(Resource res, Instant instant) {
|
|
|
|
if (resources2.keySet().contains(res) && instant.compareTo(getStart()) >= 0 && instant.compareTo(getEnd()) <= 0) {
|
|
|
|
if (res.isClosedAt(instant)) {
|
2018-04-06 20:36:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-02-09 21:56:24 +00:00
|
|
|
// int size = 0;
|
|
|
|
return resources2.get(res);
|
|
|
|
// for (Resource r : resources) {
|
|
|
|
// if (r.getLoadAt(i) > 0) {
|
|
|
|
// size++;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return getLoadAt(instant) / size;
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private LoadPlanable getRessourcePlan() {
|
2019-02-09 21:56:24 +00:00
|
|
|
if (resources2.size() == 0) {
|
2018-04-06 20:36:30 +00:00
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
return new LoadPlanable() {
|
|
|
|
|
|
|
|
public int getLoadAt(Instant instant) {
|
|
|
|
int result = 0;
|
2019-02-09 21:56:24 +00:00
|
|
|
for (Map.Entry<Resource, Integer> ent : resources2.entrySet()) {
|
|
|
|
final Resource res = ent.getKey();
|
|
|
|
if (res.isClosedAt(instant)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final int percentage = ent.getValue();
|
|
|
|
result += percentage;
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrettyDisplay() {
|
2019-02-09 21:56:24 +00:00
|
|
|
if (resources2.size() > 0) {
|
2018-04-06 20:36:30 +00:00
|
|
|
final StringBuilder result = new StringBuilder(code.getSimpleDisplay());
|
|
|
|
result.append(" ");
|
2019-02-09 21:56:24 +00:00
|
|
|
for (Iterator<Map.Entry<Resource, Integer>> it = resources2.entrySet().iterator(); it.hasNext();) {
|
|
|
|
final Map.Entry<Resource, Integer> ent = it.next();
|
2018-04-06 20:36:30 +00:00
|
|
|
result.append("{");
|
2019-02-09 21:56:24 +00:00
|
|
|
result.append(ent.getKey().getName());
|
|
|
|
final int percentage = ent.getValue();
|
|
|
|
if (percentage != 100) {
|
|
|
|
result.append(":" + percentage + "%");
|
|
|
|
}
|
2018-04-06 20:36:30 +00:00
|
|
|
result.append("}");
|
|
|
|
if (it.hasNext()) {
|
|
|
|
result.append(" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result.toString();
|
|
|
|
}
|
|
|
|
return code.getSimpleDisplay();
|
2017-02-01 18:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return code.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String debug() {
|
2018-04-06 20:36:30 +00:00
|
|
|
return "" + getStart() + " ---> " + getEnd() + " [" + getLoad() + "]";
|
2017-02-01 18:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public TaskCode getCode() {
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Instant getStart() {
|
2018-04-06 20:36:30 +00:00
|
|
|
Instant result = (Instant) solver.getData(TaskAttribute.START);
|
|
|
|
while (getLoadAt(result) == 0) {
|
|
|
|
result = result.increment();
|
|
|
|
}
|
|
|
|
return result;
|
2017-02-01 18:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Instant getEnd() {
|
|
|
|
return (Instant) solver.getData(TaskAttribute.END);
|
|
|
|
}
|
|
|
|
|
2018-04-06 20:36:30 +00:00
|
|
|
public Load getLoad() {
|
|
|
|
return (Load) solver.getData(TaskAttribute.LOAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLoad(Load load) {
|
|
|
|
solver.setData(TaskAttribute.LOAD, load);
|
2017-02-01 18:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setStart(Instant start) {
|
|
|
|
solver.setData(TaskAttribute.START, start);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEnd(Instant end) {
|
|
|
|
solver.setData(TaskAttribute.END, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
private TaskDraw taskDraw;
|
|
|
|
private ComplementColors colors;
|
|
|
|
|
|
|
|
public void setTaskDraw(TaskDraw taskDraw) {
|
|
|
|
taskDraw.setColors(colors);
|
|
|
|
this.taskDraw = taskDraw;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TaskDraw getTaskDraw() {
|
|
|
|
return taskDraw;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setColors(ComplementColors colors) {
|
|
|
|
this.colors = colors;
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:56:24 +00:00
|
|
|
public void addResource(Resource resource, int percentage) {
|
|
|
|
this.resources2.put(resource, percentage);
|
2018-04-06 20:36:30 +00:00
|
|
|
}
|
|
|
|
|
2017-02-01 18:55:51 +00:00
|
|
|
}
|