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.costing;
051:
052: import java.io.IOException;
053: import java.io.ObjectInputStream;
054: import java.io.ObjectOutputStream;
055: import java.io.Serializable;
056: import java.util.ArrayList;
057:
058: import com.projity.configuration.Settings;
059: import com.projity.datatype.Rate;
060: import com.projity.field.FieldContext;
061: import com.projity.interval.InvalidValueObjectForIntervalException;
062:
063: /**
064: *
065: */
066: public class CostRateTables implements Cost, Serializable, Cloneable {
067: public static final int DEFAULT = 0;
068: protected CostRateTable[] costRateTableArray;
069: String[] names = null;
070:
071: String getName(int index) {
072: if (names == null) {
073: names = Settings.COST_RATE_NAMES.split(";");
074: }
075: return names[index];
076: }
077:
078: public CostRateTable getCostRateTable(int index) {
079: if (costRateTableArray[index] == null)
080: costRateTableArray[index] = new CostRateTable(
081: getName(index));
082: return costRateTableArray[index];
083: }
084:
085: public Object clone() {
086: try {
087: CostRateTables c = (CostRateTables) super .clone();
088: if (names != null)
089: c.names = new String[names.length];
090: else
091: for (int i = 0; i < names.length; i++) {
092: c.names[i] = (names[i] == null) ? null
093: : new String(names[i]);
094: }
095: if (costRateTableArray != null) {
096: c.costRateTableArray = new CostRateTable[costRateTableArray.length];
097: for (int i = 0; i < costRateTableArray.length; i++) {
098: c.costRateTableArray[i] = (costRateTableArray[i] == null) ? null
099: : (CostRateTable) costRateTableArray[i]
100: .clone();
101: if (c.costRateTableArray[i] != null)
102: c.costRateTableArray[i].initAfterCloning();
103: }
104: }
105: return c;
106: } catch (CloneNotSupportedException e) {
107: throw new InternalError();
108: }
109: }
110:
111: public void setCostRateTable(int index, CostRateTable t) {
112: costRateTableArray[index] = t;
113: }
114:
115: private CostRate getCurrent() {
116: return (CostRate) costRateTableArray[DEFAULT].findCurrent();
117: }
118:
119: /* (non-Javadoc)
120: * @see com.projity.pm.costing.Rate#getCostPerUse()
121: */
122: public double getCostPerUse() {
123: return getCurrent().getCostPerUse();
124: }
125:
126: /* (non-Javadoc)
127: * @see com.projity.pm.costing.Rate#getOvertimeRate()
128: */
129: public Rate getOvertimeRate() {
130: return getCurrent().getOvertimeRate();
131: }
132:
133: /* (non-Javadoc)
134: * @see com.projity.pm.costing.Rate#getStandardRate()
135: */
136: public Rate getStandardRate() {
137: return getCurrent().getStandardRate();
138: }
139:
140: /* (non-Javadoc)
141: * @see com.projity.pm.costing.Cost#setCostPerUse(double)
142: */
143: public void setCostPerUse(double costPerUse) {
144: getCurrent().setCostPerUse(costPerUse);
145: }
146:
147: /* (non-Javadoc)
148: * @see com.projity.pm.costing.Cost#setOvertimeRate(double)
149: */
150: public void setOvertimeRate(Rate overtimeRate) {
151: getCurrent().setOvertimeRate(overtimeRate);
152: }
153:
154: /* (non-Javadoc)
155: * @see com.projity.pm.costing.Cost#setStandardRate(double)
156: */
157: public void setStandardRate(Rate standardRate) {
158: getCurrent().setStandardRate(standardRate);
159: }
160:
161: /**
162: *
163: *
164: */
165: public CostRateTables() {
166: super ();
167: costRateTableArray = new CostRateTable[Settings.NUM_COST_RATES]; // initialize array
168: costRateTableArray[DEFAULT] = new CostRateTable(
169: getName(DEFAULT)); //add default element
170: // java.util.GregorianCalendar start1 = new java.util.GregorianCalendar(2003,java.util.GregorianCalendar.JANUARY,4,0,0);
171: // java.util.GregorianCalendar start2 = new java.util.GregorianCalendar(2005,java.util.GregorianCalendar.JANUARY,7,0,0);
172: // try {
173: // CostRate test;
174: // test = costRateTableArray[DEFAULT].newRate(start1.getTimeInMillis());
175: // test.setStandardRate(100.0/(1000*60*60*8));
176: // test.setOvertimeRate(110.0/(1000*60*60*8));
177: // test.setCostPerUse(450);
178: // test = costRateTableArray[DEFAULT].newRate(start2.getTimeInMillis());
179: // test.setStandardRate(13);
180: // test.setOvertimeRate(1300);
181: // } catch (InvalidCostRateException e) {
182: // // TODO Auto-generated catch block
183: // e.printStackTrace();
184: // }
185:
186: }
187:
188: public long getEffectiveDate() {
189: return getCurrent().getEffectiveDate();
190: }
191:
192: public void setEffectiveDate(long effectiveDate)
193: throws InvalidValueObjectForIntervalException {
194: getCurrent().setEffectiveDate(effectiveDate);
195: }
196:
197: public boolean isReadOnlyEffectiveDate(FieldContext fieldContext) {
198: return getCurrent().isReadOnlyEffectiveDate(fieldContext);
199: }
200:
201: public void serialize(ObjectOutputStream s) throws IOException {
202: s.writeObject(names);
203:
204: ArrayList[] costRates = new ArrayList[costRateTableArray.length];
205: for (int i = 0; i < costRates.length; i++) {
206: costRates[i] = (costRateTableArray[i] == null) ? null
207: : costRateTableArray[i].getValueObjects();
208: }
209: s.writeObject(costRates);
210: }
211:
212: public static CostRateTables deserialize(ObjectInputStream s)
213: throws IOException, ClassNotFoundException {
214: CostRateTables t = new CostRateTables();
215: t.names = (String[]) s.readObject();
216: ArrayList[] costRates = (ArrayList[]) s.readObject();
217: t.costRateTableArray = new CostRateTable[costRates.length];
218: for (int i = 0; i < costRates.length; i++) {
219: t.costRateTableArray[i] = (costRates[i] == null) ? null
220: : new CostRateTable(t.names[i], costRates[i]);
221: }
222: return t;
223: }
224:
225: /* (non-Javadoc)
226: * @see com.projity.pm.costing.Cost#fieldHideOvertimeRate(com.projity.field.FieldContext)
227: */
228: public boolean fieldHideOvertimeRate(FieldContext fieldContext) {
229: return getCurrent().fieldHideOvertimeRate(fieldContext);
230: }
231:
232: }
|