| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.util; |
| 22 |
|
|
| 23 |
|
import java.io.UnsupportedEncodingException; |
| 24 |
|
import java.net.URLEncoder; |
| 25 |
|
import java.util.ArrayList; |
| 26 |
|
import java.util.List; |
| 27 |
|
import java.util.Locale; |
| 28 |
|
import java.util.regex.Matcher; |
| 29 |
|
import java.util.regex.Pattern; |
| 30 |
|
|
| 31 |
|
import jalview.bin.Console; |
| 32 |
|
|
| |
|
| 0% |
Uncovered Elements: 354 (354) |
Complexity: 110 |
Complexity Density: 0.52 |
|
| 33 |
|
public class StringUtils |
| 34 |
|
{ |
| 35 |
|
private static final Pattern DELIMITERS_PATTERN = Pattern |
| 36 |
|
.compile(".*='[^']*(?!')"); |
| 37 |
|
|
| 38 |
|
private static final char PERCENT = '%'; |
| 39 |
|
|
| 40 |
|
private static final boolean DEBUG = false; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
private static String[] urlEncodings = new String[255]; |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@param |
| 53 |
|
|
| 54 |
|
@param |
| 55 |
|
|
| 56 |
|
@param |
| 57 |
|
|
| 58 |
|
@param |
| 59 |
|
|
| 60 |
|
|
| |
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 61 |
0 |
public static final char[] insertCharAt(char[] in, int position,... |
| 62 |
|
int count, char ch) |
| 63 |
|
{ |
| 64 |
0 |
char[] tmp = new char[in.length + count]; |
| 65 |
|
|
| 66 |
0 |
if (position >= in.length) |
| 67 |
|
{ |
| 68 |
0 |
System.arraycopy(in, 0, tmp, 0, in.length); |
| 69 |
0 |
position = in.length; |
| 70 |
|
} |
| 71 |
|
else |
| 72 |
|
{ |
| 73 |
0 |
System.arraycopy(in, 0, tmp, 0, position); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
0 |
int index = position; |
| 77 |
0 |
while (count > 0) |
| 78 |
|
{ |
| 79 |
0 |
tmp[index++] = ch; |
| 80 |
0 |
count--; |
| 81 |
|
} |
| 82 |
|
|
| 83 |
0 |
if (position < in.length) |
| 84 |
|
{ |
| 85 |
0 |
System.arraycopy(in, position, tmp, index, in.length - position); |
| 86 |
|
} |
| 87 |
|
|
| 88 |
0 |
return tmp; |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
@param |
| 95 |
|
@param |
| 96 |
|
@param |
| 97 |
|
@return |
| 98 |
|
|
| |
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 99 |
0 |
public static final char[] deleteChars(char[] in, int from, int to)... |
| 100 |
|
{ |
| 101 |
0 |
if (from >= in.length || from < 0) |
| 102 |
|
{ |
| 103 |
0 |
return in; |
| 104 |
|
} |
| 105 |
|
|
| 106 |
0 |
char[] tmp; |
| 107 |
|
|
| 108 |
0 |
if (to >= in.length) |
| 109 |
|
{ |
| 110 |
0 |
tmp = new char[from]; |
| 111 |
0 |
System.arraycopy(in, 0, tmp, 0, from); |
| 112 |
0 |
to = in.length; |
| 113 |
|
} |
| 114 |
|
else |
| 115 |
|
{ |
| 116 |
0 |
tmp = new char[in.length - to + from]; |
| 117 |
0 |
System.arraycopy(in, 0, tmp, 0, from); |
| 118 |
0 |
System.arraycopy(in, to, tmp, from, in.length - to); |
| 119 |
|
} |
| 120 |
0 |
return tmp; |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
@param |
| 128 |
|
@param |
| 129 |
|
|
| 130 |
|
@return |
| 131 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 132 |
0 |
public static String getLastToken(String input, String token)... |
| 133 |
|
{ |
| 134 |
0 |
if (input == null) |
| 135 |
|
{ |
| 136 |
0 |
return null; |
| 137 |
|
} |
| 138 |
0 |
if (token == null) |
| 139 |
|
{ |
| 140 |
0 |
return input; |
| 141 |
|
} |
| 142 |
0 |
String[] st = input.split(token); |
| 143 |
0 |
return st[st.length - 1]; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
@param |
| 152 |
|
@param |
| 153 |
|
@return |
| 154 |
|
|
| |
|
| 0% |
Uncovered Elements: 54 (54) |
Complexity: 17 |
Complexity Density: 0.53 |
|
| 155 |
0 |
public static String[] separatorListToArray(String input,... |
| 156 |
|
String delimiter) |
| 157 |
|
{ |
| 158 |
0 |
int seplen = delimiter.length(); |
| 159 |
0 |
if (input == null || input.equals("") || input.equals(delimiter)) |
| 160 |
|
{ |
| 161 |
0 |
return null; |
| 162 |
|
} |
| 163 |
0 |
List<String> jv = new ArrayList<>(); |
| 164 |
0 |
int cp = 0, pos, escape; |
| 165 |
0 |
boolean wasescaped = false, wasquoted = false; |
| 166 |
0 |
String lstitem = null; |
| 167 |
0 |
while ((pos = input.indexOf(delimiter, cp)) >= cp) |
| 168 |
|
{ |
| 169 |
0 |
escape = (pos > 0 && input.charAt(pos - 1) == '\\') ? -1 : 0; |
| 170 |
0 |
if (wasescaped || wasquoted) |
| 171 |
|
{ |
| 172 |
|
|
| 173 |
0 |
jv.set(jv.size() - 1, lstitem = lstitem + delimiter |
| 174 |
|
+ input.substring(cp, pos + escape)); |
| 175 |
|
} |
| 176 |
|
else |
| 177 |
|
{ |
| 178 |
0 |
jv.add(lstitem = input.substring(cp, pos + escape)); |
| 179 |
|
} |
| 180 |
0 |
cp = pos + seplen; |
| 181 |
0 |
wasescaped = escape == -1; |
| 182 |
|
|
| 183 |
0 |
wasquoted = DELIMITERS_PATTERN.matcher(lstitem).matches(); |
| 184 |
|
} |
| 185 |
0 |
if (cp < input.length()) |
| 186 |
|
{ |
| 187 |
0 |
String c = input.substring(cp); |
| 188 |
0 |
if (wasescaped || wasquoted) |
| 189 |
|
{ |
| 190 |
|
|
| 191 |
0 |
jv.set(jv.size() - 1, lstitem + delimiter + c); |
| 192 |
|
} |
| 193 |
|
else |
| 194 |
|
{ |
| 195 |
0 |
if (!c.equals(delimiter)) |
| 196 |
|
{ |
| 197 |
0 |
jv.add(c); |
| 198 |
|
} |
| 199 |
|
} |
| 200 |
|
} |
| 201 |
0 |
if (jv.size() > 0) |
| 202 |
|
{ |
| 203 |
0 |
String[] v = jv.toArray(new String[jv.size()]); |
| 204 |
0 |
jv.clear(); |
| 205 |
0 |
if (DEBUG) |
| 206 |
|
{ |
| 207 |
0 |
ErrorLog.errPrintln("Array from '" + delimiter |
| 208 |
|
+ "' separated List:\n" + v.length); |
| 209 |
0 |
for (int i = 0; i < v.length; i++) |
| 210 |
|
{ |
| 211 |
0 |
ErrorLog.errPrintln("item " + i + " '" + v[i] + "'"); |
| 212 |
|
} |
| 213 |
|
} |
| 214 |
0 |
return v; |
| 215 |
|
} |
| 216 |
0 |
if (DEBUG) |
| 217 |
|
{ |
| 218 |
0 |
ErrorLog.errPrintln( |
| 219 |
|
"Empty Array from '" + delimiter + "' separated List"); |
| 220 |
|
} |
| 221 |
0 |
return null; |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
|
| 227 |
|
|
| 228 |
|
|
| 229 |
|
@param |
| 230 |
|
@param |
| 231 |
|
@return |
| 232 |
|
|
| |
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 8 |
Complexity Density: 0.57 |
|
| 233 |
0 |
public static String arrayToSeparatorList(String[] list, String separator)... |
| 234 |
|
{ |
| 235 |
0 |
StringBuffer v = new StringBuffer(); |
| 236 |
0 |
if (list != null && list.length > 0) |
| 237 |
|
{ |
| 238 |
0 |
for (int i = 0, iSize = list.length; i < iSize; i++) |
| 239 |
|
{ |
| 240 |
0 |
if (list[i] != null) |
| 241 |
|
{ |
| 242 |
0 |
if (v.length() > 0) |
| 243 |
|
{ |
| 244 |
0 |
v.append(separator); |
| 245 |
|
} |
| 246 |
|
|
| 247 |
0 |
v.append(list[i]); |
| 248 |
|
} |
| 249 |
|
} |
| 250 |
0 |
if (DEBUG) |
| 251 |
|
{ |
| 252 |
0 |
System.err |
| 253 |
|
.println("Returning '" + separator + "' separated List:\n"); |
| 254 |
0 |
ErrorLog.errPrintln(v.toString()); |
| 255 |
|
} |
| 256 |
0 |
return v.toString(); |
| 257 |
|
} |
| 258 |
0 |
if (DEBUG) |
| 259 |
|
{ |
| 260 |
0 |
ErrorLog.errPrintln( |
| 261 |
|
"Returning empty '" + separator + "' separated List\n"); |
| 262 |
|
} |
| 263 |
0 |
return "" + separator; |
| 264 |
|
} |
| 265 |
|
|
| 266 |
|
|
| 267 |
|
|
| 268 |
|
|
| 269 |
|
|
| 270 |
|
|
| 271 |
|
@param |
| 272 |
|
@param |
| 273 |
|
@return |
| 274 |
|
|
| |
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 275 |
0 |
public static String listToDelimitedString(List<String> terms,... |
| 276 |
|
String delim) |
| 277 |
|
{ |
| 278 |
0 |
StringBuilder sb = new StringBuilder(32); |
| 279 |
0 |
if (terms != null && !terms.isEmpty()) |
| 280 |
|
{ |
| 281 |
0 |
boolean appended = false; |
| 282 |
0 |
for (String term : terms) |
| 283 |
|
{ |
| 284 |
0 |
if (appended) |
| 285 |
|
{ |
| 286 |
0 |
sb.append(delim); |
| 287 |
|
} |
| 288 |
0 |
appended = true; |
| 289 |
0 |
sb.append(term); |
| 290 |
|
} |
| 291 |
|
} |
| 292 |
0 |
return sb.toString(); |
| 293 |
|
} |
| 294 |
|
|
| 295 |
|
|
| 296 |
|
|
| 297 |
|
|
| 298 |
|
|
| 299 |
|
@param |
| 300 |
|
@return |
| 301 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 302 |
0 |
public static int parseInt(String s)... |
| 303 |
|
{ |
| 304 |
0 |
int result = 0; |
| 305 |
0 |
if (s != null && s.length() > 0) |
| 306 |
|
{ |
| 307 |
0 |
try |
| 308 |
|
{ |
| 309 |
0 |
result = Integer.parseInt(s); |
| 310 |
|
} catch (NumberFormatException ex) |
| 311 |
|
{ |
| 312 |
|
} |
| 313 |
|
} |
| 314 |
0 |
return result; |
| 315 |
|
} |
| 316 |
|
|
| 317 |
|
|
| 318 |
|
|
| 319 |
|
|
| 320 |
|
|
| 321 |
|
@param |
| 322 |
|
@param |
| 323 |
|
@return |
| 324 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 325 |
0 |
public static int compareVersions(String v1, String v2)... |
| 326 |
|
{ |
| 327 |
0 |
return compareVersions(v1, v2, null); |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
|
| 331 |
|
|
| 332 |
|
|
| 333 |
|
|
| 334 |
|
@param |
| 335 |
|
@param |
| 336 |
|
@param |
| 337 |
|
|
| 338 |
|
|
| 339 |
|
@return |
| 340 |
|
|
| |
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 9 |
Complexity Density: 0.38 |
|
| 341 |
0 |
public static int compareVersions(String v1, String v2,... |
| 342 |
|
String pointSeparator) |
| 343 |
|
{ |
| 344 |
0 |
if (v1 == null || v2 == null) |
| 345 |
|
{ |
| 346 |
0 |
return 0; |
| 347 |
|
} |
| 348 |
0 |
String[] toks1 = v1.split("\\."); |
| 349 |
0 |
String[] toks2 = v2.split("\\."); |
| 350 |
0 |
int i = 0; |
| 351 |
0 |
for (; i < toks1.length; i++) |
| 352 |
|
{ |
| 353 |
0 |
if (i >= toks2.length) |
| 354 |
|
{ |
| 355 |
|
|
| 356 |
|
|
| 357 |
|
|
| 358 |
0 |
return 1; |
| 359 |
|
} |
| 360 |
0 |
String tok1 = toks1[i]; |
| 361 |
0 |
String tok2 = toks2[i]; |
| 362 |
0 |
if (pointSeparator != null) |
| 363 |
|
{ |
| 364 |
|
|
| 365 |
|
|
| 366 |
|
|
| 367 |
0 |
tok1 = tok1.replace(pointSeparator, "."); |
| 368 |
0 |
tok2 = tok2.replace(pointSeparator, "."); |
| 369 |
|
} |
| 370 |
0 |
try |
| 371 |
|
{ |
| 372 |
0 |
float f1 = Float.valueOf(tok1); |
| 373 |
0 |
float f2 = Float.valueOf(tok2); |
| 374 |
0 |
int comp = Float.compare(f1, f2); |
| 375 |
0 |
if (comp != 0) |
| 376 |
|
{ |
| 377 |
0 |
return comp; |
| 378 |
|
} |
| 379 |
|
} catch (NumberFormatException e) |
| 380 |
|
{ |
| 381 |
0 |
System.err |
| 382 |
|
.println("Invalid version format found: " + e.getMessage()); |
| 383 |
0 |
return 0; |
| 384 |
|
} |
| 385 |
|
} |
| 386 |
|
|
| 387 |
0 |
if (i < toks2.length) |
| 388 |
|
{ |
| 389 |
|
|
| 390 |
|
|
| 391 |
|
|
| 392 |
0 |
return -1; |
| 393 |
|
} |
| 394 |
|
|
| 395 |
|
|
| 396 |
|
|
| 397 |
|
|
| 398 |
0 |
return 0; |
| 399 |
|
} |
| 400 |
|
|
| 401 |
|
|
| 402 |
|
|
| 403 |
|
|
| 404 |
|
|
| 405 |
|
@param |
| 406 |
|
@return |
| 407 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 408 |
0 |
public static String toSentenceCase(String s)... |
| 409 |
|
{ |
| 410 |
0 |
if (s == null) |
| 411 |
|
{ |
| 412 |
0 |
return s; |
| 413 |
|
} |
| 414 |
0 |
if (s.length() <= 1) |
| 415 |
|
{ |
| 416 |
0 |
return s.toUpperCase(Locale.ROOT); |
| 417 |
|
} |
| 418 |
0 |
return s.substring(0, 1).toUpperCase(Locale.ROOT) |
| 419 |
|
+ s.substring(1).toLowerCase(Locale.ROOT); |
| 420 |
|
} |
| 421 |
|
|
| 422 |
|
|
| 423 |
|
|
| 424 |
|
|
| 425 |
|
|
| 426 |
|
@param |
| 427 |
|
@return |
| 428 |
|
|
| |
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 8 |
Complexity Density: 0.44 |
|
| 429 |
0 |
public static String stripHtmlTags(String text)... |
| 430 |
|
{ |
| 431 |
0 |
if (text == null) |
| 432 |
|
{ |
| 433 |
0 |
return null; |
| 434 |
|
} |
| 435 |
0 |
String tmp2up = text.toUpperCase(Locale.ROOT); |
| 436 |
0 |
int startTag = tmp2up.indexOf("<HTML>"); |
| 437 |
0 |
if (startTag > -1) |
| 438 |
|
{ |
| 439 |
0 |
text = text.substring(startTag + 6); |
| 440 |
0 |
tmp2up = tmp2up.substring(startTag + 6); |
| 441 |
|
} |
| 442 |
|
|
| 443 |
0 |
int endTag = tmp2up.indexOf("</BODY>"); |
| 444 |
0 |
if (endTag > -1) |
| 445 |
|
{ |
| 446 |
0 |
text = text.substring(0, endTag); |
| 447 |
0 |
tmp2up = tmp2up.substring(0, endTag); |
| 448 |
|
} |
| 449 |
0 |
endTag = tmp2up.indexOf("</HTML>"); |
| 450 |
0 |
if (endTag > -1) |
| 451 |
|
{ |
| 452 |
0 |
text = text.substring(0, endTag); |
| 453 |
|
} |
| 454 |
|
|
| 455 |
0 |
if (startTag == -1 && (text.contains("<") || text.contains(">"))) |
| 456 |
|
{ |
| 457 |
0 |
text = text.replaceAll("<", "<"); |
| 458 |
0 |
text = text.replaceAll(">", ">"); |
| 459 |
|
} |
| 460 |
0 |
return text; |
| 461 |
|
} |
| 462 |
|
|
| 463 |
|
|
| 464 |
|
|
| 465 |
|
|
| 466 |
|
|
| 467 |
|
@param |
| 468 |
|
@param |
| 469 |
|
@return |
| 470 |
|
|
| |
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
| 471 |
0 |
public static String urlEncode(String s, String encodable)... |
| 472 |
|
{ |
| 473 |
0 |
if (s == null || s.isEmpty()) |
| 474 |
|
{ |
| 475 |
0 |
return s; |
| 476 |
|
} |
| 477 |
|
|
| 478 |
|
|
| 479 |
|
|
| 480 |
|
|
| 481 |
0 |
if (encodable.indexOf(PERCENT) != -1) |
| 482 |
|
{ |
| 483 |
0 |
s = urlEncode(s, PERCENT); |
| 484 |
|
} |
| 485 |
|
|
| 486 |
0 |
for (char c : encodable.toCharArray()) |
| 487 |
|
{ |
| 488 |
0 |
if (c != PERCENT) |
| 489 |
|
{ |
| 490 |
0 |
s = urlEncode(s, c); |
| 491 |
|
} |
| 492 |
|
} |
| 493 |
0 |
return s; |
| 494 |
|
} |
| 495 |
|
|
| 496 |
|
|
| 497 |
|
|
| 498 |
|
|
| 499 |
|
|
| 500 |
|
@param |
| 501 |
|
@param |
| 502 |
|
@return |
| 503 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 504 |
0 |
static String urlEncode(String s, char c)... |
| 505 |
|
{ |
| 506 |
0 |
String decoded = String.valueOf(c); |
| 507 |
0 |
if (s.indexOf(decoded) != -1) |
| 508 |
|
{ |
| 509 |
0 |
String encoded = getUrlEncoding(c); |
| 510 |
0 |
if (!encoded.equals(decoded)) |
| 511 |
|
{ |
| 512 |
0 |
s = s.replace(decoded, encoded); |
| 513 |
|
} |
| 514 |
|
} |
| 515 |
0 |
return s; |
| 516 |
|
} |
| 517 |
|
|
| 518 |
|
|
| 519 |
|
|
| 520 |
|
|
| 521 |
|
|
| 522 |
|
|
| 523 |
|
|
| 524 |
|
|
| 525 |
|
@param |
| 526 |
|
@param |
| 527 |
|
@return |
| 528 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 529 |
0 |
public static String urlDecode(String s, String encodable)... |
| 530 |
|
{ |
| 531 |
0 |
if (s == null || s.isEmpty()) |
| 532 |
|
{ |
| 533 |
0 |
return s; |
| 534 |
|
} |
| 535 |
|
|
| 536 |
0 |
for (char c : encodable.toCharArray()) |
| 537 |
|
{ |
| 538 |
0 |
String encoded = getUrlEncoding(c); |
| 539 |
0 |
if (s.indexOf(encoded) != -1) |
| 540 |
|
{ |
| 541 |
0 |
String decoded = String.valueOf(c); |
| 542 |
0 |
s = s.replace(encoded, decoded); |
| 543 |
|
} |
| 544 |
|
} |
| 545 |
0 |
return s; |
| 546 |
|
} |
| 547 |
|
|
| 548 |
|
|
| 549 |
|
|
| 550 |
|
|
| 551 |
|
|
| 552 |
|
@param |
| 553 |
|
@return |
| 554 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 5 |
Complexity Density: 0.62 |
|
| 555 |
0 |
private static String getUrlEncoding(char c)... |
| 556 |
|
{ |
| 557 |
0 |
if (c < 0 || c >= urlEncodings.length) |
| 558 |
|
{ |
| 559 |
0 |
return String.valueOf(c); |
| 560 |
|
} |
| 561 |
|
|
| 562 |
0 |
String enc = urlEncodings[c]; |
| 563 |
0 |
if (enc == null) |
| 564 |
|
{ |
| 565 |
0 |
try |
| 566 |
|
{ |
| 567 |
0 |
enc = urlEncodings[c] = URLEncoder.encode(String.valueOf(c), |
| 568 |
|
"UTF-8"); |
| 569 |
|
} catch (UnsupportedEncodingException e) |
| 570 |
|
{ |
| 571 |
0 |
enc = urlEncodings[c] = String.valueOf(c); |
| 572 |
|
} |
| 573 |
|
} |
| 574 |
0 |
return enc; |
| 575 |
|
} |
| 576 |
|
|
| 577 |
|
|
| 578 |
|
|
| 579 |
|
|
| 580 |
|
|
| 581 |
|
@param |
| 582 |
|
@return |
| 583 |
|
|
| |
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 9 |
Complexity Density: 1.12 |
|
| 584 |
0 |
public static boolean isHexString(String s)... |
| 585 |
|
{ |
| 586 |
0 |
int j = s.length(); |
| 587 |
0 |
if (j == 0) |
| 588 |
|
{ |
| 589 |
0 |
return false; |
| 590 |
|
} |
| 591 |
0 |
for (int i = 0; i < j; i++) |
| 592 |
|
{ |
| 593 |
0 |
int c = s.charAt(i); |
| 594 |
0 |
if (!(c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F')) |
| 595 |
|
{ |
| 596 |
0 |
return false; |
| 597 |
|
} |
| 598 |
|
} |
| 599 |
0 |
return true; |
| 600 |
|
} |
| 601 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 602 |
0 |
public static int firstCharPosIgnoreCase(String text, String chars)... |
| 603 |
|
{ |
| 604 |
0 |
int min = text.length() + 1; |
| 605 |
0 |
for (char c : chars.toLowerCase(Locale.ROOT).toCharArray()) |
| 606 |
|
{ |
| 607 |
0 |
int i = text.toLowerCase(Locale.ROOT).indexOf(c); |
| 608 |
0 |
if (0 <= i && i < min) |
| 609 |
|
{ |
| 610 |
0 |
min = i; |
| 611 |
|
} |
| 612 |
|
} |
| 613 |
0 |
return min < text.length() + 1 ? min : -1; |
| 614 |
|
} |
| 615 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
| 616 |
0 |
public static boolean equalsIgnoreCase(String s1, String s2)... |
| 617 |
|
{ |
| 618 |
0 |
if (s1 == null || s2 == null) |
| 619 |
|
{ |
| 620 |
0 |
return s1 == s2; |
| 621 |
|
} |
| 622 |
0 |
return s1.toLowerCase(Locale.ROOT).equals(s2.toLowerCase(Locale.ROOT)); |
| 623 |
|
} |
| 624 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 625 |
0 |
public static int indexOfFirstWhitespace(String text)... |
| 626 |
|
{ |
| 627 |
0 |
int index = -1; |
| 628 |
0 |
Pattern pat = Pattern.compile("\\s"); |
| 629 |
0 |
Matcher m = pat.matcher(text); |
| 630 |
0 |
if (m.find()) |
| 631 |
|
{ |
| 632 |
0 |
index = m.start(); |
| 633 |
|
} |
| 634 |
0 |
return index; |
| 635 |
|
} |
| 636 |
|
|
| 637 |
|
|
| 638 |
|
|
| 639 |
|
|
| 640 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 641 |
0 |
public static String replaceLast(String string, String toReplace,... |
| 642 |
|
String replacement) |
| 643 |
|
{ |
| 644 |
0 |
int pos = string.lastIndexOf(toReplace); |
| 645 |
0 |
if (pos > -1) |
| 646 |
|
{ |
| 647 |
0 |
return new StringBuilder().append(string.substring(0, pos)) |
| 648 |
|
.append(replacement) |
| 649 |
|
.append(string.substring(pos + toReplace.length())) |
| 650 |
|
.toString(); |
| 651 |
|
} |
| 652 |
|
else |
| 653 |
|
{ |
| 654 |
0 |
return string; |
| 655 |
|
} |
| 656 |
|
|
| 657 |
|
} |
| 658 |
|
|
| 659 |
|
|
| 660 |
|
|
| 661 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 662 |
0 |
public static int maxLength(List<String> l)... |
| 663 |
|
{ |
| 664 |
0 |
int max = 0; |
| 665 |
0 |
for (String s : l) |
| 666 |
|
{ |
| 667 |
0 |
if (s == null) |
| 668 |
0 |
continue; |
| 669 |
0 |
if (s.length() > max) |
| 670 |
0 |
max = s.length(); |
| 671 |
|
} |
| 672 |
0 |
return max; |
| 673 |
|
} |
| 674 |
|
|
| 675 |
|
|
| 676 |
|
|
| 677 |
|
|
| 678 |
|
|
| 679 |
|
private final static String fixedSalt = "Fixed Jalview Salt String"; |
| 680 |
|
|
| 681 |
|
|
| 682 |
|
|
| 683 |
|
|
| 684 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 685 |
0 |
public static byte[] getHashedBytes(String name)... |
| 686 |
|
{ |
| 687 |
0 |
byte[] digestBytes = DigestUtils |
| 688 |
|
.computeSHA256((name + fixedSalt).getBytes(DigestUtils.enc)); |
| 689 |
0 |
if (digestBytes == null) |
| 690 |
|
{ |
| 691 |
0 |
Console.warn("No SHA256 digest bytes retrieved"); |
| 692 |
|
} |
| 693 |
0 |
return digestBytes; |
| 694 |
|
} |
| 695 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 696 |
0 |
public static boolean isStartsWithAlphabetOrUnderScore(String value)... |
| 697 |
|
{ |
| 698 |
0 |
return value != null && value.matches("^[a-zA-Z_].*"); |
| 699 |
|
} |
| 700 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 701 |
0 |
public static boolean isValidFloat(String str)... |
| 702 |
|
{ |
| 703 |
0 |
try |
| 704 |
|
{ |
| 705 |
0 |
Float.parseFloat(str); |
| 706 |
0 |
return true; |
| 707 |
|
} catch (NumberFormatException e) |
| 708 |
|
{ |
| 709 |
0 |
return false; |
| 710 |
|
} |
| 711 |
|
} |
| 712 |
|
} |