66import java .net .MalformedURLException ;
77import java .net .URL ;
88import java .net .URLDecoder ;
9- import java .util .*;
9+ import java .util .Arrays ;
10+ import java .util .Collection ;
11+ import java .util .Iterator ;
12+ import java .util .LinkedList ;
13+ import java .util .List ;
14+ import java .util .Map ;
1015import java .util .regex .Pattern ;
1116
12- public class Utils {
17+ public final class Utils {
1318
1419 public static final String HTTP = "http://" ;
1520 public static final String HTTPS = "https://" ;
@@ -46,18 +51,16 @@ public static String removeNonDigitCharacters(final String toRemove) {
4651 *
4752 * @param numberWord string to be converted to a long
4853 * @return a long
49- * @throws NumberFormatException
50- * @throws ParsingException
5154 */
5255 public static long mixedNumberWordToLong (final String numberWord ) throws NumberFormatException ,
5356 ParsingException {
5457 String multiplier = "" ;
5558 try {
5659 multiplier = Parser .matchGroup ("[\\ d]+([\\ .,][\\ d]+)?([KMBkmb])+" , numberWord , 2 );
57- } catch (ParsingException ignored ) {
60+ } catch (final ParsingException ignored ) {
5861 }
59- double count = Double .parseDouble (Parser . matchGroup1 ( "([ \\ d]+([ \\ .,][ \\ d]+)?)" , numberWord )
60- .replace ("," , "." ));
62+ final double count = Double .parseDouble (
63+ Parser . matchGroup1 ( "([ \\ d]+([ \\ .,][ \\ d]+)?)" , numberWord ) .replace ("," , "." ));
6164 switch (multiplier .toUpperCase ()) {
6265 case "K" :
6366 return (long ) (count * 1e3 );
@@ -86,15 +89,10 @@ public static void checkUrl(final String pattern, final String url) throws Parsi
8689 }
8790 }
8891
89- public static void printErrors (List <Throwable > errors ) {
90- for (Throwable e : errors ) {
91- e .printStackTrace ();
92- System .err .println ("----------------" );
93- }
94- }
95-
9692 public static String replaceHttpWithHttps (final String url ) {
97- if (url == null ) return null ;
93+ if (url == null ) {
94+ return null ;
95+ }
9896
9997 if (!url .isEmpty () && url .startsWith (HTTP )) {
10098 return HTTPS + url .substring (HTTP .length ());
@@ -111,29 +109,25 @@ public static String replaceHttpWithHttps(final String url) {
111109 * @return a string that contains the value of the query parameter or null if nothing was found
112110 */
113111 public static String getQueryValue (final URL url , final String parameterName ) {
114- String urlQuery = url .getQuery ();
112+ final String urlQuery = url .getQuery ();
115113
116114 if (urlQuery != null ) {
117- for (String param : urlQuery .split ("&" )) {
118- String [] params = param .split ("=" , 2 );
115+ for (final String param : urlQuery .split ("&" )) {
116+ final String [] params = param .split ("=" , 2 );
119117
120118 String query ;
121119 try {
122120 query = URLDecoder .decode (params [0 ], UTF_8 );
123121 } catch (final UnsupportedEncodingException e ) {
124- System .err .println (
125- "Cannot decode string with UTF-8. using the string without decoding" );
126- e .printStackTrace ();
122+ // Cannot decode string with UTF-8, using the string without decoding
127123 query = params [0 ];
128124 }
129125
130126 if (query .equals (parameterName )) {
131127 try {
132128 return URLDecoder .decode (params [1 ], UTF_8 );
133129 } catch (final UnsupportedEncodingException e ) {
134- System .err .println (
135- "Cannot decode string with UTF-8. using the string without decoding" );
136- e .printStackTrace ();
130+ // Cannot decode string with UTF-8, using the string without decoding
137131 return params [1 ];
138132 }
139133 }
@@ -153,7 +147,7 @@ public static String getQueryValue(final URL url, final String parameterName) {
153147 public static URL stringToURL (final String url ) throws MalformedURLException {
154148 try {
155149 return new URL (url );
156- } catch (MalformedURLException e ) {
150+ } catch (final MalformedURLException e ) {
157151 // if no protocol is given try prepending "https://"
158152 if (e .getMessage ().equals ("no protocol: " + url )) {
159153 return new URL (HTTPS + url );
@@ -165,13 +159,13 @@ public static URL stringToURL(final String url) throws MalformedURLException {
165159
166160 public static boolean isHTTP (final URL url ) {
167161 // make sure its http or https
168- String protocol = url .getProtocol ();
162+ final String protocol = url .getProtocol ();
169163 if (!protocol .equals ("http" ) && !protocol .equals ("https" )) {
170164 return false ;
171165 }
172166
173- boolean usesDefaultPort = url .getPort () == url .getDefaultPort ();
174- boolean setsNoPort = url .getPort () == -1 ;
167+ final boolean usesDefaultPort = url .getPort () == url .getDefaultPort ();
168+ final boolean setsNoPort = url .getPort () == -1 ;
175169
176170 return setsNoPort || usesDefaultPort ;
177171 }
@@ -186,14 +180,15 @@ public static String removeMAndWWWFromUrl(final String url) {
186180 return url ;
187181 }
188182
189- public static String removeUTF8BOM (String s ) {
190- if (s .startsWith ("\uFEFF " )) {
191- s = s .substring (1 );
183+ public static String removeUTF8BOM (final String s ) {
184+ String result = s ;
185+ if (result .startsWith ("\uFEFF " )) {
186+ result = result .substring (1 );
192187 }
193- if (s .endsWith ("\uFEFF " )) {
194- s = s .substring (0 , s .length () - 1 );
188+ if (result .endsWith ("\uFEFF " )) {
189+ result = result .substring (0 , result .length () - 1 );
195190 }
196- return s ;
191+ return result ;
197192 }
198193
199194 public static String getBaseUrl (final String url ) throws ParsingException {
@@ -243,7 +238,7 @@ public static boolean isNullOrEmpty(final Collection<?> collection) {
243238 }
244239
245240 // can be used for JsonObjects
246- public static boolean isNullOrEmpty (final Map map ) {
241+ public static boolean isNullOrEmpty (final Map <?, ?> map ) {
247242 return map == null || map .isEmpty ();
248243 }
249244
0 commit comments