1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-15 22:52:24 +00:00
plantuml/src/net/sourceforge/plantuml/project3/TaskImpl.java

176 lines
4.3 KiB
Java
Raw Normal View History

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;
import java.util.LinkedHashSet;
import java.util.Set;
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;
private final Set<Resource> resources = new LinkedHashSet<Resource>();
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) {
LoadPlanable plan1 = defaultPlan;
if (resources.size() > 0) {
plan1 = PlanUtils.minOf(plan1, getRessourcePlan());
}
return PlanUtils.minOf(getLoad(), plan1).getLoadAt(instant);
}
public int loadForResource(Resource res, Instant i) {
if (resources.contains(res) && i.compareTo(getStart()) >= 0 && i.compareTo(getEnd()) <= 0) {
if (res.getLoadAt(i) == 0) {
return 0;
}
int size = 0;
for (Resource r : resources) {
if (r.getLoadAt(i) > 0) {
size++;
}
}
return getLoadAt(i) / size;
}
return 0;
}
private LoadPlanable getRessourcePlan() {
if (resources.size() == 0) {
throw new IllegalStateException();
}
return new LoadPlanable() {
public int getLoadAt(Instant instant) {
int result = 0;
for (Resource res : resources) {
result += res.getLoadAt(instant);
}
return result;
}
};
}
public String getPrettyDisplay() {
if (resources.size() > 0) {
final StringBuilder result = new StringBuilder(code.getSimpleDisplay());
result.append(" ");
for (Iterator<Resource> it = resources.iterator(); it.hasNext();) {
result.append("{");
result.append(it.next().getName());
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;
}
2018-04-06 20:36:30 +00:00
public void addResource(Resource resource) {
this.resources.add(resource);
}
2017-02-01 18:55:51 +00:00
}