Source Code Cross Referenced for TimeMap.java in  » J2EE » wicket » wicket » util » time » 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 » J2EE » wicket » wicket.util.time 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*
02:         * $Id: TimeMap.java 455983 2005-02-22 17:48:25Z jonl $ $Revision:
03:         * 1.4 $ $Date: 2005-02-22 18:48:25 +0100 (Tue, 22 Feb 2005) $
04:         * 
05:         * ==============================================================================
06:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07:         * use this file except in compliance with the License. You may obtain a copy of
08:         * the License at
09:         * 
10:         * http://www.apache.org/licenses/LICENSE-2.0
11:         * 
12:         * Unless required by applicable law or agreed to in writing, software
13:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15:         * License for the specific language governing permissions and limitations under
16:         * the License.
17:         */
18:        package wicket.util.time;
19:
20:        import java.util.HashMap;
21:        import java.util.Iterator;
22:        import java.util.Map;
23:
24:        /**
25:         * This class maps ITimeFrames to Objects. Since values are stored using
26:         * ITimeFrameSource implementing objects, the value returned by the source may
27:         * vary over time. For example, one implementation of ITimeFrameSource might
28:         * return the start and end time of lunch on any given day.
29:         * <p>
30:         * To associate an object with a dynamic TimeFrame (via ITimeFrameSource), call
31:         * put(ITimeFrameSource, Object). You can later retrieve the first object for a
32:         * point in time with get(Time). The method get() is provided for convenience
33:         * and is equivalent to get(Time.now()).
34:         * <p>
35:         * This class is not threadsafe.
36:         * 
37:         * @author Jonathan Locke
38:         */
39:        public final class TimeMap {
40:            /** Map from ITimeFrameSource implementing objects to Object values. */
41:            private final Map sources = new HashMap();
42:
43:            /**
44:             * @return Object for the current time
45:             */
46:            public Object get() {
47:                return get(Time.now());
48:            }
49:
50:            /**
51:             * @param time
52:             *            The time
53:             * @return Gets an Object for the given time value or null if none exists
54:             */
55:            public Object get(final Time time) {
56:                for (final Iterator iterator = sources.keySet().iterator(); iterator
57:                        .hasNext();) {
58:                    final TimeFrame current = ((ITimeFrameSource) iterator
59:                            .next()).getTimeFrame();
60:                    if (current.contains(time)) {
61:                        return sources.get(current);
62:                    }
63:                }
64:
65:                return null;
66:            }
67:
68:            /**
69:             * Associates an object with a dynamic time frame
70:             * 
71:             * @param source
72:             *            A source that can produce a timeframe to compare a time value
73:             *            with
74:             * @param o
75:             *            The object to be returned for the given dynamic timeframe
76:             */
77:            public void put(final ITimeFrameSource source, final Object o) {
78:                final TimeFrame timeframe = source.getTimeFrame();
79:
80:                for (final Iterator iterator = sources.keySet().iterator(); iterator
81:                        .hasNext();) {
82:                    final TimeFrame current = ((ITimeFrameSource) iterator
83:                            .next()).getTimeFrame();
84:
85:                    if (timeframe.overlaps(current)) {
86:                        throw new IllegalArgumentException("Timeframe "
87:                                + timeframe + " overlaps timeframe " + current);
88:                    }
89:                }
90:
91:                sources.put(source, o);
92:            }
93:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.