View Javadoc

1   package net.sf.chainedoptions.support;
2   
3   import java.util.List;
4   
5   import net.sf.chainedoptions.ChainedOptionStrategy;
6   import net.sf.chainedoptions.LabelValueBean;
7   
8   
9   /***
10   * Strategy that does not perform any sorting and returns the first item in the
11   * list as default value.
12   * 
13   * @author Mattias Arthursson
14   */
15  public class NoSortStrategy extends Object implements ChainedOptionStrategy {
16  
17      /***
18       * Do nothing, just return the supplied list.
19       * 
20       * @param options
21       *            the list to return.
22       * @param context
23       *            ignored for this implementation.
24       * @return the supplied list, unmodified.
25       */
26      public List adjustAndSort(List options, Object context) {
27          return options;
28      }
29  
30      /***
31       * Returns the value of the first item in the list.
32       * 
33       * @param options
34       *            the list of options.
35       * @param context
36       *            ignored for this implementation.
37       * @return the value of the first item in the List if the List is not empty,
38       *         empty String otherwise.
39       */
40      public String getDefaultValue(List options, Object context) {
41          if (options.size() > 0) {
42              LabelValueBean bean = (LabelValueBean) options.get(0);
43              return bean.getValue();
44          } else {
45              return "";
46          }
47      }
48  
49  }