Source Code Cross Referenced for People.java in  » Ajax » dwr » org » getahead » dwrdemo » people » 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 » Ajax » dwr » org.getahead.dwrdemo.people 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Joe Walker
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.getahead.dwrdemo.people;
017:
018:        import java.util.ArrayList;
019:        import java.util.Collections;
020:        import java.util.List;
021:        import java.util.regex.Pattern;
022:
023:        import org.apache.commons.logging.Log;
024:        import org.apache.commons.logging.LogFactory;
025:        import org.getahead.dwrdemo.util.RandomData;
026:
027:        /**
028:         * A container for a set of people
029:         * @author Joe Walker [joe at getahead dot ltd dot uk]
030:         */
031:        public class People {
032:            /**
033:             * Pre-populate with random people
034:             */
035:            public People() {
036:                init(5);
037:            }
038:
039:            /**
040:             * 
041:             */
042:            public void init(int count) {
043:                for (int i = 0; i < count; i++) {
044:                    people.add(getRandomPerson());
045:                }
046:            }
047:
048:            /**
049:             * Accessor for the current list of people
050:             * @return the current list of people
051:             */
052:            public List<Person> getAllPeople() {
053:                return people;
054:            }
055:
056:            /**
057:             * Accessor for a subset of the current list of people
058:             * @return the current list of people
059:             */
060:            public List<Person> getMatchingPeople(String filter) {
061:                List<Person> reply = new ArrayList<Person>();
062:                Pattern regex = Pattern.compile(filter,
063:                        Pattern.CASE_INSENSITIVE);
064:                for (Person person : people) {
065:                    if (regex.matcher(person.getName()).find()) {
066:                        reply.add(person);
067:                        log.debug("Adding " + person + " to reply");
068:                    }
069:                }
070:                return reply;
071:            }
072:
073:            /**
074:             * Insert a person into the set of people
075:             * @param person The person to add or update
076:             */
077:            public void setPerson(Person person) {
078:                log.debug("Adding person: " + person);
079:                if (person.getId() == -1) {
080:                    person.setId(getNextId());
081:                }
082:
083:                people.remove(person);
084:                people.add(person);
085:            }
086:
087:            /**
088:             * Delete a person from the set of people
089:             * @param person The person to delete
090:             */
091:            public void deletePerson(Person person) {
092:                log.debug("Removing person: " + person);
093:                people.remove(person);
094:                debug();
095:            }
096:
097:            /**
098:             * Create a random person
099:             * @return a random person
100:             */
101:            public static Person getRandomPerson() {
102:                Person person = new Person();
103:                person.setId(getNextId());
104:                person.setName(RandomData.getFullName());
105:                String[] addressAndNumber = RandomData.getAddressAndNumber();
106:                person.setAddress(addressAndNumber[0]);
107:                person.setPhoneNumber(addressAndNumber[1]);
108:                person.setSalary(RandomData.getSalary());
109:                return person;
110:            }
111:
112:            /**
113:             * List the current people so we know what is going on
114:             */
115:            protected void debug() {
116:                for (Person person : people) {
117:                    log.debug(person.toString());
118:                }
119:            }
120:
121:            /**
122:             * Get the next unique ID in a thread safe way
123:             * @return a unique id
124:             */
125:            public static synchronized int getNextId() {
126:                return nextId++;
127:            }
128:
129:            /**
130:             * The next ID, to get around serialization issues
131:             */
132:            private static int nextId = 1;
133:
134:            /**
135:             * the current list of people
136:             */
137:            private List<Person> people = Collections
138:                    .synchronizedList(new ArrayList<Person>());
139:
140:            /**
141:             * The log stream
142:             */
143:            private static final Log log = LogFactory.getLog(People.class);
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.