Coverage Report - org.kuali.rice.core.api.criteria.NotInPredicate
 
Classes in this File Line Coverage Branch Coverage Complexity
NotInPredicate
90%
20/22
75%
6/8
2
NotInPredicate$Constants
0%
0/1
N/A
2
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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 org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.CoreConstants;
 20  
 import org.w3c.dom.Element;
 21  
 
 22  
 import javax.xml.bind.annotation.XmlAccessType;
 23  
 import javax.xml.bind.annotation.XmlAccessorType;
 24  
 import javax.xml.bind.annotation.XmlAnyElement;
 25  
 import javax.xml.bind.annotation.XmlAttribute;
 26  
 import javax.xml.bind.annotation.XmlElement;
 27  
 import javax.xml.bind.annotation.XmlElements;
 28  
 import javax.xml.bind.annotation.XmlRootElement;
 29  
 import javax.xml.bind.annotation.XmlType;
 30  
 import java.util.Collection;
 31  
 import java.util.Collections;
 32  
 import java.util.HashSet;
 33  
 import java.util.Set;
 34  
 
 35  
 /**
 36  
  * An immutable predicate which represents a "not in" statement which is
 37  
  * evaluated against a list of values.
 38  
  * 
 39  
  * @see PredicateFactory for a convenient way to construct this class.
 40  
  * 
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  */
 43  36
 @XmlRootElement(name = NotInPredicate.Constants.ROOT_ELEMENT_NAME)
 44  
 @XmlAccessorType(XmlAccessType.NONE)
 45  
 @XmlType(name = NotInPredicate.Constants.TYPE_NAME, propOrder = {
 46  
     CriteriaSupportUtils.PropertyConstants.VALUES,
 47  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 48  
 })
 49  
 public final class NotInPredicate extends AbstractPredicate implements MultiValuedPredicate {
 50  
 
 51  
         private static final long serialVersionUID = -7676442296587603655L;
 52  
         
 53  
         @XmlAttribute(name = CriteriaSupportUtils.PropertyConstants.PROPERTY_PATH)
 54  
         private final String propertyPath;
 55  
 
 56  
         @XmlElements(value = {
 57  
             @XmlElement(name = CriteriaStringValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaStringValue.class, required = true),
 58  
             @XmlElement(name = CriteriaDateTimeValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaDateTimeValue.class, required = true),
 59  
             @XmlElement(name = CriteriaIntegerValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaIntegerValue.class, required = true),
 60  
             @XmlElement(name = CriteriaDecimalValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaDecimalValue.class, required = true)
 61  
         })
 62  
         private final Set<? extends CriteriaValue<?>> values;
 63  
 
 64  39
     @SuppressWarnings("unused")
 65  
     @XmlAnyElement
 66  
     private final Collection<Element> _futureElements = null;
 67  
 
 68  
         /**
 69  
      * Should only be invoked by JAXB.
 70  
      */
 71  
     @SuppressWarnings("unused")
 72  12
     private NotInPredicate() {
 73  12
         this.propertyPath = null;
 74  12
         this.values = null;
 75  12
     }
 76  
     
 77  
     /**
 78  
          * Constructs a NotInPredicate for the given propertyPath and list of criteria values.
 79  
          * 
 80  
          * @param propertyPath the property path for the predicate, must not be null or blank
 81  
          * @param values the list of criteria values to use for this predicate, must be non-null,
 82  
          * non-empty, and all CriteriaValues contained within must be of the same type.
 83  
          * 
 84  
          * @throws IllegalArgumentException if the propertyPath is null or blank
 85  
          * @throws IllegalArgumentException if the list of values is null, empty, or contains {@link CriteriaValue} of different types
 86  
          */
 87  27
     NotInPredicate(String propertyPath, Set<? extends CriteriaValue<?>> values) {
 88  27
             if (StringUtils.isBlank(propertyPath)) {
 89  2
                         throw new IllegalArgumentException("Property path cannot be null or blank.");
 90  
                 }
 91  25
             CriteriaSupportUtils.validateValuesForMultiValuedPredicate(values);
 92  20
                 this.propertyPath = propertyPath;
 93  
 
 94  20
         if (values == null) {
 95  0
             this.values = Collections.emptySet();
 96  
         } else {
 97  20
             final Set<CriteriaValue<?>> temp = new HashSet<CriteriaValue<?>>();
 98  20
             for (CriteriaValue<?> value: values) {
 99  57
                 if (value != null) {
 100  57
                     temp.add(value);
 101  
                 }
 102  
             }
 103  20
             this.values = Collections.unmodifiableSet(temp);
 104  
         }
 105  20
     }
 106  
 
 107  
     @Override
 108  
     public String getPropertyPath() {
 109  4
             return propertyPath;
 110  
     }
 111  
     
 112  
     @Override
 113  
     public Set<CriteriaValue<?>> getValues() {
 114  8
             return Collections.unmodifiableSet(values);
 115  
     }
 116  
         
 117  
         /**
 118  
      * Defines some internal constants used on this class.
 119  
      */
 120  0
     static class Constants {
 121  
         final static String ROOT_ELEMENT_NAME = "notIn";
 122  
         final static String TYPE_NAME = "NotInType";
 123  
     }
 124  
 
 125  
     @Override
 126  
     public String toString() {
 127  0
         return CriteriaSupportUtils.toString(this);
 128  
     }
 129  
 }