Coverage Report - org.kuali.rice.core.api.criteria.InExpression
 
Classes in this File Line Coverage Branch Coverage Complexity
InExpression
100%
14/14
100%
2/2
1.5
InExpression$Constants
0%
0/1
N/A
1.5
 
 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 java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import javax.xml.bind.annotation.XmlAccessType;
 22  
 import javax.xml.bind.annotation.XmlAccessorType;
 23  
 import javax.xml.bind.annotation.XmlAttribute;
 24  
 import javax.xml.bind.annotation.XmlElement;
 25  
 import javax.xml.bind.annotation.XmlElements;
 26  
 import javax.xml.bind.annotation.XmlRootElement;
 27  
 import javax.xml.bind.annotation.XmlType;
 28  
 
 29  
 import org.apache.commons.lang.StringUtils;
 30  
 
 31  
 /**
 32  
  * An immutable expression which represents an "in" statement which is
 33  
  * evaluated against a list of values.
 34  
  * 
 35  
  * <p>Constructed as part of a {@link Criteria} when built using a
 36  
  * {@link CriteriaBuilder}.
 37  
  * 
 38  
  * @see Criteria
 39  
  * @see CriteriaBuilder
 40  
  * 
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  */
 43  10
 @XmlRootElement(name = InExpression.Constants.ROOT_ELEMENT_NAME)
 44  
 @XmlAccessorType(XmlAccessType.NONE)
 45  
 @XmlType(name = InExpression.Constants.TYPE_NAME)
 46  
 public final class InExpression extends AbstractExpression implements MultiValuedExpression {
 47  
         
 48  
         private static final long serialVersionUID = -1888858317314153374L;
 49  
 
 50  
         @XmlAttribute(name = CriteriaSupportUtils.PropertyConstants.PROPERTY_PATH)
 51  
         private final String propertyPath;
 52  
         @XmlElements(value = {
 53  
             @XmlElement(name = CriteriaStringValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaStringValue.class, required = true),
 54  
             @XmlElement(name = CriteriaDateTimeValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaDateTimeValue.class, required = true),
 55  
             @XmlElement(name = CriteriaIntegerValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaIntegerValue.class, required = true),
 56  
             @XmlElement(name = CriteriaDecimalValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaDecimalValue.class, required = true)
 57  
         })
 58  
         private final List<? extends CriteriaValue<?>> values;
 59  
         
 60  
         /**
 61  
      * Should only be invoked by JAXB.
 62  
      */
 63  
     @SuppressWarnings("unused")
 64  10
     private InExpression() {
 65  10
         this.propertyPath = null;
 66  10
         this.values = null;
 67  10
     }
 68  
     
 69  
     /**
 70  
          * Constructs an InExpression for the given propertyPath and list of criteria values.
 71  
          * 
 72  
          * @param propertyPath the property path for the expression, must not be null or blank
 73  
          * @param values the list of criteria values to use for this expression, must be non-null,
 74  
          * non-empty, and all CriteriaValues contained within must be of the same type.
 75  
          * 
 76  
          * @throws IllegalArgumentException if the propertyPath is null or blank
 77  
          * @throws IllegalArgumentException if the list of values is null, empty, or contains {@link CriteriaValue} of different types
 78  
          */
 79  28
     InExpression(String propertyPath, List<? extends CriteriaValue<?>> values) {
 80  28
             if (StringUtils.isBlank(propertyPath)) {
 81  2
                         throw new IllegalArgumentException("Property path cannot be null or blank.");
 82  
                 }
 83  26
             CriteriaSupportUtils.validateValuesForMultiValuedExpression(values);
 84  21
                 this.propertyPath = propertyPath;
 85  21
                 this.values = values;
 86  21
     }
 87  
     
 88  
     @Override
 89  
     public String getPropertyPath() {
 90  4
             return propertyPath;
 91  
     }
 92  
     
 93  
     @Override
 94  
     public List<CriteriaValue<?>> getValues() {
 95  8
             return new ArrayList<CriteriaValue<?>>(values);
 96  
     }
 97  
         
 98  
         /**
 99  
      * Defines some internal constants used on this class.
 100  
      */
 101  0
     static class Constants {
 102  
         final static String ROOT_ELEMENT_NAME = "in";
 103  
         final static String TYPE_NAME = "InType";
 104  
     }
 105  
     
 106  
 }