View Javadoc

1   /*
2    * Created by IntelliJ IDEA.
3    * User: mike
4    * Date: Jan 7, 2002
5    * Time: 4:32:26 AM
6    * To change template for new class use
7    * Code Style | Class Templates options (Tools | IDE Options).
8    */
9   package com.atlassian.core.util;
10  
11  import com.opensymphony.util.TextUtils;
12  
13  import java.util.ArrayList;
14  import java.util.Iterator;
15  import java.util.List;
16  
17  public class FilterUtils
18  {
19      /**
20       * Returned string is non-null IFF there is a true value (ie some text)
21       */
22      public static String verifyString(String s)
23      {
24          if (TextUtils.stringSet(TextUtils.noNull(s).trim()))
25          {
26              return s;
27          }
28          else
29          {
30              return null;
31          }
32      }
33  
34      /**
35       * Retirned string array is non-null IFF there is a true value (ie some text)
36       */
37      public static String[] verifyStringArray(String[] sa)
38      {
39          List<String> result = new ArrayList<String>();
40  
41          for (int i = 0; i < sa.length; i++)
42          {
43              String s = verifyString(sa[i]);
44              if (s != null)
45                  result.add(s);
46          }
47  
48          if (result.size() == 0)
49          {
50              return null;
51          }
52          else
53          {
54              String[] resultSa = new String[result.size()];
55              int count = 0;
56              for (Iterator<String> iterator = result.iterator(); iterator.hasNext();)
57              {
58                  resultSa[count++] = iterator.next();
59              }
60  
61              return resultSa;
62          }
63      }
64  
65      public static Long verifyLong(Long id)
66      {
67          if (id != null && id.longValue() > 0)
68          {
69              return id;
70          }
71  
72          return null;
73      }
74  
75  }