Coverage Report - org.kuali.rice.core.api.criteria.AbstractCompositePredicate
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractCompositePredicate
56%
14/25
50%
5/10
2.25
AbstractCompositePredicate$Constants
0%
0/1
N/A
2.25
 
 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  1
     private static final String LINE_SEPARATOR = System.getProperty("line.separator");
 34  
 
 35  
     /**
 36  
      * Defines the JAXB annotations for the List of predicates.  All supported predicates *MUST* be
 37  
      * included in this List in order for them to be supported in the XML schema.
 38  
      * 
 39  
      * If a new type of predicate is created it *MUST* be added to this list.
 40  
      */
 41  
         @XmlElements(value = {
 42  
             @XmlElement(name = AndPredicate.Constants.ROOT_ELEMENT_NAME, type = AndPredicate.class, required = true),
 43  
             @XmlElement(name = EqualPredicate.Constants.ROOT_ELEMENT_NAME, type = EqualPredicate.class, required = true),
 44  
             @XmlElement(name = GreaterThanPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanPredicate.class, required = true),
 45  
             @XmlElement(name = GreaterThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanOrEqualPredicate.class, required = true),
 46  
             @XmlElement(name = InPredicate.Constants.ROOT_ELEMENT_NAME, type = InPredicate.class, required = true),
 47  
             @XmlElement(name = LessThanPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanPredicate.class, required = true),
 48  
             @XmlElement(name = LessThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanOrEqualPredicate.class, required = true),
 49  
             @XmlElement(name = LikePredicate.Constants.ROOT_ELEMENT_NAME, type = LikePredicate.class, required = true),
 50  
             @XmlElement(name = NotEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = NotEqualPredicate.class, required = true),
 51  
             @XmlElement(name = NotInPredicate.Constants.ROOT_ELEMENT_NAME, type = NotInPredicate.class, required = true),
 52  
             @XmlElement(name = NotLikePredicate.Constants.ROOT_ELEMENT_NAME, type = NotLikePredicate.class, required = true),
 53  
             @XmlElement(name = NotNullPredicate.Constants.ROOT_ELEMENT_NAME, type = NotNullPredicate.class, required = true),
 54  
             @XmlElement(name = NullPredicate.Constants.ROOT_ELEMENT_NAME, type = NullPredicate.class, required = true),
 55  
             @XmlElement(name = OrPredicate.Constants.ROOT_ELEMENT_NAME, type = OrPredicate.class, required = true)
 56  
     })
 57  
     private final Set<Predicate> predicates;
 58  
 
 59  
         /**
 60  
          * This default constructor exists only to be invoked by sub-classes
 61  
          * in their default constructors which is used by JAXB. 
 62  
          */
 63  20
     AbstractCompositePredicate() {
 64  20
         this.predicates = null;
 65  20
     }
 66  
 
 67  
     /**
 68  
      * When invoked by a subclass, this constructor will set the predicates
 69  
      * to the given set. If the set is null then it will be translated
 70  
      * internally to an empty set.
 71  
      * 
 72  
      * @param predicates the list of predicates to set
 73  
      */
 74  29
     AbstractCompositePredicate(final Set<Predicate> predicates) {
 75  29
         if (predicates == null) {
 76  2
             this.predicates = Collections.emptySet();
 77  
         } else {
 78  27
             final Set<Predicate> temp = new HashSet<Predicate>();
 79  27
             for (Predicate predicate: predicates) {
 80  70
                 if (predicate != null) {
 81  70
                     temp.add(predicate);
 82  
                 }
 83  
             }
 84  27
             this.predicates = Collections.unmodifiableSet(temp);
 85  
         }
 86  29
     }
 87  
 
 88  
     @Override
 89  
     public Set<Predicate> getPredicates() {
 90  15
         return Collections.unmodifiableSet(predicates);
 91  
     }
 92  
 
 93  
     /**
 94  
      * Defines some internal constants used on this class.
 95  
      */
 96  0
     static class Constants {
 97  
         final static String TYPE_NAME = "CompositePredicateType";
 98  
     }
 99  
 
 100  
     @Override
 101  
     public final String toString() {
 102  0
         StringBuilder b = new StringBuilder(CriteriaSupportUtils.findDynName(this.getClass().getSimpleName()));
 103  0
         b.append("(");
 104  0
         if (!predicates.isEmpty()) {
 105  0
             for (Predicate p : predicates) {
 106  0
                 b.append(LINE_SEPARATOR);
 107  
                 //b.append("\t");
 108  0
                 b.append(p);
 109  0
                 b.append(", ");
 110  
             }
 111  0
             b.deleteCharAt(b.lastIndexOf(", "));
 112  0
             b.append(LINE_SEPARATOR);
 113  
         }
 114  0
         b.append(')');
 115  0
         return  b.toString();
 116  
     }
 117  
 }