Source Code Cross Referenced for AnyPredicate.java in  » Library » Apache-common-Collections » org » apache » commons » collections » functors » 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 » Library » Apache common Collections » org.apache.commons.collections.functors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2001-2004,2006 The Apache Software Foundation
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.apache.commons.collections.functors;
017:
018:        import java.io.Serializable;
019:        import java.util.Collection;
020:
021:        import org.apache.commons.collections.Predicate;
022:
023:        /**
024:         * Predicate implementation that returns true if any of the
025:         * predicates return true.
026:         * If the array of predicates is empty, then this predicate returns false.
027:         * <p>
028:         * NOTE: In versions prior to 3.2 an array size of zero or one
029:         * threw an exception.
030:         *
031:         * @since Commons Collections 3.0
032:         * @version $Revision: 406071 $ $Date: 2006-05-13 11:44:37 +0100 (Sat, 13 May 2006) $
033:         *
034:         * @author Stephen Colebourne
035:         * @author Matt Benson
036:         */
037:        public final class AnyPredicate implements  Predicate,
038:                PredicateDecorator, Serializable {
039:
040:            /** Serial version UID */
041:            private static final long serialVersionUID = 7429999530934647542L;
042:
043:            /** The array of predicates to call */
044:            private final Predicate[] iPredicates;
045:
046:            /**
047:             * Factory to create the predicate.
048:             * <p>
049:             * If the array is size zero, the predicate always returns false.
050:             * If the array is size one, then that predicate is returned.
051:             *
052:             * @param predicates  the predicates to check, cloned, not null
053:             * @return the <code>any</code> predicate
054:             * @throws IllegalArgumentException if the predicates array is null
055:             * @throws IllegalArgumentException if any predicate in the array is null
056:             */
057:            public static Predicate getInstance(Predicate[] predicates) {
058:                FunctorUtils.validate(predicates);
059:                if (predicates.length == 0) {
060:                    return FalsePredicate.INSTANCE;
061:                }
062:                if (predicates.length == 1) {
063:                    return predicates[0];
064:                }
065:                return new AnyPredicate(FunctorUtils.copy(predicates));
066:            }
067:
068:            /**
069:             * Factory to create the predicate.
070:             * <p>
071:             * If the collection is size zero, the predicate always returns false.
072:             * If the collection is size one, then that predicate is returned.
073:             *
074:             * @param predicates  the predicates to check, cloned, not null
075:             * @return the <code>all</code> predicate
076:             * @throws IllegalArgumentException if the predicates array is null
077:             * @throws IllegalArgumentException if any predicate in the array is null
078:             */
079:            public static Predicate getInstance(Collection predicates) {
080:                Predicate[] preds = FunctorUtils.validate(predicates);
081:                if (preds.length == 0) {
082:                    return FalsePredicate.INSTANCE;
083:                }
084:                if (preds.length == 1) {
085:                    return preds[0];
086:                }
087:                return new AnyPredicate(preds);
088:            }
089:
090:            /**
091:             * Constructor that performs no validation.
092:             * Use <code>getInstance</code> if you want that.
093:             * 
094:             * @param predicates  the predicates to check, not cloned, not null
095:             */
096:            public AnyPredicate(Predicate[] predicates) {
097:                super ();
098:                iPredicates = predicates;
099:            }
100:
101:            /**
102:             * Evaluates the predicate returning true if any predicate returns true.
103:             * 
104:             * @param object  the input object
105:             * @return true if any decorated predicate return true
106:             */
107:            public boolean evaluate(Object object) {
108:                for (int i = 0; i < iPredicates.length; i++) {
109:                    if (iPredicates[i].evaluate(object)) {
110:                        return true;
111:                    }
112:                }
113:                return false;
114:            }
115:
116:            /**
117:             * Gets the predicates, do not modify the array.
118:             * 
119:             * @return the predicates
120:             * @since Commons Collections 3.1
121:             */
122:            public Predicate[] getPredicates() {
123:                return iPredicates;
124:            }
125:
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.