Source Code Cross Referenced for RoleScheduleImpl.java in  » Science » Cougaar12_4 » org » cougaar » planning » ldm » plan » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.planning.ldm.plan 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 1997-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.planning.ldm.plan;
028:
029:        import java.util.Collection;
030:        import java.util.Date;
031:        import java.util.Enumeration;
032:        import java.util.Iterator;
033:        import java.util.List;
034:
035:        import org.cougaar.planning.ldm.asset.Asset;
036:        import org.cougaar.util.UnaryPredicate;
037:
038:        /**
039:         * A RoleSchedule is a representation of an asset's scheduled
040:         * commitments. These commitments(plan elements) are stored
041:         * in a collection.  RoleSchedules do not travel with an
042:         * asset accross agent boundaries, therefore, the roleschedule 
043:         * is only valid while that asset is assigned to the current agent.
044:         **/
045:        public class RoleScheduleImpl extends ScheduleImpl implements 
046:                RoleSchedule, NewRoleSchedule {
047:            private transient Schedule availableschedule;
048:            private Asset asset;
049:
050:            /** Constructor
051:             * @param theasset this roleschedule is attached to
052:             **/
053:            public RoleScheduleImpl(Asset theasset) {
054:                super ();
055:                setScheduleType(ScheduleType.ROLE);
056:                setScheduleElementType(ScheduleElementType.PLAN_ELEMENT);
057:                asset = theasset;
058:            }
059:
060:            /** @return the Asset of this roleschedule.
061:             **/
062:            public Asset getAsset() {
063:                return asset;
064:            }
065:
066:            /** SHOULD *ONLY* BE CALLED BY THE ASSET CREATOR or THE ASSETTRANSFER LP!
067:             * set the availableschedule
068:             * @param avschedule - the schedule that the asset is assigned 
069:             * or available to this agent
070:             **/
071:            public void setAvailableSchedule(Schedule avschedule) {
072:                availableschedule = avschedule;
073:            }
074:
075:            //return the available schedule for this asset
076:            public Schedule getAvailableSchedule() {
077:                return availableschedule;
078:            }
079:
080:            /**
081:             *  Cougaar INTERNAL METHOD - SHOULD NEVER BE CALLED BY A PLUGIN
082:             *  add a single planelement to the roleschedule container
083:             *  @param aPlanElement PlanElement to add
084:             *  @deprecated Use add(Object aPlanElement) instead.
085:             **/
086:            public synchronized void addToRoleSchedule(PlanElement aPlanElement) {
087:                add(aPlanElement);
088:            }
089:
090:            /**
091:             *  Cougaar INTERNAL METHOD - SHOULD NEVER BE CALLED BY A PLUGIN
092:             *  remove a single planelement from the roleschedule container
093:             *  @param aPlanElement PlanElement to remove
094:             *  @deprecated Use remove(Object aPlanElement) instead.
095:             **/
096:            public synchronized void removeFromRoleSchedule(
097:                    PlanElement aPlanElement) {
098:                remove(aPlanElement);
099:            }
100:
101:            public Collection getEncapsulatedRoleSchedule(Date start, Date end) {
102:                return getEncapsulatedRoleSchedule(start.getTime(), end
103:                        .getTime());
104:            }
105:
106:            public synchronized Collection getEncapsulatedRoleSchedule(
107:                    long start, long end) {
108:                return getEncapsulatedScheduleElements(start, end);
109:            }
110:
111:            public synchronized Collection getEqualAspectValues(
112:                    final int aspect, final double value) {
113:                return filter(new UnaryPredicate() {
114:                    public boolean execute(Object obj) {
115:                        AllocationResult ar = ((PlanElement) obj)
116:                                .getEstimatedResult();
117:                        if (ar != null) {
118:                            return (value == ar.getValue(aspect));
119:                        }
120:                        return false;
121:                    }
122:                });
123:            }
124:
125:            public synchronized Collection getMatchingRoleElements(
126:                    final Role aRole) {
127:                return filter(new UnaryPredicate() {
128:                    public boolean execute(Object obj) {
129:                        if (obj instanceof  Allocation) {
130:                            Role disrole = ((Allocation) obj).getRole();
131:                            if (disrole.equals(aRole)) {
132:                                return true;
133:                            }
134:                        } else if (obj instanceof  AssetTransfer) {
135:                            Role disrole = ((AssetTransfer) obj).getRole();
136:                            if (disrole.equals(aRole)) {
137:                                return true;
138:                            }
139:                        }
140:                        return false;
141:                    }
142:                });
143:            }
144:
145:            public Collection getOverlappingRoleSchedule(Date start, Date end) {
146:                return getOverlappingRoleSchedule(start.getTime(), end
147:                        .getTime());
148:            }
149:
150:            public synchronized Collection getOverlappingRoleSchedule(
151:                    long start, long end) {
152:                return getOverlappingScheduleElements(start, end);
153:            }
154:
155:            /** get an enumeration over a copy of all of the schedule elements of this 
156:             * schedule.
157:             * Note that this is a copy, changes to the underlying schedule will not be 
158:             * reflected in the Enumeration.
159:             * @return Enumeration{ScheduleElement}
160:             */
161:            public Enumeration getRoleScheduleElements() {
162:                return getAllScheduleElements();
163:            }
164:
165:            /** Convenience utility that adds the requested aspectvalues of the estimated
166:             * allocationresult of each PlanElement (RoleSchedule Element) in the given
167:             * orderedset.
168:             * If the requested aspecttype is not defined for any of the elements, nothing
169:             * will be added to the sum for that particular element.
170:             * This utility should be used to add aspecttypes like quantity, cost, etc.
171:             * @return double The sum of the aspectvalues
172:             * @param elementsToAdd  A set of roleschedule elements (planelements) to add
173:             * @see org.cougaar.planning.ldm.plan.AspectType
174:             **/
175:            public double addAspectValues(Collection elementsToAdd,
176:                    int aspecttype) {
177:                double acc = 0.0;
178:
179:                synchronized (elementsToAdd) {
180:                    if (elementsToAdd instanceof  List) {
181:                        int listSize = elementsToAdd.size();
182:
183:                        for (int index = 0; index < listSize; index++) {
184:                            PlanElement anElement = (PlanElement) ((List) elementsToAdd)
185:                                    .get(index);
186:                            AllocationResult aResult = anElement
187:                                    .getEstimatedResult();
188:                            if (aResult != null
189:                                    && aResult.isDefined(aspecttype)) {
190:                                acc += aResult.getValue(aspecttype);
191:                            }
192:                        }
193:                    } else {
194:                        for (Iterator i = elementsToAdd.iterator(); i.hasNext();) {
195:                            PlanElement anElement = (PlanElement) i.next();
196:                            AllocationResult aResult = anElement
197:                                    .getEstimatedResult();
198:                            if (aResult != null
199:                                    && aResult.isDefined(aspecttype)) {
200:                                acc += aResult.getValue(aspecttype);
201:                            }
202:                        }
203:                    }
204:                } // end synchronization on elementsToAdd
205:
206:                return acc;
207:            }
208:
209:            // for BeanInfo
210:            public synchronized String[] getRoleScheduleIDs() {
211:                int l = size();
212:                String[] IDs = new String[l];
213:                for (int i = 0; i < l; i++) {
214:                    IDs[i] = ((PlanElement) get(i)).getUID().toString();
215:                }
216:                return IDs;
217:            }
218:
219:            public String getRoleScheduleID(int i) {
220:                return ((PlanElement) get(i)).getUID().toString();
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.