Source Code Cross Referenced for BasicCompositeConstraint.java in  » Database-ORM » MMBase » org » mmbase » storage » search » implementation » 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 » Database ORM » MMBase » org.mmbase.storage.search.implementation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.storage.search.implementation;
011:
012:        import java.util.*;
013:        import org.mmbase.storage.search.*;
014:        import org.mmbase.util.logging.*;
015:
016:        /**
017:         * Basic implementation.
018:         *
019:         * @author Rob van Maris
020:         * @version $Id: BasicCompositeConstraint.java,v 1.10 2007/02/11 14:46:13 nklasens Exp $
021:         * @since MMBase-1.7
022:         */
023:        public class BasicCompositeConstraint extends BasicConstraint implements 
024:                CompositeConstraint {
025:            private static final Logger log = Logging
026:                    .getLoggerInstance(BasicCompositeConstraint.class);
027:
028:            /** The child constraints. */
029:            private List<Constraint> childs = new ArrayList<Constraint>();
030:
031:            /** The logical operator. */
032:            private int logicalOperator = 0;
033:
034:            /**
035:             * Constructor.
036:             *
037:             * @param logicalOperator The logical operator.
038:             * @throws IllegalArgumentException when an invalid argument is supplied.
039:             */
040:            public BasicCompositeConstraint(int logicalOperator) {
041:                // Invalid argument, must be either LOGICAL_AND or LOGICAL_OR.
042:                if (logicalOperator != CompositeConstraint.LOGICAL_AND
043:                        && logicalOperator != CompositeConstraint.LOGICAL_OR) {
044:                    throw new IllegalArgumentException(
045:                            ("Invalid argument: " + logicalOperator
046:                                    + ", must be either "
047:                                    + CompositeConstraint.LOGICAL_AND + " or " + CompositeConstraint.LOGICAL_OR));
048:                }
049:                this .logicalOperator = logicalOperator;
050:            }
051:
052:            /**
053:             * Adds new child constraint.
054:             *
055:             * @param child The child constraint.
056:             * @return This <code>BasicCompositeConstraint</code> instance.
057:             * @throws IllegalArgumentException when an invalid argument is supplied.
058:             */
059:            public BasicCompositeConstraint addChild(Constraint child) {
060:                if (child == null) {
061:                    throw new IllegalArgumentException(
062:                            "Invalid child argument: " + child);
063:                }
064:                // Check constraint not added to itself.
065:                if (child == this ) {
066:                    throw new IllegalArgumentException(
067:                            "Trying to add constraint as child to itself: "
068:                                    + child);
069:                }
070:                childs.add(child);
071:                return this ;
072:            }
073:
074:            public BasicCompositeConstraint removeChild(Constraint child) {
075:                if (!childs.remove(child)) {
076:                    log.info("Tried to remove non existing child");
077:                }
078:                return this ;
079:            }
080:
081:            // javadoc is inherited
082:            public List<Constraint> getChilds() {
083:                // return a unmodifiable list
084:                return Collections.unmodifiableList(childs);
085:            }
086:
087:            // javadoc is inherited
088:            public int getLogicalOperator() {
089:                return logicalOperator;
090:            }
091:
092:            /**
093:             * Returns a description of the logical operator
094:             */
095:            public String getLogicalOperatorDescription() {
096:                try {
097:                    return CompositeConstraint.LOGICAL_OPERATOR_DESCRIPTIONS[logicalOperator];
098:                } catch (IndexOutOfBoundsException ioobe) {
099:                    return null;
100:                }
101:            }
102:
103:            // javadoc is inherited
104:            public int getBasicSupportLevel() {
105:                // Calculate support as lowest value among childs.
106:                int result = SearchQueryHandler.SUPPORT_OPTIMAL;
107:                Iterator<Constraint> iChilds = childs.iterator();
108:                while (iChilds.hasNext()) {
109:                    Constraint constraint = iChilds.next();
110:                    int support = constraint.getBasicSupportLevel();
111:                    if (support < result) {
112:                        result = support;
113:                        // Stop iteration when a not supported child constraint is found.
114:                        if (result == SearchQueryHandler.SUPPORT_NONE) {
115:                            break;
116:                        }
117:                    }
118:                }
119:                return result;
120:            }
121:
122:            // javadoc is inherited
123:            public boolean equals(Object obj) {
124:                if (obj == this ) {
125:                    return true;
126:                }
127:                if (obj instanceof  CompositeConstraint) {
128:                    CompositeConstraint constraint = (CompositeConstraint) obj;
129:                    return isInverse() == constraint.isInverse()
130:                            && logicalOperator == constraint
131:                                    .getLogicalOperator()
132:                            && childs.equals(constraint.getChilds());
133:                    // XXX should order of childs matter (it does now)?
134:                } else {
135:                    return false;
136:                }
137:            }
138:
139:            // javadoc is inherited
140:            public int hashCode() {
141:                return super .hashCode() + 109 * logicalOperator + 71
142:                        * childs.hashCode();
143:            }
144:
145:            // javadoc is inherited
146:            public String toString() {
147:                StringBuilder sb = new StringBuilder(
148:                        "CompositeConstraint(inverse:").append(isInverse())
149:                        .append(", operator:").append(
150:                                getLogicalOperatorDescription()).append(
151:                                ", childs:").append(getChilds()).append(")");
152:                return sb.toString();
153:            }
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.