TaskManagerImpl.java

Index Score
net.sourceforge.ganttproject.task
GanttProject

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
EXITSProcedure exits
LOOPSNumber of loops
LOGICAL_LINESNumber of statements
FUNCTIONSNumber of function declarations
OPERATORSNumber of operators
CYCLOMATICCyclomatic complexity
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
RETURNSNumber of return points from functions
BLOCKSNumber of blocks
INTERFACE_COMPLEXITYInterface complexity
ELOCEffective lines of code
SIZESize of the file in bytes
UNIQUE_OPERANDSNumber of unique operands
LOCLines of code
PROGRAM_VOCABHalstead program vocabulary
PARAMSNumber of formal parameter declarations
LINESNumber of lines in the source file
LINE_COMMENTNumber of line comments
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0031JAVA0031 Case statement not properly closed
COMPARISONSNumber of comparison operators
JAVA0083JAVA0083 Unnecessary instanceof test
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0032JAVA0032 Switch statement missing default
JAVA0285JAVA0285 Dereference of potentially null variable
JAVA0034JAVA0034 Missing braces in if statement
JAVA0177JAVA0177 Variable declaration missing initializer
UNIQUE_OPERATORSNumber of unique operators
JAVA0265JAVA0265 Use of Throwable.printStackTrace()
JAVA0080JAVA0080 Import declaration not used
EXEC_COMMENTSComments in executable code
JAVA0144JAVA0144 Line exceeds maximum M characters
JAVA0119JAVA0119 Control variable changed within body of for loop
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0035JAVA0035 Missing braces in for statement
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0264JAVA0264 Integer math in long context - check for overflow
JAVA0030JAVA0030 Private field not used
JAVA0171JAVA0171 Unused local variable
JAVA0123JAVA0123 Use all three components of for loop
JAVA0029JAVA0029 Private method not used
JAVA0067JAVA0067 Array descriptor on identifier name
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
DOC_COMMENTNumber of javadoc comment lines
JAVA0130JAVA0130 Non-static method does not use instance fields
COMMENTSComment lines
NEST_DEPTHMaximum nesting depth
JAVA0145JAVA0145 Tab character used in source file
/* * Created on 05.07.2003 * */ package net.sourceforge.ganttproject.task; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; import net.sourceforge.ganttproject.GanttCalendar; import net.sourceforge.ganttproject.GanttTask; import net.sourceforge.ganttproject.GanttTaskRelationship; import net.sourceforge.ganttproject.Mediator; import net.sourceforge.ganttproject.calendar.AlwaysWorkingTimeCalendarImpl; import net.sourceforge.ganttproject.calendar.GPCalendar; import net.sourceforge.ganttproject.calendar.GPCalendarActivity; import net.sourceforge.ganttproject.resource.HumanResource; import net.sourceforge.ganttproject.resource.ResourceManager; import net.sourceforge.ganttproject.task.algorithm.AdjustTaskBoundsAlgorithm; import net.sourceforge.ganttproject.task.algorithm.AlgorithmCollection; import net.sourceforge.ganttproject.task.algorithm.CriticalPathAlgorithm; import net.sourceforge.ganttproject.task.algorithm.CriticalPathAlgorithmImpl; import net.sourceforge.ganttproject.task.algorithm.FindPossibleDependeesAlgorithm; import net.sourceforge.ganttproject.task.algorithm.FindPossibleDependeesAlgorithmImpl; import net.sourceforge.ganttproject.task.algorithm.ProjectBoundsAlgorithm; import net.sourceforge.ganttproject.task.algorithm.RecalculateTaskCompletionPercentageAlgorithm; import net.sourceforge.ganttproject.task.algorithm.RecalculateTaskScheduleAlgorithm; import net.sourceforge.ganttproject.task.algorithm.ProjectBoundsAlgorithm.Result; import net.sourceforge.ganttproject.task.dependency.EventDispatcher; import net.sourceforge.ganttproject.task.dependency.TaskDependency; import net.sourceforge.ganttproject.task.dependency.TaskDependencyCollection; import net.sourceforge.ganttproject.task.dependency.TaskDependencyCollectionImpl; import net.sourceforge.ganttproject.task.dependency.TaskDependencyConstraint; import net.sourceforge.ganttproject.task.dependency.TaskDependencyException; import net.sourceforge.ganttproject.task.dependency.constraint.FinishFinishConstraintImpl; import net.sourceforge.ganttproject.task.dependency.constraint.FinishStartConstraintImpl; import net.sourceforge.ganttproject.task.dependency.constraint.StartFinishConstraintImpl; import net.sourceforge.ganttproject.task.dependency.constraint.StartStartConstraintImpl; import net.sourceforge.ganttproject.task.event.TaskDependencyEvent; import net.sourceforge.ganttproject.task.event.TaskHierarchyEvent; import net.sourceforge.ganttproject.task.event.TaskListener; import net.sourceforge.ganttproject.task.event.TaskPropertyEvent; import net.sourceforge.ganttproject.task.event.TaskScheduleEvent; import net.sourceforge.ganttproject.task.hierarchy.TaskHierarchyManagerImpl; import net.sourceforge.ganttproject.time.DateFrameable; import net.sourceforge.ganttproject.time.TimeUnit; import net.sourceforge.ganttproject.time.gregorian.GregorianCalendar; /** * @author bard */ public class TaskManagerImpl implements TaskManager { private static final GPCalendar RESTLESS_CALENDAR = new AlwaysWorkingTimeCalendarImpl(); private final TaskHierarchyManagerImpl myHierarchyManager; private final TaskDependencyCollectionImpl myDependencyCollection; private final AlgorithmCollection myAlgorithmCollection; private final List myListeners = new ArrayList(); private int myMaxID = -1; private Task myRoot; private final TaskManagerConfig myConfig; private final TaskContainmentHierarchyFacade.Factory myFacadeFactory; private TaskContainmentHierarchyFacade myTaskContainment; private static class TaskMap { private final Map myId2task = new HashMap(); private TaskDocumentOrderComparator myComparator; private boolean isModified = true; private Task[] myArray; private final TaskManagerImpl myManager; TaskMap(TaskManagerImpl taskManager) { myComparator = new TaskDocumentOrderComparator(taskManager); myManager = taskManager; } void addTask(Task task) { myId2task.put(new Integer(task.getTaskID()), task); isModified = true; } Task getTask(int id) { return (Task) myId2task.get(new Integer(id)); } public Task[] getTasks() { if (isModified) { myArray = (Task[]) myId2task.values().toArray(new Task[myId2task.size()]); Arrays.sort(myArray, myComparator); isModified = false; } return myArray; } public void clear() { myId2task.clear(); isModified = true; } public void removeTask(Task task) { myId2task.remove(new Integer(task.getTaskID())); Task[] nestedTasks = myManager.getTaskHierarchy().getNestedTasks(task); for (int i=0; i<nestedTasks.length; i++) { removeTask(nestedTasks[i]); } isModified = true; } public int size() { return myId2task.size(); } public boolean isEmpty() { return myId2task.isEmpty(); } void setDirty() { isModified = true; } } private final TaskMap myTaskMap = new TaskMap(this); private final CustomColumnsStorage myCustomColumnsStorage; TaskManagerImpl( TaskContainmentHierarchyFacade.Factory containmentFacadeFactory, TaskManagerConfig config) { myConfig = config; myCustomColumnsStorage = new CustomColumnsStorage(); Mediator.registerCustomColumnsStorage(myCustomColumnsStorage); myHierarchyManager = new TaskHierarchyManagerImpl(); EventDispatcher dispatcher = new EventDispatcher() { public void fireDependencyAdded(TaskDependency dep) { TaskManagerImpl.this.fireDependencyAdded(dep); } public void fireDependencyRemoved(TaskDependency dep) { TaskManagerImpl.this.fireDependencyRemoved(dep); } }; myDependencyCollection = new TaskDependencyCollectionImpl(containmentFacadeFactory, dispatcher) { private TaskContainmentHierarchyFacade myTaskHierarchy; protected TaskContainmentHierarchyFacade getTaskHierarchy() { if (myTaskHierarchy == null) { myTaskHierarchy = TaskManagerImpl.this.getTaskHierarchy(); } return myTaskHierarchy; } }; myFacadeFactory = containmentFacadeFactory == null ? new FacadeFactoryImpl() : containmentFacadeFactory; // clear(); { Date today = GregorianCalendar.getInstance().getTime(); myRoot = new GanttTask(null, new GanttCalendar(today), 1, this, -1); myRoot.setStart(new GanttCalendar(GregorianCalendar.getInstance() .getTime())); myRoot.setDuration(createLength(getConfig().getTimeUnitStack() .getDefaultTimeUnit(), 1)); myRoot.setExpand(true); } FindPossibleDependeesAlgorithm alg1 = new FindPossibleDependeesAlgorithmImpl() { protected TaskContainmentHierarchyFacade createContainmentFacade() { return TaskManagerImpl.this.getTaskHierarchy(); } }; AdjustTaskBoundsAlgorithm alg3 = new AdjustTaskBoundsAlgorithm() { protected TaskContainmentHierarchyFacade createContainmentFacade() { return TaskManagerImpl.this.getTaskHierarchy(); } }; RecalculateTaskScheduleAlgorithm alg2 = new RecalculateTaskScheduleAlgorithm( alg3) { protected TaskContainmentHierarchyFacade createContainmentFacade() { return TaskManagerImpl.this.getTaskHierarchy(); } }; RecalculateTaskCompletionPercentageAlgorithm alg4 = new RecalculateTaskCompletionPercentageAlgorithm() { protected TaskContainmentHierarchyFacade createContainmentFacade() { return TaskManagerImpl.this.getTaskHierarchy(); } }; ProjectBoundsAlgorithm alg5 = new ProjectBoundsAlgorithm(); myAlgorithmCollection = new AlgorithmCollection(alg1, alg2, alg3, alg4, alg5); } /* * (non-Javadoc) * * @see net.sourceforge.ganttproject.task.TaskManager#getTask(int) */ public GanttTask getTask(int taskId) { return (GanttTask) myTaskMap.getTask(taskId); } public Task getRootTask() { if (myRoot == null) { } return myRoot; } public Task[] getTasks() { return myTaskMap.getTasks(); //return (Task[]) myId2task.values().toArray(new Task[myId2task.size()]); } /* * (non-Javadoc) * * @see net.sourceforge.ganttproject.task.TaskManager#clear() */ public void clear() { myTaskMap.clear(); setMaxID(-1); myDependencyCollection.clear(); { Date today = GregorianCalendar.getInstance().getTime(); myRoot = new GanttTask(null, new GanttCalendar(today), 1, this, -1); myRoot.setStart(new GanttCalendar(GregorianCalendar.getInstance() .getTime())); myRoot.setDuration(createLength(getConfig().getTimeUnitStack() .getDefaultTimeUnit(), 1)); myRoot.setExpand(true); } } public void deleteTask(Task tasktoRemove) { myTaskMap.removeTask(tasktoRemove); // TaskDependency[] dep = // myDependencyCollection.getDependencies(tasktoRemove); // for(int i=0;i<dep.length; i++){ // dep[i].delete(); // } // todo REMOVE TASK FROM TASKHIERARCHY // fireTaskRemoved(tasktoRemove,myTaskContainment.getContainer(tasktoRemove)); } public GanttTask createTask() { GanttTask result = createTask(-1); return result; } /* * (non-Javadoc) * * @see net.sourceforge.ganttproject.task.TaskManager#createTask(int) */ public GanttTask createTask(int taskID) { GanttTask result = new GanttTask("", new GanttCalendar(), 1, this, taskID); if (result.getTaskID() >= getMaxID()) { setMaxID(result.getTaskID() + 1); } result.setName(getConfig().getTaskNamePrefix()); result.setColor(getConfig().getDefaultColor()); result.setDuration(createLength(1)); AdjustTaskBoundsAlgorithm alg = getAlgorithmCollection().getAdjustTaskBoundsAlgorithm(); alg.run(result); RecalculateTaskCompletionPercentageAlgorithm alg2 = getAlgorithmCollection().getRecalculateTaskCompletionPercentageAlgorithm(); alg2.run(result); myCustomColumnsStorage.processNewTask(result); // result.setTaskID(taskID); // getTaskHierarchy().move(result, getRootTask()); // result.move(getRootTask()); fireTaskAdded(result); return result; } /* * (non-Javadoc) * * @see net.sourceforge.ganttproject.task.TaskManager#registerTask(net.sourceforge.ganttproject.GanttTask) */ public void registerTask(Task task) { int taskID = task.getTaskID(); if (myTaskMap.getTask(taskID) == null) { // if the taskID is // not in the map myTaskMap.addTask(task); if (getMaxID() < taskID) { setMaxID(taskID + 1); } } else { // taskID has been in the map. the newTask will not be added throw new RuntimeException( "There is a task that already has the ID " + taskID); } } boolean isRegistered(TaskImpl task) { return myTaskMap.getTask(task.getTaskID())!=null; } /* * (non-Javadoc) * * @see net.sourceforge.ganttproject.task.TaskManager#setTask(net.sourceforge.ganttproject.GanttTask) */ public void setTask(Task task) { int taskID = task.getTaskID(); myTaskMap.addTask(task); if (taskID > getMaxID()) { setMaxID(taskID); } } public int getTaskCount() { return myTaskMap.size(); } public TaskLength getProjectLength() { if (myTaskMap.isEmpty()) { return createLength(getConfig().getTimeUnitStack() .getDefaultTimeUnit(), 0); } Result result = getAlgorithmCollection().getProjectBoundsAlgorithm() .getBounds(Arrays.asList(myTaskMap.getTasks())); return createLength( getConfig().getTimeUnitStack().getDefaultTimeUnit(), result.lowerBound, result.upperBound); } public Date getProjectStart() { if (myTaskMap.isEmpty()) { return myRoot.getStart().getTime(); } Result result = getAlgorithmCollection().getProjectBoundsAlgorithm() .getBounds(Arrays.asList(myTaskMap.getTasks())); return result.lowerBound; } public Date getProjectEnd(){ if (myTaskMap.isEmpty()) { return myRoot.getStart().getTime(); } Result result = getAlgorithmCollection().getProjectBoundsAlgorithm() .getBounds(Arrays.asList(myTaskMap.getTasks())); return result.upperBound; } public TaskLength createLength(TimeUnit unit, float length) { return new TaskLengthImpl(unit, length); } public TaskLength createLength(long count) { return new TaskLengthImpl(getConfig().getTimeUnitStack() .getDefaultTimeUnit(), count); } public String encode(TaskLength taskLength) { StringBuffer result = new StringBuffer(String.valueOf(taskLength.getLength())); result.append(myConfig.getTimeUnitStack().encode(taskLength.getTimeUnit())); return result.toString(); } public TaskLength createLength(String lengthAsString) throws DurationParsingException { int state = 0; StringBuffer valueBuffer = new StringBuffer(); Integer currentValue = null; TaskLength currentLength = null; lengthAsString += " "; for (int i=0; i<lengthAsString.length(); i++) { char nextChar = lengthAsString.charAt(i); if (Character.isDigit(nextChar)) { switch (state) { case 0: if (currentValue!=null) { throw new DurationParsingException(); } state = 1; valueBuffer.setLength(0); case 1: valueBuffer.append(nextChar); break; case 2: TimeUnit timeUnit = findTimeUnit(valueBuffer.toString()); if (timeUnit==null) { throw new DurationParsingException(valueBuffer.toString()); } assert currentValue!=null; TaskLength localResult = createLength(timeUnit, currentValue.floatValue()); if (currentLength==null) { currentLength = localResult; } else { if (currentLength.getTimeUnit().isConstructedFrom(timeUnit)) { float recalculatedLength = currentLength.getLength(timeUnit); currentLength = createLength(timeUnit, localResult.getValue()+recalculatedLength); } else { throw new DurationParsingException(); } } state = 1; currentValue = null; valueBuffer.setLength(0); valueBuffer.append(nextChar); break; } } else if(Character.isWhitespace(nextChar)) { switch (state) { case 0: break; case 1: currentValue = Integer.valueOf(valueBuffer.toString()); state = 0; break; case 2: TimeUnit timeUnit = findTimeUnit(valueBuffer.toString()); if (timeUnit==null) { throw new DurationParsingException(valueBuffer.toString()); } assert currentValue!=null; TaskLength localResult = createLength(timeUnit, currentValue.floatValue()); if (currentLength==null) { currentLength = localResult; } else { if (currentLength.getTimeUnit().isConstructedFrom(timeUnit)) { float recalculatedLength = currentLength.getLength(timeUnit); currentLength = createLength(timeUnit, localResult.getValue()+recalculatedLength); } else { throw new DurationParsingException(); } } state = 0; currentValue = null; break; } } else { switch (state) { case 1: currentValue = Integer.valueOf(valueBuffer.toString()); case 0: if (currentValue==null) { throw new DurationParsingException(); } state = 2; valueBuffer.setLength(0); case 2: valueBuffer.append(nextChar); break; } } } if (currentValue!=null) { currentValue = Integer.valueOf(valueBuffer.toString()); TimeUnit dayUnit = findTimeUnit("d"); currentLength = createLength(dayUnit, currentValue.floatValue()); } return currentLength; } private TimeUnit findTimeUnit(String code) { return myConfig.getTimeUnitStack().findTimeUnit(code); } public TaskLength createLength(TimeUnit timeUnit, Date startDate, Date endDate) { TaskLength result; int sign = 1; if (endDate.before(startDate)) { sign = -1; Date temp = endDate; endDate = startDate; startDate = temp; } if (timeUnit instanceof DateFrameable) { DateFrameable df = (DateFrameable) timeUnit; int unitCount = 0; for (; startDate.before(endDate); unitCount++) { startDate = df.adjustRight(startDate); } result = new TaskLengthImpl(timeUnit, unitCount*sign); } else { throw new IllegalArgumentException("Time unit=" + timeUnit + " is not date frameable"); } return result; } public Date shift(Date original, TaskLength duration) { GPCalendar calendar = RESTLESS_CALENDAR; TimeUnit atomUnit = getConfig().getTimeUnitStack().getDefaultTimeUnit(); long atomDuration = (long) duration.getLength(atomUnit); List activities = calendar.getActivities(original, atomUnit, atomDuration); if (activities.isEmpty()) { return original; } //final long length = duration.getLength(); final Date result; if (atomDuration >= 0) { GPCalendarActivity lastActivity = (GPCalendarActivity) activities .get(activities.size() - 1); result = lastActivity.getEnd(); } else { GPCalendarActivity firstActivity = (GPCalendarActivity) activities .get(0); result = firstActivity.getStart(); } return result; } public TaskDependencyCollection getDependencyCollection() { return myDependencyCollection; } public AlgorithmCollection getAlgorithmCollection() { return myAlgorithmCollection; } public TaskHierarchyManagerImpl getHierarchyManager() { return myHierarchyManager; } public TaskDependencyConstraint createConstraint(final int constraintID) { TaskDependencyConstraint result; switch (constraintID) { case GanttTaskRelationship.FS: { result = new FinishStartConstraintImpl(); break; } case GanttTaskRelationship.FF: { result = new FinishFinishConstraintImpl(); break; } case GanttTaskRelationship.SF: { result = new StartFinishConstraintImpl(); break; } case GanttTaskRelationship.SS: { result = new StartStartConstraintImpl(); break; } default: { throw new IllegalArgumentException("Unknown constraint ID=" + constraintID); } } return result; } public int getMaxID() { return myMaxID; } private void setMaxID(int id) { myMaxID = id; } void increaseMaxID() { myMaxID++; } public void addTaskListener(TaskListener listener) { myListeners.add(listener); } public GPCalendar getCalendar() { return getConfig().getCalendar(); } public void fireTaskProgressChanged(Task changedTask) { TaskPropertyEvent e = new TaskPropertyEvent(changedTask); for (int i = 0; i < myListeners.size(); i++) { TaskListener next = (TaskListener) myListeners.get(i); next.taskProgressChanged(e); } } void fireTaskScheduleChanged(Task changedTask, GanttCalendar oldStartDate, GanttCalendar oldFinishDate) { TaskScheduleEvent e = new TaskScheduleEvent(changedTask, oldStartDate, oldFinishDate, changedTask.getStart(), changedTask.getEnd()); // List copy = new ArrayList(myListeners); // myListeners.clear(); for (int i = 0; i < myListeners.size(); i++) { TaskListener next = (TaskListener) myListeners.get(i); next.taskScheduleChanged(e); } } private void fireDependencyAdded(TaskDependency newDependency) { TaskDependencyEvent e = new TaskDependencyEvent( getDependencyCollection(), newDependency); for (int i = 0; i < myListeners.size(); i++) { TaskListener next = (TaskListener) myListeners.get(i); next.dependencyAdded(e); } } private void fireDependencyRemoved(TaskDependency dep) { TaskDependencyEvent e = new TaskDependencyEvent( getDependencyCollection(), dep); for (int i = 0; i < myListeners.size(); i++) { TaskListener next = (TaskListener) myListeners.get(i); next.dependencyRemoved(e); } } private void fireTaskAdded(Task task) { TaskHierarchyEvent e = new TaskHierarchyEvent(this, task, null, getTaskHierarchy().getContainer(task)); for (int i = 0; i < myListeners.size(); i++) { TaskListener next = (TaskListener) myListeners.get(i); next.taskAdded(e); } } private void fireTaskRemoved(Task task, Task oldSupertask) { TaskHierarchyEvent e = new TaskHierarchyEvent(this, task, oldSupertask, null); for (int i = 0; i < myListeners.size(); i++) { TaskListener next = (TaskListener) myListeners.get(i); next.taskRemoved(e); } } void fireTaskPropertiesChanged(Task task) { TaskPropertyEvent e = new TaskPropertyEvent(task); for (int i = 0; i < myListeners.size(); i++) { TaskListener next = (TaskListener) myListeners.get(i); next.taskPropertiesChanged(e); } } public TaskManagerConfig getConfig() { return myConfig; } private final class FacadeImpl implements TaskContainmentHierarchyFacade { //private final Task myRoot; private List myPathBuffer = new ArrayList(); // public FacadeImpl(Task root) { // myRoot = root; // } public Task[] getNestedTasks(Task container) { return container.getNestedTasks(); } public boolean hasNestedTasks(Task container) { return container.getNestedTasks().length>0; } public Task getRootTask() { return TaskManagerImpl.this.getRootTask(); } public Task getContainer(Task nestedTask) { return nestedTask.getSupertask(); } public boolean areUnrelated(Task first, Task second) { myPathBuffer.clear(); for (Task container = getContainer(first); container != null; container = getContainer(container)) { myPathBuffer.add(container); } if (myPathBuffer.contains(second)) { return false; } myPathBuffer.clear(); for (Task container = getContainer(second); container != null; container = getContainer(container)) { myPathBuffer.add(container); } if (myPathBuffer.contains(first)) { return false; } return true; } public void move(Task whatMove, Task newContainer) { move(whatMove, newContainer, -1); } public void move(Task whatMove, Task newContainer, int childIndex) { whatMove.move(newContainer, childIndex); } public int getDepth(Task task) { int depth = 0; while (task != myRoot) { task = task.getSupertask(); depth++; } return depth; } public int compareDocumentOrder(Task task1, Task task2) { if (task1==task2) { return 0; } List buffer1 = new ArrayList(); for (Task container = task1; container != null; container = getContainer(container)) { buffer1.add(0,container); } List buffer2 = new ArrayList(); for (Task container = task2; container != null; container = getContainer(container)) { buffer2.add(0,container); } if (buffer1.get(0)!=getRootTask() && buffer2.get(0)==getRootTask()) { return -1; } if (buffer1.get(0)==getRootTask() && buffer2.get(0)!=getRootTask()) { return 1; } int result = 0; int i=0; Task commonRoot = null; while (true) { if (i==buffer1.size()) { return -1; } if (i==buffer2.size()) { return 1; } Task root1 = (Task) buffer1.get(i); Task root2 = (Task) buffer2.get(i); if (root1!=root2) { assert commonRoot!=null : "Failure comparing task="+task1+" and task="+task2+"\n. Path1="+buffer1+"\nPath2="+buffer2; Task[] nestedTasks = commonRoot.getNestedTasks(); for (int j=0; j<nestedTasks.length; j++) { if (nestedTasks[j]==root1) { return -1; } if (nestedTasks[j]==root2) { return 1; } } throw new IllegalStateException("We should not be here"); } i++; commonRoot = root1; } } public boolean contains(Task task) { throw new UnsupportedOperationException(); } } private class FacadeFactoryImpl implements TaskContainmentHierarchyFacade.Factory { // private final Task myRoot; // // FacadeFactoryImpl(Task root) { // myRoot = root; // } public TaskContainmentHierarchyFacade createFacede() { return new FacadeImpl(); } } public TaskContainmentHierarchyFacade getTaskHierarchy() { // if (myTaskContainment==null) { return myFacadeFactory.createFacede(); // } // return myTaskContainment; } public TaskManager emptyClone() { return new TaskManagerImpl(null, myConfig); } public Map importData(TaskManager taskManager) { Task importRoot = taskManager.getRootTask(); Map original2imported = new HashMap(); importData(importRoot, getRootTask(), original2imported); TaskDependency[] deps = taskManager.getDependencyCollection() .getDependencies(); for (int i = 0; i < deps.length; i++) { Task nextDependant = deps[i].getDependant(); Task nextDependee = deps[i].getDependee(); Task importedDependant = (Task) original2imported .get(nextDependant); Task importedDependee = (Task) original2imported.get(nextDependee); try { TaskDependency dependency = getDependencyCollection() .createDependency(importedDependant, importedDependee, new FinishStartConstraintImpl()); dependency.setConstraint(deps[i].getConstraint()); dependency.setDifference(deps[i].getDifference()); dependency.setHardness(deps[i].getHardness()); } catch (TaskDependencyException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return original2imported; } private void importData(Task importRoot, Task root, Map original2imported) { Task[] nested = importRoot.getManager().getTaskHierarchy() .getNestedTasks(importRoot); for (int i = nested.length - 1; i >= 0; i--) { Task nextImported = myTaskMap.getTask(nested[i].getTaskID()) == null ? createTask(nested[i].getTaskID()) : createTask(); registerTask(nextImported); nextImported.setName(nested[i].getName()); nextImported.setStart(nested[i].getStart().Clone()); nextImported.setDuration(nested[i].getDuration()); nextImported.setMilestone(nested[i].isMilestone()); nextImported.setColor(nested[i].getColor()); nextImported.setShape(nested[i].getShape()); nextImported.setCompletionPercentage(nested[i] .getCompletionPercentage()); nextImported.setNotes(nested[i].getNotes()); nextImported.setTaskInfo(nested[i].getTaskInfo()); nextImported.setExpand(nested[i].getExpand()); if (nested[i].getThird() != null) { nextImported.setThirdDate(nested[i].getThird().Clone()); nextImported.setThirdDateConstraint(nested[i] .getThirdDateConstraint()); } Mediator.getCustomColumnsStorage().processNewTask(nextImported); // System.out.println ("Import : " + nextImported.getTaskID() + " // -->> " + nextImported.getName()); original2imported.put(nested[i], nextImported); // nextImported.move(root); getTaskHierarchy().move(nextImported, root); importData(nested[i], nextImported, original2imported); } } public Date findClosestWorkingTime(Date time) { return getCalendar().findClosestWorkingTime(time); } public void processCriticalPath(TaskNode root) { try { myAlgorithmCollection.getRecalculateTaskScheduleAlgorithm().run(); } catch (TaskDependencyException e) { e.printStackTrace(); } CriticalPathAlgorithm criticAlgo = new CriticalPathAlgorithmImpl(root, getCalendar()); Task tasks[] = criticAlgo.getCriticalTasks(); resetCriticalPath(root); for (int i = 0; i < tasks.length; i++) tasks[i].setCritical(true); } private void resetCriticalPath(TaskNode root) { Enumeration en = root.preorderEnumeration(); while (en.hasMoreElements()) { Object next = en.nextElement(); if (!(next instanceof TaskNode)) continue; Task t = (Task) ((TaskNode) next).getUserObject(); t.setCritical(false); } } public void importAssignments(TaskManager importedTaskManager, ResourceManager hrManager, Map original2importedTask, Map original2importedResource) { Task[] tasks = importedTaskManager.getTasks(); for (int i = 0; i < tasks.length; i++) { ResourceAssignment[] assignments = tasks[i].getAssignments(); for (int j = 0; j < assignments.length; j++) { Task task = getTask(((Task) original2importedTask.get(tasks[i])) .getTaskID()); ResourceAssignment assignment = task.getAssignmentCollection() .addAssignment( (HumanResource) original2importedResource .get(assignments[j].getResource())); assignment.setLoad(assignments[j].getLoad()); assignment.setCoordinator(assignments[j].isCoordinator()); } } } void onTaskMoved(TaskImpl task) { if (!isRegistered(task)) { registerTask(task); } myTaskMap.setDirty(); } public TaskLength getZeroLength() { return createLength(0); } }

The table below shows all metrics for TaskManagerImpl.java.

MetricValueDescription
BLOCKS154.00Number of blocks
BLOCK_COMMENT29.00Number of block comment lines
COMMENTS64.00Comment lines
COMMENT_DENSITY 0.11Comment density
COMPARISONS72.00Number of comparison operators
CYCLOMATIC157.00Cyclomatic complexity
DECL_COMMENTS16.00Comments in declarations
DOC_COMMENT 3.00Number of javadoc comment lines
ELOC596.00Effective lines of code
EXEC_COMMENTS12.00Comments in executable code
EXITS168.00Procedure exits
FUNCTIONS76.00Number of function declarations
HALSTEAD_DIFFICULTY 0.41Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY165.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 1.00JAVA0029 Private method not used
JAVA0030 1.00JAVA0030 Private field not used
JAVA0031 3.00JAVA0031 Case statement not properly closed
JAVA0032 3.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 1.00JAVA0034 Missing braces in if statement
JAVA0035 1.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 1.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 1.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 5.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 1.00JAVA0082 Unnecessary widening cast
JAVA0083 1.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA011712.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 1.00JAVA0119 Control variable changed within body of for loop
JAVA0123 1.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 1.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 1.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 2.00JAVA0144 Line exceeds maximum M characters
JAVA0145193.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 1.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 3.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 1.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 1.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 2.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 6.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 3.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
JAVA0289 2.00null
LINES911.00Number of lines in the source file
LINE_COMMENT32.00Number of line comments
LOC755.00Lines of code
LOGICAL_LINES413.00Number of statements
LOOPS23.00Number of loops
NEST_DEPTH 5.00Maximum nesting depth
OPERANDS1806.00Number of operands
OPERATORS3369.00Number of operators
PARAMS64.00Number of formal parameter declarations
PROGRAM_LENGTH5175.00Halstead program length
PROGRAM_VOCAB580.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS101.00Number of return points from functions
SIZE34134.00Size of the file in bytes
UNIQUE_OPERANDS519.00Number of unique operands
UNIQUE_OPERATORS61.00Number of unique operators
WHITESPACE92.00Number of whitespace lines