|
1 | 1 | package com.openize.drako; |
2 | 2 |
|
3 | 3 |
|
4 | | -import java.lang.reflect.Array; |
5 | | -import java.text.DateFormat; |
6 | | -import java.text.ParseException; |
7 | | -import java.text.SimpleDateFormat; |
8 | 4 | import java.util.*; |
9 | 5 |
|
10 | 6 | /** |
@@ -117,48 +113,6 @@ private static char[] encode (byte[] in, int iOff, int iLen) { |
117 | 113 | } |
118 | 114 | return out; |
119 | 115 | } |
120 | | - /** |
121 | | - * Format date in ISO 8601 format |
122 | | - * @param date |
123 | | - * @return |
124 | | - */ |
125 | | - public static String formatISO8601(Date date) { |
126 | | - |
127 | | - TimeZone tz = TimeZone.getTimeZone("UTC"); |
128 | | - DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); |
129 | | - df.setTimeZone(tz); |
130 | | - return df.format(date); |
131 | | - } |
132 | | - public static String formatISO8601(Calendar date) { |
133 | | - return formatISO8601(date.getTime()); |
134 | | - } |
135 | | - |
136 | | - public static Calendar parseISO8601(String str) { |
137 | | - long t = parseISO8601AsMilliseconds(str); |
138 | | - if(t == -1) |
139 | | - return null; |
140 | | - Calendar ret = Calendar.getInstance(); |
141 | | - ret.setTimeInMillis(t); |
142 | | - return ret; |
143 | | - } |
144 | | - private static SimpleDateFormat[] iso8601Formats = { |
145 | | - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"), |
146 | | - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'") |
147 | | - }; |
148 | | - private static long parseISO8601AsMilliseconds(String str) |
149 | | - { |
150 | | - for(int i = 0; i < iso8601Formats.length; i++) { |
151 | | - synchronized (iso8601Formats[i]) { |
152 | | - try { |
153 | | - Date date = iso8601Formats[i].parse(str); |
154 | | - return date.getTime(); |
155 | | - } catch (ParseException e) { |
156 | | - |
157 | | - } |
158 | | - } |
159 | | - } |
160 | | - return -1; |
161 | | - } |
162 | 116 |
|
163 | 117 | public static void blockCopy(Object src, int srcOffset, Object dst, int dstOffset, int count) { |
164 | 118 | if(dst == null || src == null) |
@@ -393,22 +347,7 @@ public static Object changeType(Object value, Class<?> clazz) { |
393 | 347 | public static Class<?> getUnderlyingType(Object value) { |
394 | 348 | throw new RuntimeException("Not implemented"); |
395 | 349 | } |
396 | | - public static boolean parseDateTime(String input, String pattern, @Out Calendar[] ret) |
397 | | - { |
398 | | - try { |
399 | | - |
400 | | - String newPattern = normalizeDateFormat(pattern); |
401 | | - SimpleDateFormat sdf = new SimpleDateFormat(newPattern); |
402 | | - Date d = sdf.parse(trim(input)); |
403 | | - ret[0] = Calendar.getInstance(); |
404 | | - ret[0].setTimeInMillis(d.getTime()); |
405 | | - return true; |
406 | | - } catch (Exception e) { |
407 | | - ret[0] = null; |
408 | | - return false; |
409 | | - |
410 | | - } |
411 | | - } |
| 350 | + |
412 | 351 |
|
413 | 352 | /** |
414 | 353 | * Convert .net style date format into java's style |
@@ -479,104 +418,59 @@ public static List<?> asList(Object array) |
479 | 418 | } |
480 | 419 | public static List<Character> asList(char[] array) |
481 | 420 | { |
482 | | - return new ListUtils.NativeArrayList<Character>(array); |
| 421 | + ArrayList<Character> ret = new ArrayList<>(array.length); |
| 422 | + for(char c : array) |
| 423 | + ret.add(c); |
| 424 | + return ret; |
483 | 425 | } |
484 | 426 | public static List<Boolean> asList(boolean[] array) |
485 | 427 | { |
486 | | - return new ListUtils.NativeArrayList<Boolean>(array); |
| 428 | + ArrayList<Boolean> ret = new ArrayList<>(array.length); |
| 429 | + for(boolean b : array) |
| 430 | + ret.add(b); |
| 431 | + return ret; |
487 | 432 | } |
488 | 433 | public static List<Byte> asList(byte[] array) |
489 | 434 | { |
490 | | - return new ListUtils.NativeArrayList<Byte>(array); |
| 435 | + ArrayList<Byte> ret = new ArrayList<>(array.length); |
| 436 | + for(byte b : array) |
| 437 | + ret.add(b); |
| 438 | + return ret; |
491 | 439 | } |
492 | 440 | public static List<Short> asList(short[] array) |
493 | 441 | { |
494 | | - return new ListUtils.NativeArrayList<Short>(array); |
| 442 | + ArrayList<Short> ret = new ArrayList<>(array.length); |
| 443 | + for(short s : array) |
| 444 | + ret.add(s); |
| 445 | + return ret; |
495 | 446 | } |
496 | 447 | public static List<Integer> asList(int[] array) |
497 | 448 | { |
498 | 449 | return new ListUtils.IntList(array); |
499 | 450 | } |
500 | 451 | public static List<Long> asList(long[] array) |
501 | 452 | { |
502 | | - return new ListUtils.NativeArrayList<Long>(array); |
| 453 | + ArrayList<Long> ret = new ArrayList<>(array.length); |
| 454 | + for(long l : array) |
| 455 | + ret.add(l); |
| 456 | + return ret; |
503 | 457 | } |
504 | 458 | public static List<Float> asList(float[] array) |
505 | 459 | { |
506 | | - return new ListUtils.NativeArrayList<Float>(array); |
| 460 | + ArrayList<Float> ret = new ArrayList<>(array.length); |
| 461 | + for(float f : array) |
| 462 | + ret.add(f); |
| 463 | + return ret; |
507 | 464 | } |
508 | 465 | public static List<Double> asList(double[] array) |
509 | 466 | { |
510 | | - return new ListUtils.NativeArrayList<Double>(array); |
| 467 | + ArrayList<Double> ret = new ArrayList<>(array.length); |
| 468 | + for(double d : array) |
| 469 | + ret.add(d); |
| 470 | + return ret; |
511 | 471 | } |
512 | 472 |
|
513 | 473 |
|
514 | | - /** |
515 | | - * Unbox the boxed array to primitive array |
516 | | - * e.g. Convert Object[] to int[] |
517 | | - * Call unbox(array, int.class) |
518 | | - * @param array array of boxed type |
519 | | - * @return array of primitive type |
520 | | - */ |
521 | | - public static Object unbox(Object[] array, Class<?> elementType) |
522 | | - { |
523 | | - if(array == null) |
524 | | - throw new IllegalArgumentException("array cannot be null"); |
525 | | - if(elementType == null) |
526 | | - throw new IllegalArgumentException("elementType cannot be null"); |
527 | | - |
528 | | - Object ret = Array.newInstance(elementType, array.length); |
529 | | - if(array.length > 0) { |
530 | | - if(elementType == int.class) { |
531 | | - int[] ints = (int[]) ret; |
532 | | - for (int i = 0; i < array.length; i++) { |
533 | | - ints[i] = ((Number) array[i]).intValue(); |
534 | | - } |
535 | | - } else if(elementType == short.class) { |
536 | | - short[] vals = (short[]) ret; |
537 | | - for (int i = 0; i < array.length; i++) { |
538 | | - vals[i] = ((Number) array[i]).shortValue(); |
539 | | - } |
540 | | - } else if(elementType == byte.class) { |
541 | | - byte[] vals = (byte[]) ret; |
542 | | - for (int i = 0; i < array.length; i++) { |
543 | | - vals[i] = ((Number) array[i]).byteValue(); |
544 | | - } |
545 | | - } else if(elementType == long.class) { |
546 | | - long[] vals = (long[]) ret; |
547 | | - for (int i = 0; i < array.length; i++) { |
548 | | - vals[i] = ((Number) array[i]).longValue(); |
549 | | - } |
550 | | - } else if(elementType == double.class) { |
551 | | - double[] vals = (double[]) ret; |
552 | | - for (int i = 0; i < array.length; i++) { |
553 | | - vals[i] = ((Number) array[i]).doubleValue(); |
554 | | - } |
555 | | - } else if(elementType == float.class) { |
556 | | - float[] vals = (float[]) ret; |
557 | | - for (int i = 0; i < array.length; i++) { |
558 | | - vals[i] = ((Number) array[i]).floatValue(); |
559 | | - } |
560 | | - } else if(elementType == boolean.class) { |
561 | | - boolean[] vals = (boolean[]) ret; |
562 | | - for (int i = 0; i < array.length; i++) { |
563 | | - vals[i] = (Boolean) array[i]; |
564 | | - } |
565 | | - } else if(elementType == char.class) { |
566 | | - char[] vals = (char[]) ret; |
567 | | - for (int i = 0; i < array.length; i++) { |
568 | | - vals[i] = (Character) array[i]; |
569 | | - } |
570 | | - } else { |
571 | | - //generic version, slow but for all types |
572 | | - for (int i = 0; i < array.length; i++) { |
573 | | - Array.set(ret, i, array[i]); |
574 | | - } |
575 | | - } |
576 | | - } |
577 | | - return ret; |
578 | | - |
579 | | - } |
580 | 474 | /** |
581 | 475 | * Unbox the boxed array to primitive array |
582 | 476 | * @param array array of boxed type |
|
0 commit comments