Source Code Cross Referenced for yFormatter.java in  » Search-Engine » yacy » de » anomic » tools » 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 » Search Engine » yacy » de.anomic.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // yFormatter.java 
002:        // -----------------------
003:        // part of YACY
004:        // (C) by Michael Peter Christen; mc@anomic.de
005:        // first published on http://www.anomic.de
006:        // Frankfurt, Germany, 2004
007:        //
008:        // (C) 2007 Bjoern 'Fuchs' Krombholz; fox.box@gmail.com
009:        //
010:        // This program is free software; you can redistribute it and/or modify
011:        // it under the terms of the GNU General Public License as published by
012:        // the Free Software Foundation; either version 2 of the License, or
013:        // (at your option) any later version.
014:        //
015:        // This program is distributed in the hope that it will be useful,
016:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
017:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
018:        // GNU General Public License for more details.
019:        //
020:        // You should have received a copy of the GNU General Public License
021:        // along with this program; if not, write to the Free Software
022:        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
023:        //
024:        // Using this software in any meaning (reading, learning, copying, compiling,
025:        // running) means that you agree that the Author(s) is (are) not responsible
026:        // for cost, loss of data or any harm that may be caused directly or indirectly
027:        // by usage of this softare or this documentation. The usage of this software
028:        // is on your own risk. The installation and usage (starting/running) of this
029:        // software may allow other people or application to access your computer and
030:        // any attached devices and is highly dependent on the configuration of the
031:        // software which must be done by the user of the software; the author(s) is
032:        // (are) also not responsible for proper configuration and usage of the
033:        // software, even if provoked by documentation provided together with
034:        // the software.
035:        //
036:        // Any changes to this file according to the GPL as documented in the file
037:        // gpl.txt aside this file in the shipment you received can be done to the
038:        // lines that follows this copyright notice here, but changes must not be
039:        // done inside the copyright notive above. A re-distribution must contain
040:        // the intact and unchanged copyright notice.
041:        // Contributions and changes to the program code must be marked as such.
042:        package de.anomic.tools;
043:
044:        import java.text.DecimalFormat;
045:        import java.text.DecimalFormatSymbols;
046:        import java.text.NumberFormat;
047:        import java.util.Locale;
048:
049:        /**
050:         * This class provides simple Formatters to unify YaCy's output
051:         * formattings.
052:         *
053:         * At the moment yFormatter can be used to format numbers according
054:         * to the locale set for YaCy.
055:         */
056:        public final class yFormatter {
057:            // default formatter
058:            private static NumberFormat numForm = NumberFormat
059:                    .getInstance(new Locale("en"));
060:
061:            // generic formatter that can be used when no localized formatting is allowed
062:            private static final NumberFormat cleanNumForm = new DecimalFormat(
063:                    "####.##", new DecimalFormatSymbols(Locale.ENGLISH));
064:
065:            static {
066:                // just initialize defaults on class load
067:                initDefaults();
068:            }
069:
070:            /**
071:             * @param locale the {@link Locale} to set or <code>null</code> to set the special
072:             * empty locale to create unformatted numbers
073:             */
074:            public static void setLocale(Locale locale) {
075:                numForm = (locale == null ? cleanNumForm : NumberFormat
076:                        .getInstance(locale));
077:                initDefaults();
078:            }
079:
080:            /**
081:             * @param lang an ISO 639 language code which is used to generate a {@link Locale}
082:             */
083:            public static void setLocale(String lang) {
084:                String l = (lang.equalsIgnoreCase("default") ? "en" : lang
085:                        .toLowerCase());
086:
087:                setLocale(l.equals("none") ? null : new Locale(l));
088:            }
089:
090:            private static void initDefaults() {
091:                numForm.setGroupingUsed(true); // always group int digits
092:                numForm.setParseIntegerOnly(false); // allow int/double/float
093:                numForm.setMaximumFractionDigits(2); // 2 decimal digits for float/double
094:            }
095:
096:            public static String number(double d, boolean localized) {
097:                return (localized ? number(d) : cleanNumForm.format(d));
098:            }
099:
100:            public static String number(double d) {
101:                return numForm.format(d);
102:            }
103:
104:            public static String number(long l, boolean localized) {
105:                return (localized ? number(l) : cleanNumForm.format(l));
106:            }
107:
108:            public static String number(long l) {
109:                return numForm.format(l);
110:            }
111:
112:            /**
113:             * Method formats String representation of numbers according to the formatting
114:             * rules for numbers defined by this class. This method is probably only useful
115:             * for "numbers" read from property files.
116:             * @param s string to parse into a number and reformat
117:             * @return the formatted number as a String or "-" in case of a parsing error
118:             */
119:            public static String number(String s) {
120:                String ret = null;
121:                try {
122:                    if (s.indexOf('.') == -1) {
123:                        ret = number(Long.parseLong(s));
124:                    } else {
125:                        ret = number(Double.parseDouble(s));
126:                    }
127:                } catch (NumberFormatException e) { /* empty */
128:                }
129:
130:                return (ret == null ? "-" : ret);
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.