Coverage Report - org.kuali.rice.core.api.criteria.AbstractCompositePredicate
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractCompositePredicate
100%
13/13
83%
5/6
2
AbstractCompositePredicate$Constants
0%
0/1
N/A
2
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation Licensed under the Educational Community License, Version 1.0 (the "License"); you may
 3  
  * not use this file except in compliance with the License. You may obtain a copy of the License at
 4  
  * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law or agreed to in writing, software
 5  
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 6  
  * express or implied. See the License for the specific language governing permissions and limitations under the License.
 7  
  */
 8  
 package org.kuali.rice.core.api.criteria;
 9  
 
 10  
 import javax.xml.bind.annotation.XmlAccessType;
 11  
 import javax.xml.bind.annotation.XmlAccessorType;
 12  
 import javax.xml.bind.annotation.XmlElement;
 13  
 import javax.xml.bind.annotation.XmlElements;
 14  
 import javax.xml.bind.annotation.XmlType;
 15  
 import java.util.Collections;
 16  
 import java.util.HashSet;
 17  
 import java.util.Set;
 18  
 
 19  
 /**
 20  
  * An abstract implementation of a {@link CompositePredicate}.  This class defines all of the JAXB
 21  
  * annotations such that sub-classes should not have to.
 22  
  * 
 23  
  * <p>If a class subclasses this class then it *MUST* be sure to add itself to the JAXB
 24  
  * annotations for {@link #predicates}
 25  
  * 
 26  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 27  
  */
 28  
 @XmlAccessorType(XmlAccessType.NONE)
 29  
 @XmlType(name = AbstractCompositePredicate.Constants.TYPE_NAME)
 30  
 abstract class AbstractCompositePredicate extends AbstractPredicate implements CompositePredicate {
 31  
 
 32  
     private static final long serialVersionUID = 6164560054223588779L;
 33  
     
 34  
     /**
 35  
      * Defines the JAXB annotations for the List of predicates.  All supported predicates *MUST* be
 36  
      * included in this List in order for them to be supported in the XML schema.
 37  
      * 
 38  
      * If a new type of predicate is created it *MUST* be added to this list.
 39  
      */
 40  
         @XmlElements(value = {
 41  
             @XmlElement(name = AndPredicate.Constants.ROOT_ELEMENT_NAME, type = AndPredicate.class, required = true),
 42  
             @XmlElement(name = EqualPredicate.Constants.ROOT_ELEMENT_NAME, type = EqualPredicate.class, required = true),
 43  
             @XmlElement(name = GreaterThanPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanPredicate.class, required = true),
 44  
             @XmlElement(name = GreaterThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanOrEqualPredicate.class, required = true),
 45  
             @XmlElement(name = InPredicate.Constants.ROOT_ELEMENT_NAME, type = InPredicate.class, required = true),
 46  
             @XmlElement(name = LessThanPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanPredicate.class, required = true),
 47  
             @XmlElement(name = LessThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanOrEqualPredicate.class, required = true),
 48  
             @XmlElement(name = LikePredicate.Constants.ROOT_ELEMENT_NAME, type = LikePredicate.class, required = true),
 49  
             @XmlElement(name = NotEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = NotEqualPredicate.class, required = true),
 50  
             @XmlElement(name = NotInPredicate.Constants.ROOT_ELEMENT_NAME, type = NotInPredicate.class, required = true),
 51  
             @XmlElement(name = NotLikePredicate.Constants.ROOT_ELEMENT_NAME, type = NotLikePredicate.class, required = true),
 52  
             @XmlElement(name = NotNullPredicate.Constants.ROOT_ELEMENT_NAME, type = NotNullPredicate.class, required = true),
 53  
             @XmlElement(name = NullPredicate.Constants.ROOT_ELEMENT_NAME, type = NullPredicate.class, required = true),
 54  
             @XmlElement(name = OrPredicate.Constants.ROOT_ELEMENT_NAME, type = OrPredicate.class, required = true)
 55  
     })
 56  
     private final Set<Predicate> predicates;
 57  
 
 58  
         /**
 59  
          * This default constructor exists only to be invoked by sub-classes
 60  
          * in their default constructors which is used by JAXB. 
 61  
          */
 62  20
     AbstractCompositePredicate() {
 63  20
         this.predicates = null;
 64  20
     }
 65  
 
 66  
     /**
 67  
      * When invoked by a subclass, this constructor will set the predicates
 68  
      * to the given set. If the set is null then it will be translated
 69  
      * internally to an empty set.
 70  
      * 
 71  
      * @param predicates the list of predicates to set
 72  
      */
 73  29
     AbstractCompositePredicate(final Set<Predicate> predicates) {
 74  29
         if (predicates == null) {
 75  2
             this.predicates = Collections.emptySet();
 76  
         } else {
 77  27
             final Set<Predicate> temp = new HashSet<Predicate>();
 78  27
             for (Predicate predicate: predicates) {
 79  70
                 if (predicate != null) {
 80  70
                     temp.add(predicate);
 81  
                 }
 82  
             }
 83  27
             this.predicates = Collections.unmodifiableSet(temp);
 84  
         }
 85  29
     }
 86  
 
 87  
     @Override
 88  
     public Set<Predicate> getPredicates() {
 89  15
         return Collections.unmodifiableSet(predicates);
 90  
     }
 91  
 
 92  
     /**
 93  
      * Defines some internal constants used on this class.
 94  
      */
 95  0
     static class Constants {
 96  
         final static String TYPE_NAME = "CompositePredicateType";
 97  
     }
 98  
 
 99  
 }