Source Code Cross Referenced for DateField.java in  » Net » lucene-connector » org » apache » lucene » document » 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 » Net » lucene connector » org.apache.lucene.document 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.lucene.document;
002:
003:        /**
004:         * Licensed to the Apache Software Foundation (ASF) under one or more
005:         * contributor license agreements.  See the NOTICE file distributed with
006:         * this work for additional information regarding copyright ownership.
007:         * The ASF licenses this file to You under the Apache License, Version 2.0
008:         * (the "License"); you may not use this file except in compliance with
009:         * the License.  You may obtain a copy of the License at
010:         *
011:         *     http://www.apache.org/licenses/LICENSE-2.0
012:         *
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License.
018:         */
019:
020:        import org.apache.lucene.search.PrefixQuery;
021:        import org.apache.lucene.search.RangeQuery;
022:
023:        import java.util.Date; // for javadoc
024:
025:        /**
026:         * Provides support for converting dates to strings and vice-versa.
027:         * The strings are structured so that lexicographic sorting orders by date,
028:         * which makes them suitable for use as field values and search terms.
029:         *
030:         * <P>Note that this class saves dates with millisecond granularity,
031:         * which is bad for {@link RangeQuery} and {@link PrefixQuery}, as those
032:         * queries are expanded to a BooleanQuery with a potentially large number
033:         * of terms when searching. Thus you might want to use
034:         * {@link DateTools} instead.
035:         *
036:         * <P>
037:         * Note: dates before 1970 cannot be used, and therefore cannot be
038:         * indexed when using this class. See {@link DateTools} for an
039:         * alternative without such a limitation.
040:         *
041:         * @deprecated If you build a new index, use {@link DateTools} instead. This class is included for use with existing
042:         * indices and will be removed in a future release.
043:         */
044:        public class DateField {
045:
046:            private DateField() {
047:            }
048:
049:            // make date strings long enough to last a millenium
050:            private static int DATE_LEN = Long.toString(
051:                    1000L * 365 * 24 * 60 * 60 * 1000, Character.MAX_RADIX)
052:                    .length();
053:
054:            public static String MIN_DATE_STRING() {
055:                return timeToString(0);
056:            }
057:
058:            public static String MAX_DATE_STRING() {
059:                char[] buffer = new char[DATE_LEN];
060:                char c = Character.forDigit(Character.MAX_RADIX - 1,
061:                        Character.MAX_RADIX);
062:                for (int i = 0; i < DATE_LEN; i++)
063:                    buffer[i] = c;
064:                return new String(buffer);
065:            }
066:
067:            /**
068:             * Converts a Date to a string suitable for indexing.
069:             * @throws RuntimeException if the date specified in the
070:             * method argument is before 1970
071:             */
072:            public static String dateToString(Date date) {
073:                return timeToString(date.getTime());
074:            }
075:
076:            /**
077:             * Converts a millisecond time to a string suitable for indexing.
078:             * @throws RuntimeException if the time specified in the
079:             * method argument is negative, that is, before 1970
080:             */
081:            public static String timeToString(long time) {
082:                if (time < 0)
083:                    throw new RuntimeException("time '" + time
084:                            + "' is too early, must be >= 0");
085:
086:                String s = Long.toString(time, Character.MAX_RADIX);
087:
088:                if (s.length() > DATE_LEN)
089:                    throw new RuntimeException("time '" + time
090:                            + "' is too late, length of string "
091:                            + "representation must be <= " + DATE_LEN);
092:
093:                // Pad with leading zeros
094:                if (s.length() < DATE_LEN) {
095:                    StringBuffer sb = new StringBuffer(s);
096:                    while (sb.length() < DATE_LEN)
097:                        sb.insert(0, 0);
098:                    s = sb.toString();
099:                }
100:
101:                return s;
102:            }
103:
104:            /** Converts a string-encoded date into a millisecond time. */
105:            public static long stringToTime(String s) {
106:                return Long.parseLong(s, Character.MAX_RADIX);
107:            }
108:
109:            /** Converts a string-encoded date into a Date object. */
110:            public static Date stringToDate(String s) {
111:                return new Date(stringToTime(s));
112:            }
113:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.