BrightSide Workbench Full Report + Source Code
BrightSide/elephant-zkoss/src/main/java/org/turro/zkoss/svg/GanttItem.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.zkoss.svg;
19 
20 import java.util.HashSet;
21 import java.util.Iterator;
22 import java.util.Set;
23 import org.turro.util.CompareUtil;
24 import org.zkoss.lang.Strings;
25 
30 public class GanttItem implements Comparable<GanttItem> {
31 
32  private GanttData set;
33 
34  private final long reference;
35  private final String name, uniqueId;
36  private double hours, done, start = 0.0;
37  private int position = -1;
38  private boolean milestone, finished;
39  private final Set<GanttPredecessor> predecessors = new HashSet<>();
40 
41  public GanttItem(long reference, String uniqueId, String name, double hours, double done) {
42  this.reference = reference;
43  this.uniqueId = uniqueId;
44  this.name = name;
45  this.hours = hours;
46  this.done = done;
47  }
48 
49  public boolean isFinished() {
50  return finished;
51  }
52 
53  public void setFinished(boolean finished) {
54  this.finished = finished;
55  }
56 
57  public boolean isMilestone() {
58  return milestone;
59  }
60 
61  public void setMilestone(boolean milestone) {
62  this.milestone = milestone;
63  }
64 
65  public double getMaxHours() {
66  return finished ? (done == 0.0 ? Math.max(done, hours) : done) : Math.max(done, hours);
67  }
68 
69  public double getHours() {
70  return hours;
71  }
72 
73  public double getStart() {
74  return start;
75  }
76 
77  public void initStart() {
78  for(GanttPredecessor gp : predecessors) {
79  GanttItem predecessor = set.getItem(gp.getIndex());
80  if(gp.getMode() == GanttPredecessor.GANTT_START_TO_START) {
81  start = Math.max(predecessor.start + gp.getLag(), start);
82  } else if(gp.getMode() == GanttPredecessor.GANTT_END_TO_START) {
83  start = Math.max(predecessor.start + predecessor.getMaxHours() + gp.getLag(), start);
84  }
85  }
86  }
87 
88  public void initReference() {
89  if(Strings.isBlank(uniqueId)) {
90  start = -1;
91  double endHours = 0.0d;
92  for(GanttItem gi : set) {
93  if(gi.reference == reference && !Strings.isBlank(gi.uniqueId)) {
94  start = (start == -1 ? gi.start : Math.min(start, gi.start));
95  endHours = Math.max(gi.start + gi.hours, endHours);
96  }
97  }
98  start = Math.max(start, 0.0d);
99  hours = endHours - start;
100  }
101  }
102 
103  public double getDone() {
104  return done;
105  }
106 
107  public String getName() {
108  return name;
109  }
110 
111  public int getPosition() {
112  if(position == -1) {
113  Iterator<GanttItem> it = set.iterator();
114  int idx = 0;
115  while(it.hasNext()) {
116  GanttItem gi = it.next();
117  if(gi.compareTo(this) == 0) {
118  position = idx;
119  break;
120  }
121  idx++;
122  }
123  }
124  return position;
125  }
126 
127  public void setPosition(int position) {
128  this.position = position;
129  }
130 
131  public String getUniqueId() {
132  return uniqueId;
133  }
134 
135  public GanttData getSet() {
136  return set;
137  }
138 
139  public void setSet(GanttData set) {
140  this.set = set;
141  }
142 
143  public Set<GanttPredecessor> getPredecessors() {
144  return predecessors;
145  }
146 
147  @Override
148  public int compareTo(GanttItem o) {
149  int result = CompareUtil.compare(reference, o.reference);
150  if(result == 0) {
151  result = CompareUtil.compare(uniqueId, o.uniqueId);
152  }
153  return result;
154  }
155 
156 }
GanttItem(long reference, String uniqueId, String name, double hours, double done)