001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright © 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.pm.assignment.contour;
051:
052: import java.util.ArrayList;
053:
054: import com.projity.configuration.Configuration;
055: import com.projity.pm.time.ImmutableInterval;
056: import com.projity.pm.time.MutableInterval;
057:
058: /**
059: * A standard contour represents a work distribution. There are several predined ones, which correspond to a stepping function.
060: * Because the function is the same for each type, instances of this class are final static.
061: * @stereotype strategy
062: */
063: public class StandardContour extends AbstractContour implements
064: ContourTypes {
065: private double meanUnits = 0.0;
066: private int type;
067:
068: public static StandardContour getInstance(int type,
069: AbstractContourBucket[] contourBuckets) {
070: return new StandardContour(type, contourBuckets);
071: }
072:
073: public boolean isPersonal() {
074: return false;
075: }
076:
077: /**
078: * @return Returns the meanUnits.
079: */
080: public double getMeanUnits() {
081: return meanUnits;
082: }
083:
084: public String getName() {
085: return Configuration.getInstance().getFieldDictionary()
086: .getFieldFromId("Field.workContour").convertIdToString(
087: new Integer(type));
088: }
089:
090: /*
091: * (non-Javadoc)
092: * @see com.projity.pm.assignment.contour.Contour#calcTotalWork(long)
093: */
094: public long calcTotalWork(long assignmentDuration) {
095: return (long) (meanUnits * assignmentDuration);
096: }
097:
098: private StandardContour(int type,
099: AbstractContourBucket[] contourBuckets) {
100: super (contourBuckets);
101: this .type = type;
102: meanUnits = calcWeightedSum();
103: }
104:
105: private double calcWeightedSum() {
106: double sum = 0;
107: for (int i = 0; i < contourBuckets.length; i++)
108: sum += contourBuckets[i].weightedSum();
109: return sum;
110: }
111:
112: // The following curves are same as MS project contours
113: public static final StandardContour FLAT_CONTOUR = getInstance(
114: ContourTypes.FLAT, new StandardContourBucket[] { // mean is 1.0
115: new StandardContourBucket(1.0, 1.0) });
116:
117: public static final StandardContour BACK_LOADED_CONTOUR = getInstance(
118: ContourTypes.BACK_LOADED, new StandardContourBucket[] { // mean is 0.6
119: new StandardContourBucket(0.1, 0.1), // 10% charge for first 10%
120: new StandardContourBucket(0.15, 0.1), // 15% charge for next 10%
121: new StandardContourBucket(0.25, 0.1), // 25% charge for next 10%
122: new StandardContourBucket(0.5, 0.2), // 50% charge for next 20%
123: new StandardContourBucket(0.75, 0.2), // 75% charge for next 20%
124: new StandardContourBucket(1.0, 0.3) // 100% charge last 30%
125: });
126:
127: public static final StandardContour FRONT_LOADED_CONTOUR = getInstance(
128: ContourTypes.FRONT_LOADED, new StandardContourBucket[] { // mean is 0.6
129: new StandardContourBucket(1.0, 0.3), // 100% charge first 30%
130: new StandardContourBucket(0.75, 0.2), // 75% charge for next 20%
131: new StandardContourBucket(0.5, 0.2), // 50% charge for next 20%
132: new StandardContourBucket(0.25, 0.1), // 25% charge for next 10%
133: new StandardContourBucket(0.15, 0.1), // 15% charge for next 10%
134: new StandardContourBucket(0.1, 0.1) // 10% charge for last 10%
135: });
136:
137: public static final StandardContour DOUBLE_PEAK_CONTOUR = getInstance(
138: ContourTypes.DOUBLE_PEAK, new StandardContourBucket[] { // mean is 0.5
139: new StandardContourBucket(0.25, 0.1), // 25% charge first 10%
140: new StandardContourBucket(0.5, 0.1), // 50% charge for next 10%
141: new StandardContourBucket(1.0, 0.1), // 100% charge for next 10%
142: new StandardContourBucket(0.5, 0.1), // 50% charge for next 10%
143: new StandardContourBucket(0.25, 0.2), // 25% charge next 20%
144: new StandardContourBucket(0.5, 0.1), // 50% charge for next 10%
145: new StandardContourBucket(1.0, 0.1), // 100% charge for next 10%
146: new StandardContourBucket(0.5, 0.1), // 50% charge for next 10%
147: new StandardContourBucket(0.25, 0.1), // 25% charge last 10%
148: });
149:
150: public static final StandardContour EARLY_PEAK_CONTOUR = getInstance(
151: ContourTypes.EARLY_PEAK, new StandardContourBucket[] { // mean is 0.5
152: new StandardContourBucket(0.25, 0.1), // 25% charge first 10%
153: new StandardContourBucket(0.5, 0.1), // 50% charge for next 10%
154: new StandardContourBucket(1.0, 0.2), // 100% charge for next 20%
155: new StandardContourBucket(0.75, 0.1), // 75% charge for next 10%
156: new StandardContourBucket(0.5, 0.2), // 50% charge next 20%
157: new StandardContourBucket(0.25, 0.1), // 25% charge for next 10%
158: new StandardContourBucket(0.15, 0.1), // 15% charge for next 10%
159: new StandardContourBucket(0.1, 0.1), // 10% charge for last 10%
160:
161: });
162:
163: public static final StandardContour LATE_PEAK_CONTOUR = getInstance(
164: ContourTypes.LATE_PEAK, new StandardContourBucket[] { // mean is 0.5
165: new StandardContourBucket(0.1, 0.1), // 10% charge for first 10%
166: new StandardContourBucket(0.15, 0.1), // 15% charge for next 10%
167: new StandardContourBucket(0.25, 0.1), // 25% charge for next 10%
168: new StandardContourBucket(0.5, 0.2), // 50% charge next 20%
169: new StandardContourBucket(0.75, 0.1), // 75% charge for next 10%
170: new StandardContourBucket(1.0, 0.2), // 100% charge for next 20%
171: new StandardContourBucket(0.5, 0.1), // 50% charge for next 10%
172: new StandardContourBucket(0.25, 0.1) // 25% charge last 10%
173: });
174:
175: public static final StandardContour BELL_CONTOUR = getInstance(
176: ContourTypes.BELL, new StandardContourBucket[] { // mean is 0.5
177: new StandardContourBucket(0.1, 0.1), // 10% charge for first 10%
178: new StandardContourBucket(0.2, 0.1), // 20% charge for next 10%
179: new StandardContourBucket(0.4, 0.1), // 40% charge for next 10%
180: new StandardContourBucket(0.8, 0.1), // 80% charge next 10%
181: new StandardContourBucket(1.0, 0.2), // 100% charge for next 20%
182: new StandardContourBucket(0.8, 0.1), // 80% charge next 10%
183: new StandardContourBucket(0.4, 0.1), // 40% charge for next 10%
184: new StandardContourBucket(0.2, 0.1), // 20% charge for next 10%
185: new StandardContourBucket(0.1, 0.1) // 10% charge for last 10%
186: });
187:
188: public static final StandardContour TURTLE_CONTOUR = getInstance(
189: ContourTypes.TURTLE, new StandardContourBucket[] { // mean is 0.7
190: new StandardContourBucket(0.25, 0.1), // 25% charge for first 10%
191: new StandardContourBucket(0.5, 0.1), // 50% charge for next 10%
192: new StandardContourBucket(0.75, 0.1), // 75% charge for next 10%
193: new StandardContourBucket(1.0, 0.4), // 100% charge next 40%
194: new StandardContourBucket(0.75, 0.1), // 75% charge for next 10%
195: new StandardContourBucket(0.5, 0.1), // 50% charge for next 10%
196: new StandardContourBucket(0.25, 0.1), // 25% charge for last 10%
197: });
198:
199: public static StandardContour getStandardContour(int type) {
200: switch (type) {
201: case FLAT:
202: return FLAT_CONTOUR;
203: case BACK_LOADED:
204: return BACK_LOADED_CONTOUR;
205: case FRONT_LOADED:
206: return FRONT_LOADED_CONTOUR;
207: case DOUBLE_PEAK:
208: return DOUBLE_PEAK_CONTOUR;
209: case EARLY_PEAK:
210: return EARLY_PEAK_CONTOUR;
211: case LATE_PEAK:
212: return LATE_PEAK_CONTOUR;
213: case BELL:
214: return BELL_CONTOUR;
215: case TURTLE:
216: return TURTLE_CONTOUR;
217: default:
218: return null;
219: }
220: }
221:
222: // public Object clone() throws CloneNotSupportedException {
223: // return this; //since this is immutable, no need to clone it
224: // }
225: public Object clone() {
226: return super .clone();
227: }
228:
229: /**
230: * @return Returns the type.
231: */
232: public int getType() {
233: return type;
234: }
235:
236: /* (non-Javadoc)
237: * @see com.projity.pm.assignment.contour.AbstractContour#extend(long, long)
238: */
239: public AbstractContour extend(long end, long extendDuration) {
240: return this ;
241: }
242:
243: /* (non-Javadoc)
244: * @see com.projity.pm.assignment.contour.AbstractContour#extendBefore(long, long)
245: */
246: public AbstractContour extendBefore(long startOffset,
247: long extendDuration) {
248: return this ;
249: }
250:
251: public MutableInterval getRangeThatIntervalCanBeMoved(long start,
252: long end) {
253: return new MutableInterval(start, Long.MAX_VALUE); // by default unbounded
254: }
255: }
|