Source Code Cross Referenced for PollChanges.java in  » Forum » JForum-2.1.8 » net » jforum » entities » 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 » Forum » JForum 2.1.8 » net.jforum.entities 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.jforum.entities;
002:
003:        import java.util.ArrayList;
004:        import java.util.Iterator;
005:        import java.util.List;
006:
007:        import net.jforum.view.forum.common.PostCommon;
008:
009:        /**
010:         * An helper class that holds changes made to the pool.
011:         * 
012:         * @author Rafael Steil
013:         * @version $Id: PollChanges.java,v 1.4 2007/04/24 02:19:46 rafaelsteil Exp $
014:         */
015:        public class PollChanges {
016:            private List deletedOptions = new ArrayList();
017:            private List newOptions = new ArrayList();
018:            private List changedOptions = new ArrayList();
019:
020:            private boolean hasChanges;
021:
022:            private Poll first;
023:            private Poll second;
024:
025:            /**
026:             * @param first The "complete", most recent poll version. Usually the one
027:             * that's in the database. 
028:             * @param second The poll to compare with. It usually will be a poll filled
029:             * by {@link PostCommon#fillPostFromRequest()}, so matches will be done againts the 
030:             * existing poll and the data comming from the server. 
031:             */
032:            public PollChanges(Poll first, Poll second) {
033:                this .first = first;
034:                this .second = second;
035:            }
036:
037:            public void addChangedOption(PollOption option) {
038:                this .changedOptions.add(option);
039:                this .hasChanges = true;
040:            }
041:
042:            public List getChangedOptions() {
043:                return this .changedOptions;
044:            }
045:
046:            public void addDeletedOption(PollOption option) {
047:                this .deletedOptions.add(option);
048:                this .hasChanges = true;
049:            }
050:
051:            public List getDeletedOptions() {
052:                return this .deletedOptions;
053:            }
054:
055:            public void addNewOption(PollOption option) {
056:                this .newOptions.add(option);
057:                this .hasChanges = true;
058:            }
059:
060:            public List getNewOptions() {
061:                return this .newOptions;
062:            }
063:
064:            public boolean hasChanges() {
065:                this .searchForChanges();
066:                return this .hasChanges;
067:            }
068:
069:            private void searchForChanges() {
070:                if (first == null || second == null) {
071:                    return;
072:                }
073:
074:                boolean isSame = first.getLabel().equals(second.getLabel());
075:                isSame &= first.getLength() == second.getLength();
076:
077:                this .hasChanges = !isSame;
078:
079:                List firstOptions = first.getOptions();
080:                List secondOptions = second.getOptions();
081:
082:                // Search for changes in existing options
083:                for (Iterator iter = firstOptions.iterator(); iter.hasNext();) {
084:                    PollOption option = (PollOption) iter.next();
085:                    PollOption changed = this .findOptionById(option.getId(),
086:                            secondOptions);
087:
088:                    if (changed != null
089:                            && !option.getText().equals(changed.getText())) {
090:                        this .addChangedOption(changed);
091:                    } else if (changed == null) {
092:                        this .addDeletedOption(option);
093:                    }
094:                }
095:
096:                // Check if the incoming poll added options
097:                for (Iterator iter = secondOptions.iterator(); iter.hasNext();) {
098:                    PollOption option = (PollOption) iter.next();
099:
100:                    if (this .findOptionById(option.getId(), firstOptions) == null) {
101:                        this .addNewOption(option);
102:                    }
103:                }
104:            }
105:
106:            private PollOption findOptionById(int id, List options) {
107:                for (Iterator iter = options.iterator(); iter.hasNext();) {
108:                    PollOption o = (PollOption) iter.next();
109:
110:                    if (o.getId() == id) {
111:                        return o;
112:                    }
113:                }
114:
115:                return null;
116:            }
117:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.