View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.start;
20  
21  import java.util.Collection;
22  
23  public final class Utils
24  {
25      public static String join(Object[] arr, String delim)
26      {
27          if (arr == null)
28          {
29              return "";
30          }
31  
32          return join(arr,0,arr.length,delim);
33      }
34  
35      public static String join(Object[] arr, int start, int end, String delim)
36      {
37          if (arr == null)
38          {
39              return "";
40          }
41          StringBuilder str = new StringBuilder();
42          for (int i = start; i < end; i++)
43          {
44              if (i > start)
45              {
46                  str.append(delim);
47              }
48              str.append(arr[i]);
49          }
50          return str.toString();
51      }
52  
53      public static String join(Collection<?> objs, String delim)
54      {
55          if (objs == null)
56          {
57              return "";
58          }
59          StringBuilder str = new StringBuilder();
60          boolean needDelim = false;
61          for (Object obj : objs)
62          {
63              if (needDelim)
64              {
65                  str.append(delim);
66              }
67              str.append(obj);
68              needDelim = true;
69          }
70          return str.toString();
71      }
72  
73      /**
74       * Is String null, empty, or consisting of only whitespace.
75       * 
76       * @param value
77       *            the value to test
78       * @return true if null, empty, or consisting of only whitespace
79       */
80      public static boolean isBlank(String value)
81      {
82          if (value == null)
83          {
84              return true;
85          }
86          int len = value.length();
87          for (int i = 0; i < len; i++)
88          {
89              int c = value.codePointAt(i);
90              if (!Character.isWhitespace(c))
91              {
92                  return false;
93              }
94          }
95          return true;
96      }
97  
98      /**
99       * Is String valid and has something other than whitespace
100      * 
101      * @param value
102      *            the value to test
103      * @return true if String has something other than whitespace
104      */
105     public static boolean isNotBlank(String value)
106     {
107         if (value == null)
108         {
109             return false;
110         }
111         int len = value.length();
112         for (int i = 0; i < len; i++)
113         {
114             int c = value.codePointAt(i);
115             if (!Character.isWhitespace(c))
116             {
117                 return true;
118             }
119         }
120         return false;
121     }
122 }