Source Code Cross Referenced for PizzaPreferences.java in  » Science » Cougaar12_4 » org » cougaar » pizza » plugin » 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.pizza.plugin 
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:         */package org.cougaar.pizza.plugin;
026:
027:        import org.cougaar.core.service.LoggingService;
028:        import org.cougaar.core.util.UID;
029:        import org.cougaar.core.util.UniqueObject;
030:
031:        import java.util.HashMap;
032:        import java.util.Iterator;
033:        import java.util.Map;
034:        import java.util.Set;
035:        import java.util.TreeSet;
036:
037:        import org.cougaar.util.log.Logger;
038:        import org.cougaar.util.log.Logging;
039:
040:        import org.cougaar.pizza.Constants;
041:        import org.cougaar.pizza.servlet.HistoryServletFriendly;
042:
043:        /**
044:         * Local accumulation of replies to invite, marking who has replied and the kinds
045:         * of pizza they want. Automatically updated by the {@link org.cougaar.pizza.relay.RSVPRelaySource}. Published
046:         * by the InvitePlugin so that the PlaceOrderPlugin knows to start.
047:         *<p>
048:         * This class works as an example of publishing a custom object on 
049:         * the Blackboard. Note that it implements UniqueObject 
050:         * (which extends Serializable) for easy identification and retrieval
051:         * on the Blackboard, and so it can be sent in messages.
052:         *
053:         * @see org.cougaar.pizza.plugin.InvitePlugin
054:         * @see org.cougaar.pizza.plugin.PlaceOrderPlugin
055:         */
056:        public class PizzaPreferences implements  UniqueObject,
057:                HistoryServletFriendly {
058:            private UID uid;
059:            // Map of accumulated results
060:            private Map friendToPizza = new HashMap();
061:
062:            // Note this static method of getting a logger within an object.
063:            private static Logger log = Logging
064:                    .getLogger(PizzaPreferences.class);
065:
066:            // Total meat and veg servings to order
067:            private int numMeat = 0;
068:            private int numVeg = 0;
069:
070:            public PizzaPreferences(UID uid) {
071:                this .uid = uid;
072:            }
073:
074:            // for UniqueObject interface
075:            public UID getUID() {
076:                return uid;
077:            }
078:
079:            public void setUID(UID uid) {
080:                this .uid = uid;
081:            }
082:
083:            /**
084:             * The given friend has replied, requesting the given pizza, so store
085:             * their response.
086:             * 
087:             * @param friend The agent name responding
088:             * @param preference The kind of meat they like (using a pizza Constant)
089:             */
090:            public void addFriendToPizza(String friend, String preference) {
091:                if (friend == null || friend.equals(""))
092:                    return;
093:
094:                friendToPizza.put(friend, preference);
095:
096:                if (preference.equals(Constants.MEAT_PIZZA))
097:                    numMeat++;
098:                else if (preference.equals(Constants.VEGGIE_PIZZA))
099:                    numVeg++;
100:                else
101:                    log.warn("Unknown preference " + preference + " for "
102:                            + friend);
103:            }
104:
105:            /**
106:             * What kind of pizza does the given friend want?
107:             * @param friend to look up
108:             * @return kind of pizza they want
109:             */
110:            public String getPreferenceForFriend(String friend) {
111:                return (String) friendToPizza.get(friend);
112:            }
113:
114:            public Set getFriends() {
115:                return friendToPizza.keySet();
116:            }
117:
118:            /** @return printable list of the friends we have preferences for */
119:            public String getFriendNames() {
120:                return friendToPizza.keySet().toString();
121:            }
122:
123:            /** @return printable list of just the preferences collected */
124:            public String getPreferenceValues() {
125:                return friendToPizza.values().toString();
126:            }
127:
128:            /** @return printable list of the friend-to-preference mapping */
129:            public String getFriendToPreference() {
130:                return friendToPizza.toString();
131:            }
132:
133:            /** @return Number of people wanting meat pizza */
134:            public int getNumMeat() {
135:                return numMeat;
136:            }
137:
138:            /** @return Number of orders for veggie pizza */
139:            public int getNumVeg() {
140:                return numVeg;
141:            }
142:
143:            /**
144:             * Print an HTML-friendly description of the object, for use in the HistoryServlet.
145:             * @param type Not-used here, is the transaction type
146:             * @return HTML text to display this object
147:             */
148:            public String toHTML(int type) {
149:                StringBuffer buf = new StringBuffer();
150:                buf.append("<table border=1 align=center>");
151:                buf.append("<tr>");
152:                buf.append("<th>");
153:                buf.append("Friend");
154:                buf.append("</th>");
155:                buf.append("<th>");
156:                buf.append("Preference");
157:                buf.append("</th>");
158:                buf.append("</tr>");
159:                for (Iterator iter = new TreeSet(getFriends()).iterator(); iter
160:                        .hasNext();) {
161:                    buf.append("<tr>");
162:
163:                    buf.append("<td>");
164:                    String friend = (String) iter.next();
165:                    buf.append(friend);
166:                    buf.append("</td>");
167:
168:                    buf.append("<td>");
169:                    String preference = getPreferenceForFriend(friend);
170:                    buf.append(preference);
171:                    buf.append("</td>");
172:
173:                    buf.append("</tr>");
174:                }
175:                buf.append("</table>");
176:                return buf.toString();
177:            }
178:
179:            public String toString() {
180:                return "Party guests pizza preferences: " + friendToPizza;
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.