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


001:        /*
002:         * JFox - The most lightweight Java EE Application Server!
003:         * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
004:         *
005:         * JFox is licenced and re-distributable under GNU LGPL.
006:         */
007:        package org.jfox.util;
008:
009:        import java.io.File;
010:        import java.io.FileFilter;
011:        import java.util.regex.Pattern;
012:
013:        /**
014:         * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
015:         */
016:
017:        public class FileFilterUtils {
018:
019:            /**
020:             * FileFilterUtils is not normally instantiated.
021:             */
022:            private FileFilterUtils() {
023:
024:            }
025:
026:            public static FileFilter prefixFileFilter(final String... prefixes) {
027:                return new FileFilter() {
028:                    public boolean accept(File pathname) {
029:                        for (String prefix : prefixes) {
030:                            if (pathname.getName().startsWith(prefix)) {
031:                                return true;
032:                            }
033:                        }
034:                        return false;
035:                    }
036:                };
037:
038:            }
039:
040:            public static FileFilter suffixFileFilter(final String... suffixes) {
041:                return new FileFilter() {
042:                    public boolean accept(File pathname) {
043:                        for (String suffix : suffixes) {
044:                            if (pathname.getName().endsWith(suffix)) {
045:                                return true;
046:                            }
047:                        }
048:                        return false;
049:                    }
050:                };
051:            }
052:
053:            /**
054:             * Returns a filter that returns true if the filename matches the specified
055:             * text.
056:             *
057:             * @param name the filename
058:             * @return a name checking filter
059:             */
060:            public static FileFilter nameFileFilter(final String name) {
061:                return new FileFilter() {
062:                    public boolean accept(File pathname) {
063:                        return pathname.getName().equals(name);
064:                    }
065:                };
066:            }
067:
068:            public static FileFilter regexFileFile(final String regex) {
069:                return new FileFilter() {
070:                    public boolean accept(File pathname) {
071:                        return Pattern.matches(regex, pathname.getName());
072:                    }
073:                };
074:            }
075:
076:            /**
077:             * Returns a filter that checks if the file is a directory.
078:             *
079:             * @return directory file filter
080:             */
081:            public static FileFilter directoryFileFilter() {
082:                return new FileFilter() {
083:                    public boolean accept(File pathname) {
084:                        return pathname.isDirectory();
085:                    }
086:                };
087:            }
088:
089:            public static FileFilter sizeLtFileFilter(final long size) {
090:                return new FileFilter() {
091:                    public boolean accept(File pathname) {
092:                        return pathname.length() < size;
093:                    }
094:                };
095:            }
096:
097:            public static FileFilter sizeGtFileFilter(final long size) {
098:                return new FileFilter() {
099:                    public boolean accept(File pathname) {
100:                        return pathname.length() > size;
101:                    }
102:                };
103:            }
104:
105:            public static FileFilter sizeEqualFileFilter(final long size) {
106:                return new FileFilter() {
107:                    public boolean accept(File pathname) {
108:                        return pathname.length() == size;
109:                    }
110:                };
111:            }
112:
113:            // -----------------------------------------------------------------------
114:
115:            /**
116:             * Returns a filter that ANDs the two specified filters.
117:             *
118:             * @param filters and filters
119:             * @return a filter that ANDs the two specified filters
120:             */
121:            public static FileFilter and(final FileFilter... filters) {
122:                return new FileFilter() {
123:                    public boolean accept(File pathname) {
124:                        boolean result = true;
125:                        for (FileFilter filter : filters) {
126:                            result = result && filter.accept(pathname);
127:                        }
128:                        return result;
129:                    }
130:                };
131:            }
132:
133:            /**
134:             * Returns a filter that ORs the two specified filters.
135:             *
136:             * @param filters or filters
137:             * @return a filter that ORs the two specified filters
138:             */
139:            public static FileFilter or(final FileFilter... filters) {
140:                return new FileFilter() {
141:                    public boolean accept(File pathname) {
142:                        boolean result = false;
143:                        for (FileFilter filter : filters) {
144:                            result = (result || filter.accept(pathname));
145:                        }
146:                        return result;
147:                    }
148:                };
149:            }
150:
151:            /**
152:             * Returns a filter that NOTs the specified filter.
153:             *
154:             * @param filter the filter to invert
155:             * @return a filter that NOTs the specified filter
156:             */
157:            public static FileFilter not(final FileFilter filter) {
158:                return new FileFilter() {
159:                    public boolean accept(File pathname) {
160:                        return !filter.accept(pathname);
161:                    }
162:                };
163:            }
164:
165:            public static void main(String[] args) {
166:
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.