Source Code Cross Referenced for LineageImpl.java in  » Science » Cougaar12_4 » org » cougaar » servicediscovery » description » 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.servicediscovery.description 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2002-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:        package org.cougaar.servicediscovery.description;
027:
028:        import java.util.ArrayList;
029:        import java.util.Collections;
030:        import java.util.List;
031:
032:        import org.cougaar.core.util.UID;
033:        import org.cougaar.core.util.UniqueObject;
034:        import org.cougaar.util.log.Logger;
035:        import org.cougaar.util.log.Logging;
036:        import org.cougaar.util.TimeSpan;
037:
038:        import org.cougaar.planning.ldm.plan.ScheduleElement;
039:        import org.cougaar.planning.ldm.plan.ScheduleElementImpl;
040:        import org.cougaar.planning.ldm.plan.Schedule;
041:        import org.cougaar.planning.ldm.plan.ScheduleImpl;
042:
043:        /**
044:         * A Collection which maintains an ordered list of agent names - reflecting
045:         * the superior/subordinate chain from a root agent. 
046:         * Iteration starts with the current agent and goes to the root.
047:         */
048:
049:        public class LineageImpl extends Lineage {
050:            private static Logger myLogger = Logging
051:                    .getLogger(LineageImpl.class);
052:
053:            private UID myUID = null;
054:            private ArrayList myList = new ArrayList();
055:            private int myType = -1;
056:            private Schedule mySchedule = new ScheduleImpl();
057:
058:            public LineageImpl() {
059:            }
060:
061:            public LineageImpl(int type) {
062:                super ();
063:
064:                if (!validType(type)) {
065:                    throw new IllegalArgumentException(
066:                            "Unrecognized lineage type: " + type);
067:                }
068:
069:                myType = type;
070:
071:                // Default to always valid
072:                mySchedule.add(new ScheduleElementImpl(TimeSpan.MIN_VALUE,
073:                        TimeSpan.MAX_VALUE));
074:            }
075:
076:            public LineageImpl(int type, List list) {
077:                this (type);
078:
079:                myList.addAll(list);
080:            }
081:
082:            public LineageImpl(int type, List list, Schedule schedule) {
083:                this (type);
084:
085:                myList.addAll(list);
086:
087:                mySchedule = new ScheduleImpl(schedule);
088:            }
089:
090:            public LineageImpl(Lineage lineage) {
091:                this (lineage.getType(), lineage.getList(), lineage
092:                        .getSchedule());
093:            }
094:
095:            public void setUID(UID newUID) {
096:                if (myUID != null) {
097:                    myLogger.error("Attempt to reset UID.");
098:                    return;
099:                }
100:
101:                myUID = newUID;
102:            }
103:
104:            public UID getUID() {
105:                return myUID;
106:            }
107:
108:            /**
109:             * @return the type of the lineage.
110:             * Should be one of the defined lineage types.
111:             **/
112:            public int getType() {
113:                return myType;
114:            }
115:
116:            /**
117:             * @param type of the lineage.
118:             * Should be one of the defined lineage types.
119:             **/
120:            public void setType(int type) {
121:                // Not allowed to set type more than once
122:                if (myType != -1) {
123:                    myLogger.error("Attempt to reset lineage type.");
124:                    return;
125:                }
126:
127:                if (!validType(type)) {
128:                    throw new IllegalArgumentException(
129:                            "Unrecognized lineage type: " + type);
130:                }
131:
132:                myType = type;
133:            }
134:
135:            /**
136:             * @return the name of the agent at the end of the lineage
137:             * Null if lineage has no members
138:             */
139:            public String getLeaf() {
140:                return (String) ((myList.size() > 0) ? (myList.get(myList
141:                        .size() - 1)) : null);
142:            }
143:
144:            /**
145:             * @return the name of the agent at the root of the lineage.
146:             */
147:            public String getRoot() {
148:                return (String) ((myList.size() > 0) ? myList.get(0) : null);
149:            }
150:
151:            /**
152:             * @return the number of links in the lineage between the two agents. 
153:             * Returns -1 if the agents are not linked.
154:             */
155:            public int countHops(String startingAgent, String endingAgent) {
156:                return Lineage.countHops(getList(), startingAgent, endingAgent);
157:            }
158:
159:            /*
160:             * @return an unmodifiable list of all agents in the lineage
161:             */
162:            public List getList() {
163:                return Collections.unmodifiableList(myList);
164:            }
165:
166:            /*
167:             * Sets the associated lineage list
168:             */
169:            public synchronized void setList(List list) {
170:                myList = new ArrayList(list);
171:            }
172:
173:            /**
174:             * @return the time periods for which the lineage is valid
175:             */
176:            public Schedule getSchedule() {
177:                return mySchedule;
178:            }
179:
180:            /*
181:             * Sets the Schedule 
182:             */
183:            public void setSchedule(Schedule schedule) {
184:                mySchedule = new ScheduleImpl(schedule);
185:            }
186:
187:            public String toString() {
188:                StringBuffer buf = new StringBuffer();
189:                buf.append("UID=" + getUID());
190:
191:                String typeStr = "";
192:                switch (myType) {
193:                case (ADCON):
194:                    typeStr = ADCON_STRING;
195:                    break;
196:                case (OPCON):
197:                    typeStr = OPCON_STRING;
198:                    break;
199:                case (SUPPORT):
200:                    typeStr = SUPPORT_STRING;
201:                    break;
202:                default:
203:                    typeStr = UNDEFINED_STRING;
204:                }
205:                buf.append(", type=" + typeStr);
206:
207:                buf.append(", list=[");
208:                for (int i = 0; i < myList.size(); i++) {
209:                    buf.append(String.valueOf(myList.get(i)));
210:                    if (i < (myList.size() - 1))
211:                        buf.append(", ");
212:                }
213:                buf.append("]");
214:
215:                buf.append(", schedule=" + getSchedule().toString());
216:                return buf.toString();
217:            }
218:
219:            public boolean equals(Object o) {
220:                if (o instanceof  LineageImpl) {
221:                    LineageImpl otherLineage = (LineageImpl) o;
222:                    if ((getUID() == null) || (otherLineage.getUID() == null)) {
223:                        return ((otherLineage.getUID() == null)
224:                                && (getUID() == null)
225:                                && (getList().equals(otherLineage.getList())) && (getSchedule()
226:                                .equals(otherLineage.getSchedule())));
227:                    } else {
228:                        return (otherLineage.getUID().equals(getUID()));
229:                    }
230:                } else {
231:                    return false;
232:                }
233:            }
234:
235:            public int hashCode() {
236:                return getUID().hashCode();
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.