Source Code Cross Referenced for StatementFormat.java in  » Code-Analyzer » importscrubber » net » sourceforge » importscrubber » 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 » Code Analyzer » importscrubber » net.sourceforge.importscrubber 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.importscrubber;
002:
003:        import java.util.*;
004:
005:        public class StatementFormat {
006:            public static final int BREAK_EACH_PACKAGE = 0;
007:            public static final int BREAK_NONE = 1;
008:
009:            private static List _formats = new ArrayList(2);
010:
011:            static {
012:                ResourceBundle res = ResourceBundle
013:                        .getBundle("net.sourceforge.importscrubber.Resources");
014:                _formats.add(res.getString(Resources.BREAK_EACH_PACKAGE));
015:                _formats.add(res.getString(Resources.BREAK_NONE));
016:            }
017:
018:            public static Object keyToValue(int key) {
019:                return _formats.get(key);
020:            }
021:
022:            public static int valueToKey(Object value) {
023:                return _formats.indexOf(value);
024:            }
025:
026:            public static Iterator formatIterator() {
027:                return _formats.iterator();
028:            }
029:
030:            // get a description of args understood by getFormat
031:            public static String getUsage() {
032:                return "-sortJavaLibsHigh: place 'import java...' statements at the top [default: off]\n"
033:                        + "-combineThreshold <integer>: import * from a package when MORE THAN this number of imports are found [default: 0 = off]\n"
034:                        + "-thresholdStandardOnly: apply combineThreshold only to java standard library; other packages will continue to import individual classes no matter how many are used [default: off]\n"
035:                        + "-breakEachPackage: linebreak after the imports from each package [default: off]\n";
036:            }
037:
038:            // arg parsing done here to make it easier for others to add new features
039:            public static StatementFormat getFormat(String[] args) {
040:                int breakStyle = BREAK_NONE;
041:                int combineThreshold = 0;
042:                boolean sortJavaLibsHigh = ImportScrubber.argExists(
043:                        "sortjavalibshigh", args);
044:                boolean thresholdStandardOnly = ImportScrubber.argExists(
045:                        "thresholdStandardOnly", args);
046:                if (ImportScrubber.argExists("combineThreshold", args)) {
047:                    combineThreshold = new Integer(ImportScrubber.findArg(
048:                            "combineThreshold", args)).intValue();
049:                }
050:                if (ImportScrubber.argExists("breakEachPackage", args)) {
051:                    breakStyle = BREAK_EACH_PACKAGE;
052:                }
053:
054:                return new StatementFormat(sortJavaLibsHigh, breakStyle,
055:                        combineThreshold, thresholdStandardOnly);
056:            }
057:
058:            //
059:            // the actual format stuff
060:
061:            private boolean _sortJavaLibsHigh;
062:            private int _breakStyle;
063:            private int _combineThreshold;
064:            private boolean _thresholdStandardOnly; // true if threshold should only apply to standard libraries
065:            private List identical; // for applyFormat -- stored here so we avoid re-allocating each time
066:
067:            public StatementFormat(boolean sortJavaLibsHigh, int breakStyle,
068:                    int combineThreshold, boolean thresholdStandardOnly) {
069:                _sortJavaLibsHigh = sortJavaLibsHigh;
070:                _breakStyle = breakStyle;
071:                _combineThreshold = combineThreshold;
072:                _thresholdStandardOnly = thresholdStandardOnly;
073:                identical = new ArrayList(_combineThreshold);
074:            }
075:
076:            public StringBuffer applyFormat(List list) {
077:                Collections.sort(list, new ImportStatementComparator(
078:                        _sortJavaLibsHigh));
079:
080:                // pre-process the threshold requirement
081:                if (_combineThreshold > 0) {
082:                    List oldList = list;
083:                    list = new ArrayList();
084:                    String lastPackage = null;
085:                    identical.clear();
086:                    for (Iterator i = oldList.iterator(); i.hasNext();) {
087:                        ImportStatement stmt = (ImportStatement) i.next();
088:                        if (lastPackage == null
089:                                || lastPackage.compareTo(stmt.getPackage()) != 0) {
090:                            if (identical.size() > _combineThreshold) {
091:                                list
092:                                        .add(new ImportStatement(lastPackage
093:                                                + ".*"));
094:                            } else {
095:                                list.addAll(identical);
096:                            }
097:                            identical.clear();
098:                            lastPackage = stmt.getPackage();
099:                        }
100:                        if (_thresholdStandardOnly
101:                                && !(stmt.isInStdJavaLibrary() || stmt
102:                                        .isInStdJavaExtensionLibrary())) {
103:                            list.add(stmt);
104:                        } else {
105:                            identical.add(stmt);
106:                        }
107:                    }
108:                    if (identical.size() > _combineThreshold) {
109:                        list.add(new ImportStatement(lastPackage + ".*"));
110:                    } else {
111:                        list.addAll(identical);
112:                    }
113:                }
114:
115:                StringBuffer result = new StringBuffer();
116:                ImportStatement last = null;
117:                for (Iterator i = list.iterator(); i.hasNext();) {
118:                    ImportStatement next = (ImportStatement) i.next();
119:                    if (_breakStyle == BREAK_EACH_PACKAGE) {
120:                        if (last != null
121:                                && !last.getPackage().equals(next.getPackage())) {
122:                            result.append(ImportScrubber.LINE_SEPARATOR);
123:                        }
124:                    }
125:                    last = next;
126:                    result.append(next.getFormattedStmt());
127:                }
128:                return result;
129:            }
130:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.