001/**
002 * Copyright 2011-2013 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015
016package org.kuali.mobility.security.authz.expression;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import org.kuali.mobility.security.user.api.User;
022
023public class OrExpression implements NonLeafExpression {
024
025        private static final long serialVersionUID = -375075043935425839L;
026
027        private List<Expression> children;
028
029        public OrExpression() {
030                children = new ArrayList<Expression>();
031        }
032
033        public boolean evaluate(User user) {
034                for (Expression child : children) {
035                        if (child.evaluate(user)) {
036                                return true;
037                        }
038                }
039                return false;
040        }
041
042        public void addChild(Expression expression) {
043                children.add(expression);
044        }
045
046        private Object readResolve() {
047                if (children == null) {
048                        children = new ArrayList<Expression>();
049                }
050                return this;
051        }
052        
053        @Override
054        public boolean equals(Object obj) {
055                if (obj instanceof OrExpression) {
056                        OrExpression other = (OrExpression)obj;
057                        return children.equals(other.children);
058                }
059                return false;
060        }
061        
062        public List<Expression> getChildren() {
063                return children;
064        }
065        
066}