Coverage Report - net.sf.sapjcosupport.SearchCriterion
 
Classes in this File Line Coverage Branch Coverage Complexity
SearchCriterion
61% 
0% 
1
 
 1  
 package net.sf.sapjcosupport;
 2  
 
 3  
 import java.util.HashMap;
 4  
 import java.util.Map;
 5  
 
 6  
 /**
 7  
  * Class that encapsulates the concept of a search criterion.
 8  
  * <br/>
 9  
  * It allows you to specify the search criteria for the SAP Search Help.
 10  
  * <p/>
 11  
  * <u>Remark:</u> If multiple search criteria are defined for a search, the criteria that operate
 12  
  * on the same SAP field are considered <code>OR</code>-conditions. Criteria that operate on different
 13  
  * SAP fields are considered <code>AND</code>-conditions.
 14  
  *
 15  
  * @author Jo Vandermeeren
 16  
  * @since Mar 21, 2006 - 12:45:38 PM
 17  
  */
 18  2
 public class SearchCriterion {
 19  
     private String field, lowLimit, highLimit, option;
 20  
 
 21  
     /**
 22  
      * Option: field value equals value of lower limit
 23  
      */
 24  
     public static final String EQUAL = "EQ";
 25  
     /**
 26  
      * Option: field value contains the pattern in lower limit value
 27  
      */
 28  
     public static final String CONTAINS_PATTERN = "CP";
 29  
     /**
 30  
      * Option: field value is between value of lower and higher limit
 31  
      */
 32  
     public static final String BETWEEN = "BT";
 33  
     /**
 34  
      * Option: field value is not between value of lower and higher limit
 35  
      */
 36  
     public static final String NOT_BETWEEN = "NB";
 37  
     /**
 38  
      * Option: field valie is not equal to value of lower limit
 39  
      */
 40  
     public static final String NOT_EQUAL = "NE";
 41  
     /**
 42  
      * Option: field value does not contain the pattern in lower limit value
 43  
      */
 44  
     public static final String CONTAINS_NOT_PATTERN = "NP";
 45  
     /**
 46  
      * Option: field value is greater than value of lower limit
 47  
      */
 48  
     public static final String GREATER = "GT";
 49  
     /**
 50  
      * Option: field value is less than value of lower limit
 51  
      */
 52  
     public static final String LESS = "LT";
 53  
     /**
 54  
      * Option: field value is greater or equal to value of lower limit
 55  
      */
 56  
     public static final String GREATER_OR_EQUAL = "GE";
 57  
     /**
 58  
      * Option: field value is less or equal to value of lower limit
 59  
      */
 60  
     public static final String LESS_OR_EQUAL = "LE";
 61  
 
 62  
     private boolean included;
 63  
 
 64  
     /**
 65  
      * Gets the option that is associated with this search criterion.
 66  
      *
 67  
      * @return option for this search criterion
 68  
      */
 69  
     public String getOption() {
 70  2
         return option;
 71  
     }
 72  
 
 73  
     /**
 74  
      * Sets the option of the search criterion.
 75  
      * <p/>
 76  
      * Please use the constants defined in this class to assign an option.
 77  
      * Some options require 2 parameters to operate correctly, e.g. {@link #BETWEEN}.
 78  
      * You can assign those parameters by calling the {@link #setHighLimit} and {@link #setLowLimit}
 79  
      * methods. If only 1 parameter is required, assign it to as the lower limit and leave the high limit blank.
 80  
      * <p/>
 81  
      * Possible options are:
 82  
      * <ul>
 83  
      * <li>EQUAL</li>
 84  
      * <li>CONTAINS_PATTERN</li>
 85  
      * <li>BETWEEN</li>
 86  
      * <li>NOT_BETWEEN</li>
 87  
      * <li>NOT_EQUAL</li>
 88  
      * <li>CONTAINS_NOT_PATTERN</li>
 89  
      * <li>GREATER</li>
 90  
      * <li>LESS</li>
 91  
      * <li>GREATER_OR_EQUAL</li>
 92  
      * <li>LESS_OR_EQUAL</li>
 93  
      * </ul>
 94  
      *
 95  
      * @param option option for this search criterion (please use the constants defined in this class)
 96  
      */
 97  
     public void setOption(String option) {
 98  2
         this.option = option;
 99  2
     }
 100  
 
 101  
     /**
 102  
      * Gets the SAP field to which this search criterion applies.
 103  
      *
 104  
      * @return SAP field name
 105  
      */
 106  
     public String getField() {
 107  2
         return field;
 108  
     }
 109  
 
 110  
     /**
 111  
      * Sets the SAP field to which this search criterion applies
 112  
      *
 113  
      * @param field SAP field name
 114  
      */
 115  
     public void setField(String field) {
 116  2
         this.field = field;
 117  2
     }
 118  
 
 119  
     /**
 120  
      * Sets the sign of this search criterion.
 121  
      * <p/>
 122  
      * The sign of a search criterion defines if the items that match this criterion should be
 123  
      * excluded or included from the results. This allows more complex queries, e.g.
 124  
      * <i>Select all materials beginning with "ES", but exclude those ending with "MF"</i>.
 125  
      *
 126  
      * @param include true if you want to include results that match this criterion
 127  
      */
 128  
     public void setIncluded(boolean include) {
 129  2
         included = include;
 130  2
     }
 131  
 
 132  
     /**
 133  
      * Returns true if items that match this criterion should be included in the results.
 134  
      *
 135  
      * @return true if matches of this criterion will be included in the results
 136  
      */
 137  
     public boolean isIncluded() {
 138  2
         return included;
 139  
     }
 140  
 
 141  
     /**
 142  
      * Gets the lower limit associated with this search criterion's option.
 143  
      * <p/>
 144  
      * If only one parameter is required for the specified option, this method returns that single limit.
 145  
      *
 146  
      * @return lower limit for specified option
 147  
      */
 148  
     public String getLowLimit() {
 149  2
         return lowLimit;
 150  
     }
 151  
 
 152  
     /**
 153  
      * Sets the lower limit for the option that is associated with this search helper.
 154  
      * <p/>
 155  
      * If only one parameter is required for the specified option, please use this method to assign that single limit.
 156  
      *
 157  
      * @param lowLimit lower limit for specified option
 158  
      */
 159  
     public void setLowLimit(String lowLimit) {
 160  2
         this.lowLimit = lowLimit;
 161  2
     }
 162  
 
 163  
     /**
 164  
      * Gets the higher limit associated with this search criterion's option.
 165  
      *
 166  
      * @return higher limit for specified option
 167  
      */
 168  
     public String getHighLimit() {
 169  2
         return highLimit;
 170  
     }
 171  
 
 172  
     /**
 173  
      * Sets the higher limit for the option that is associated with this search helper.
 174  
      *
 175  
      * @param highLimit higher limit for specified option
 176  
      */
 177  
     public void setHighLimit(String highLimit) {
 178  0
         this.highLimit = highLimit;
 179  0
     }
 180  
 
 181  
     /**
 182  
      * Helper method to convert a <code>SearchCriterion</code> object to a <code>Map</code>.
 183  
      *
 184  
      * @return Map containing the criterion properties
 185  
      */
 186  
     public Map toMap() {
 187  0
         Map selectionRow = new HashMap(5);
 188  
 //        selectionRow.put("SHLPNAME", searchHelpName);
 189  0
         selectionRow.put("SHLPFIELD", getField());
 190  0
         selectionRow.put("SIGN", isIncluded() ? "I" : "E");
 191  0
         selectionRow.put("OPTION", getOption());
 192  0
         selectionRow.put("LOW", getLowLimit());
 193  0
         selectionRow.put("HIGH", getHighLimit());
 194  0
         return selectionRow;
 195  
     }
 196  
 }