Coverage Report - org.kuali.student.r2.core.search.dto.SearchParamInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
SearchParamInfo
0%
0/45
0%
0/30
2.357
 
 1  
 /*
 2  
  * Copyright 2010 The Kuali Foundation 
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the
 5  
  * "License"); you may not use this file except in compliance with the
 6  
  * License. You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.osedu.org/licenses/ECL-2.0
 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
 13  
  * implied. See the License for the specific language governing
 14  
  * permissions and limitations under the License.
 15  
  */
 16  
 package org.kuali.student.r2.core.search.dto;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.ArrayList;
 20  
 import java.util.Arrays;
 21  
 import java.util.List;
 22  
 
 23  
 import javax.xml.bind.annotation.XmlAccessType;
 24  
 import javax.xml.bind.annotation.XmlAccessorType;
 25  
 import javax.xml.bind.annotation.XmlAnyElement;
 26  
 import javax.xml.bind.annotation.XmlAttribute;
 27  
 import javax.xml.bind.annotation.XmlElement;
 28  
 import javax.xml.bind.annotation.XmlType;
 29  
 
 30  
 import org.kuali.student.r2.core.search.infc.SearchParam;
 31  
 import org.w3c.dom.Element;
 32  
 
 33  
 @XmlAccessorType(XmlAccessType.FIELD)
 34  
 @XmlType(name = "SearchParamInfo", propOrder = {
 35  
     "key", "values", "_futureElements"})
 36  
 public class SearchParamInfo
 37  
         implements SearchParam, Serializable {
 38  
 
 39  
     private static final long serialVersionUID = 1L;
 40  
     @XmlAttribute
 41  
     private String key;
 42  
     @XmlElement
 43  
     private List<String> values;
 44  
     @XmlAnyElement
 45  
     private List<Element> _futureElements;
 46  
 
 47  
     /**
 48  
      * Constructs a new SearchParamInfo.
 49  
      */
 50  0
     public SearchParamInfo() {
 51  0
     }
 52  
 
 53  
     /**
 54  
      * Constructs a new SearchParamInfo from
 55  
      * another SearchParam.
 56  
      *
 57  
      * @param param the SearchParam to copy
 58  
      */
 59  0
     public SearchParamInfo(SearchParam param) {
 60  0
         if (param != null) {
 61  0
             this.key = param.getKey();
 62  0
             if (param.getValues() != null) {
 63  0
                 this.values = new ArrayList(param.getValues());
 64  
             }
 65  
         }
 66  0
     }
 67  
 
 68  
     /**
 69  
      * Constructs a new SearchParamInfo from
 70  
      * a pair of key/value strings.
 71  
      *
 72  
      * Convenience method to construct a param with a single value
 73  
      * 
 74  
      * @param key the key for the parameter
 75  
      * @param value the value for the parameter
 76  
      */
 77  0
     public SearchParamInfo(String key, String value) {
 78  0
         this.key = key;
 79  0
         this.values = Arrays.asList(value);
 80  0
     }
 81  
 
 82  
     /**
 83  
      * Constructs a new SearchParamInfo for a list
 84  
      * of string values.
 85  
      *
 86  
      * @param key the key for the parameter
 87  
      * @param values a list of values for the parameter
 88  
      */
 89  0
     public SearchParamInfo(String key, List<String> values) {
 90  0
         this.key = key;
 91  0
         this.values = values;
 92  0
     }
 93  
 
 94  
     @Override
 95  
     public String getKey() {
 96  0
         return key;
 97  
     }
 98  
 
 99  
     public void setKey(String key) {
 100  0
         this.key = key;
 101  0
     }
 102  
 
 103  
     @Override
 104  
     public List<String> getValues() {
 105  0
         return values;
 106  
     }
 107  
 
 108  
     /** 
 109  
      * R1 compatibility method to return the value
 110  
      * as an object
 111  
      * If there is only one value set it returns that as a String otherwise it 
 112  
      * returns the value as a list
 113  
      * @deprecated
 114  
      */
 115  
     @Deprecated
 116  
     public Object getValue() {
 117  0
         if (values == null) {
 118  0
             return null;
 119  
         }
 120  0
         if (values.size() == 1) {
 121  0
             return values.get(0);
 122  
         }
 123  0
         return values;
 124  
     }
 125  
 
 126  
     /** 
 127  
      * R1 compatibility method to set the value as a string
 128  
      * 
 129  
      * Equivalent to calling setValues (Arrays.asList (value))
 130  
      * 
 131  
      * @deprecated
 132  
      */
 133  
     @Deprecated
 134  
     public void setValue(String value) {
 135  0
         this.values = Arrays.asList(value);
 136  0
     }
 137  
 
 138  
     /** 
 139  
      * R1 compatibility method to set the value as a list 
 140  
      * equivalent to calling setValues
 141  
      * as a string
 142  
      * @deprecated
 143  
      */
 144  
     @Deprecated
 145  
     public void setValue(List<String> values) {
 146  0
         this.values = values;
 147  0
     }
 148  
 
 149  
     public void setValues(List<String> values) {
 150  0
         this.values = values;
 151  0
     }
 152  
 
 153  
     @Override
 154  
     public String toString() {
 155  0
         return "SearchParam[key=" + key + ", value=" + values + "]";
 156  
     }
 157  
 
 158  
     @Override
 159  
     public boolean equals(Object o) {
 160  0
         if (this == o) {
 161  0
             return true;
 162  
         }
 163  0
         if (o == null || getClass() != o.getClass()) {
 164  0
             return false;
 165  
         }
 166  
 
 167  0
         SearchParamInfo that = (SearchParamInfo) o;
 168  
 
 169  0
         if (key != null ? !key.equals(that.key) : that.key != null) {
 170  0
             return false;
 171  
         }
 172  0
         if (values != null ? !values.equals(that.values) : that.values != null) {
 173  0
             return false;
 174  
         }
 175  
 
 176  0
         return true;
 177  
     }
 178  
 
 179  
     @Override
 180  
     public int hashCode() {
 181  0
         int result = values != null ? values.hashCode() : 0;
 182  0
         result = 31 * result + (key != null ? key.hashCode() : 0);
 183  0
         return result;
 184  
     }
 185  
 }