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