Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Copyright 2014-2015 the original author or authors.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
   * either express or implied. See the License for the specific language
   * governing permissions and limitations under the License.
   */
  package org.dbflute.util;
  
  import java.sql.Time;
  import java.time.ZoneId;
  import java.util.Date;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  import java.util.UUID;
  

Author(s):
modified by jflute (originated in Seasar2)
  
  public final class DfTypeUtil {
  
      // ===================================================================================
      //                                                                          Definition
      //                                                                          ==========
      public static final String HYPHENED_DATE_PATTERN = "yyyy-MM-dd";
      public static final String SLASHED_DATE_PATTERN = "yyyy/MM/dd";
      public static final String COLONED_TIME_PATTERN = "HH:mm:ss";
      public static final String PLAIN_MILLIS_PATTERN = "SSS";
      public static final String HYPHENED_TIMESTAMP_PATTERN;
      static {
      }
      public static final String SLASHED_TIMESTAMP_PATTERN;
      static {
      }
      // *hyphen basis in program, so the default patterns are hyphened
      // while, slash basis in human view (so HandyDate#toDisp() uses slashed)
      public static final String DEFAULT_DATE_PATTERN = ;
      public static final String DEFAULT_TIMESTAMP_PATTERN = ;
      public static final String DEFAULT_TIME_PATTERN = ;
  
      protected static final String NULL = "null";
      protected static final String[] EMPTY_STRINGS = new String[0];
      protected static final long GMT_AD_ORIGIN_MILLISECOND;
      static {
          final Calendar cal = Calendar.getInstance();
          cal.clear();
          cal.setTimeZone(TimeZone.getTimeZone("GMT"));
          cal.set(1, 0, 1, 0, 0, 0);
          cal.set(., 0);
          // AD0001/01/01 00:00:00.000
           = cal.getTimeInMillis();
  
          // *the value of millisecond may depend on JDK implementation
      }
  
      private static final char[] ENCODE_TABLE = { 'A''B''C''D''E''F''G''H''I''J''K''L''M''N''O''P''Q''R',
              'S''T''U''V''W''X''Y''Z''a''b''c''d''e''f''g''h''i''j''k''l''m''n''o''p''q',
             'r''s''t''u''v''w''x''y''z''0''1''2''3''4''5''6''7''8''9''+''/' };
 
     private static final char PAD = '=';
 
     private static final byte[] DECODE_TABLE = new byte[128];
     static {
         for (int i = 0; i < .i++) {
             [i] = .;
         }
         for (int i = 0; i < .i++) {
             [[i]] = (bytei;
         }
     }
 
     // ===================================================================================
     //                                                                              String
     //                                                                              ======
     // -----------------------------------------------------
     //                                            toString()
     //                                            ----------
     
Convert the object to the instance that is string.
 e.g.
  date       :: use the default time-zone.
  byte array :: encode as base64.
  exception  :: convert to stack-trace.
 

Parameters:
obj The parsed object. (NullAllowed: if null, returns null)
Returns:
The converted string. (NullAllowed: when the argument is null)
 
     public static String toString(Object obj) {
         return doConvertToString(obj, (Stringnull);
     }

    
Convert the object to the instance that is string by the pattern.
 e.g.
  date       :: use the default time-zone.
  byte array :: encode as base64.
  exception  :: convert to stack-trace.
 

Parameters:
obj The parsed object. (NullAllowed: if null, returns null)
pattern The pattern format to parse for e.g. number, date. (NotNull)
Returns:
The converted string. (NullAllowed: when the argument is null)
 
     public static String toString(Object objString pattern) {
         assertPatternNotNull("toString()"pattern);
         return doConvertToString(objpattern);
     }
 
     protected static String doConvertToString(Object objString pattern) {
         if (obj == null) {
             return null;
         }
         if (obj instanceof String) {
             return (Stringobj;
         } else if (obj instanceof Number) {
             return doConvertToStringNumber((Numberobjpattern);
         } else if (obj instanceof LocalDate) {
             return doConvertToStringLocalDate((LocalDateobjpattern);
         } else if (obj instanceof LocalDateTime) {
             return doConvertToStringLocalDateTime((LocalDateTimeobjpattern);
         } else if (obj instanceof LocalTime) {
             return doConvertToStringLocalTime((LocalTimeobjpattern);
         } else if (obj instanceof Time) {
             final String realPattern = pattern != null ? pattern : ;
             return doConvertToStringDate((Timeobj, (TimeZonenullrealPattern, (Localenull);
         } else if (obj instanceof Date) {
             return doConvertToStringDate((Dateobj, (TimeZonenullpattern, (Localenull);
         } else if (obj instanceof Calendar) {
             return doConvertToStringDate(((Calendarobj).getTime(), (TimeZonenullpattern, (Localenull);
         } else if (obj instanceof byte[]) {
             return encodeAsBase64((byte[]) obj);
         } else if (obj instanceof Throwable) {
             return toStringStackTrace((Throwableobj);
         } else {
             return obj.toString();
         }
     }
 
     // -----------------------------------------------------
     //                                        Specified Type
     //                                        --------------
     
Convert the number to the instance that is string by the pattern.

Parameters:
number The parsed number to be string. (NullAllowed: if null, returns null)
pattern The pattern format to parse as number. (NotNull)
Returns:
The converted string. (NullAllowed: when the argument is null)
 
     public static String toStringNumber(Number numberString pattern) {
         assertPatternNotNull("toStringNumber()"pattern);
         return number != null ? doConvertToStringNumber(numberpattern) : null;
     }
 
     protected static String doConvertToStringNumber(Number valueString pattern) {
         if (pattern != null) {
             return createDecimalFormat(pattern).format(value);
         }
         return value.toString();
     }

    
Convert the local date to the instance that is string by the pattern.

Parameters:
date The parsed local date to be string. (NullAllowed: if null, returns null)
pattern The pattern format to parse as local date. (NotNull)
Returns:
The converted string. (NullAllowed: when the argument is null)
 
     public static String toStringDate(LocalDate dateString pattern) {
         assertPatternNotNull("toStringDate()"pattern);
         return date != null ? doConvertToStringLocalDate(datepattern) : null;
     }
 
     protected static String doConvertToStringLocalDate(LocalDate valueString pattern) {
         final String realPattern = pattern != null ? pattern : ;
         return value.format(DateTimeFormatter.ofPattern(realPattern));
     }

    
Convert the local date-time to the instance that is string by the pattern.

Parameters:
date The parsed local date-time to be string. (NullAllowed: if null, returns null)
pattern The pattern format to parse as local date-time. (NotNull)
Returns:
The converted string. (NullAllowed: when the argument is null)
 
     public static String toStringDate(LocalDateTime dateString pattern) {
         assertPatternNotNull("toStringDate()"pattern);
         return date != null ? doConvertToStringLocalDateTime(datepattern) : null;
     }
 
     protected static String doConvertToStringLocalDateTime(LocalDateTime valueString pattern) {
         final String realPattern = pattern != null ? pattern : // only millisecond (not nanosecond) as default
         return value.format(DateTimeFormatter.ofPattern(realPattern));
     }

    
Convert the local time to the instance that is string by the pattern.

Parameters:
date The parsed local time to be string. (NullAllowed: if null, returns null)
pattern The pattern format to parse as local time. (NotNull)
Returns:
The converted string. (NullAllowed: when the argument is null)
 
     public static String toStringDate(LocalTime dateString pattern) {
         assertPatternNotNull("toStringDate()"pattern);
         return date != null ? doConvertToStringLocalTime(datepattern) : null;
     }
 
     protected static String doConvertToStringLocalTime(LocalTime valueString pattern) {
         final String realPattern = pattern != null ? pattern : // not use nanosecond part as default
         return value.format(DateTimeFormatter.ofPattern(realPattern));
     }
 
     public static String toStringDate(Date valueTimeZone timeZoneString patternLocale locale) {
         assertTimeZoneNotNull("toStringDate()"timeZone);
         assertPatternNotNull("toStringDate()"pattern);
         assertLocaleNotNull("toStringDate()"locale);
         return value != null ? doConvertToStringDate(valuetimeZonepatternlocale) : null;
     }
 
     protected static String doConvertToStringDate(Date valueTimeZone timeZoneString patternLocale locale) {
         final String realPattern;
         if (value instanceof Time && pattern == null) {
             realPattern = ;
         } else {
             realPattern = pattern// null or specified (if null, default pattern of formatter)
         }
         return doCreateDateFormat(realPatterntimeZonelocalefalse).format(value);
     }
 
     public static String toStringStackTrace(Throwable cause) {
         StringWriter sw = null;
         try {
             sw = new StringWriter();
             cause.printStackTrace(new PrintWriter(sw));
             return sw.toString();
         } finally {
             if (sw != null) {
                 try {
                     sw.close();
                 } catch (IOException ignored) {}
             }
         }
     }
 
     // -----------------------------------------------------
     //                                           Class Title
     //                                           -----------
     
Convert the object to class title name.
 o com.example.Foo to Foo
 o com.example.Foo$Bar to Foo$Bar
 o com.example.Foo$1 to Foo$1
 o Foo to Foo
 o Foo$Bar to Foo$Bar
 
If the object is Class, it uses Class.getName() as convert target string.
If the object is String, it uses it directly as convert target string.
If the object is the other object, it uses obj.getClass().getName() as convert target string.

Parameters:
obj The target object. String or Class are treated as special. (NullAllowed: if null, returns null)
Returns:
The string as class title. (NullAllowed: when the argument is null)
 
     public static String toClassTitle(Object obj) {
         if (obj == null) {
             return null;
         }
         final String fqcn;
         if (obj instanceof Class<?>) {
             fqcn = ((Class<?>) obj).getName();
         } else if (obj instanceof String) {
             fqcn = (Stringobj;
         } else {
             fqcn = obj.getClass().getName();
         }
         if (fqcn == null || fqcn.trim().length() == 0) {
             return fqcn;
         }
         final int dotLastIndex = fqcn.lastIndexOf(".");
         if (dotLastIndex < 0) {
             return fqcn;
         }
         return fqcn.substring(dotLastIndex + ".".length());
     }
 
     // -----------------------------------------------------
     //                                                Encode
     //                                                ------
     public static String encodeAsBase64(final byte[] inData) {
         if (inData == null) {
             return null;
         }
         if (inData.length == 0) {
             return "";
         }
         final int mod = inData.length % 3;
         final int num = inData.length / 3;
         final char[] outData;
         if (mod != 0) {
             outData = new char[(num + 1) * 4];
         } else {
             outData = new char[num * 4];
         }
         for (int i = 0; i < numi++) {
             encode(inDatai * 3, outDatai * 4);
         }
         switch (mod) {
         case 1:
             encode2pad(inDatanum * 3, outDatanum * 4);
             break;
         case 2:
             encode1pad(inDatanum * 3, outDatanum * 4);
             break;
         }
         return new String(outData);
     }
 
     public static byte[] decodeAsBase64(final String inData) {
         int num = (inData.length() / 4) - 1;
         int lastBytes = getLastBytes(inData);
         byte[] outData = new byte[num * 3 + lastBytes];
         for (int i = 0; i < numi++) {
             decode(inDatai * 4, outDatai * 3);
         }
         switch (lastBytes) {
         case 1:
             decode1byte(inDatanum * 4, outDatanum * 3);
             break;
         case 2:
             decode2byte(inDatanum * 4, outDatanum * 3);
             break;
         default:
             decode(inDatanum * 4, outDatanum * 3);
         }
         return outData;
     }
 
     private static void encode(final byte[] inDatafinal int inIndexfinal char[] outDatafinal int outIndex) {
         int i = ((inData[inIndex] & 0xff) << 16) + ((inData[inIndex + 1] & 0xff) << 8) + (inData[inIndex + 2] & 0xff);
         outData[outIndex] = [i >> 18];
         outData[outIndex + 1] = [(i >> 12) & 0x3f];
         outData[outIndex + 2] = [(i >> 6) & 0x3f];
         outData[outIndex + 3] = [i & 0x3f];
     }
 
     private static void encode2pad(final byte[] inDatafinal int inIndexfinal char[] outDatafinal int outIndex) {
         int i = inData[inIndex] & 0xff;
         outData[outIndex] = [i >> 2];
         outData[outIndex + 1] = [(i << 4) & 0x3f];
         outData[outIndex + 2] = ;
         outData[outIndex + 3] = ;
     }
 
     private static void encode1pad(final byte[] inDatafinal int inIndexfinal char[] outDatafinal int outIndex) {
         int i = ((inData[inIndex] & 0xff) << 8) + (inData[inIndex + 1] & 0xff);
         outData[outIndex] = [i >> 10];
         outData[outIndex + 1] = [(i >> 4) & 0x3f];
         outData[outIndex + 2] = [(i << 2) & 0x3f];
         outData[outIndex + 3] = ;
     }
 
     private static void decode(final String inDatafinal int inIndexfinal byte[] outDatafinal int outIndex) {
         byte b0 = [inData.charAt(inIndex)];
         byte b1 = [inData.charAt(inIndex + 1)];
         byte b2 = [inData.charAt(inIndex + 2)];
         byte b3 = [inData.charAt(inIndex + 3)];
         outData[outIndex] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
         outData[outIndex + 1] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
         outData[outIndex + 2] = (byte) (b2 << 6 & 0xc0 | b3 & 0x3f);
     }
 
     private static void decode1byte(final String inDatafinal int inIndexfinal byte[] outDatafinal int outIndex) {
         byte b0 = [inData.charAt(inIndex)];
         byte b1 = [inData.charAt(inIndex + 1)];
         outData[outIndex] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
     }
 
     private static void decode2byte(final String inDatafinal int inIndexfinal byte[] outDatafinal int outIndex) {
         byte b0 = [inData.charAt(inIndex)];
         byte b1 = [inData.charAt(inIndex + 1)];
         byte b2 = [inData.charAt(inIndex + 2)];
         outData[outIndex] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
         outData[outIndex + 1] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
     }
 
     private static int getLastBytes(final String inData) {
         int len = inData.length();
         if (inData.charAt(len - 2) == ) {
             return 1;
         } else if (inData.charAt(len - 1) == ) {
             return 2;
         } else {
             return 3;
         }
     }
 
     // ===================================================================================
     //                                                                              Number
     //                                                                              ======
     
Convert to number object.

Parameters:
obj The resource of number. (NullAllowed: if null, returns null)
type The type of number. (NotNull)
Returns:
The number object from resource. (NullAllowed: if type is not number, returns null)
 
     public static Number toNumber(Object objClass<?> type) {
         if (obj == null) {
             return null;
         }
         // Integer, Long and BigDecimal are prior
         if (type == Integer.class) {
             return toInteger(obj);
         } else if (type == Long.class) {
             return toLong(obj);
         } else if (type == BigDecimal.class) {
             return toBigDecimal(obj);
         } else if (type == Double.class) {
             return toDouble(obj);
         } else if (type == Float.class) {
             return toFloat(obj);
         } else if (type == Short.class) {
             return toShort(obj);
         } else if (type == Byte.class) {
             return toByte(obj);
         } else if (type == BigInteger.class) {
             return toBigInteger(obj);
         }
         return null// could not convert
     }
 
     // -----------------------------------------------------
     //                                             Normalize
     //                                             ---------
     protected static String normalize(String value) {
         return normalize(value, Locale.getDefault());
     }
 
     protected static String normalize(String valueLocale locale) {
         if (value == null) {
             return null;
         }
         final DecimalFormatSymbols symbols = getDecimalFormatSymbols(locale);
         final char groupingSep = symbols.getGroupingSeparator();
         final char decimalSep = symbols.getDecimalSeparator();
         final StringBuilder sb = new StringBuilder(20);
         for (int i = 0; i < value.length(); ++i) {
             char c = value.charAt(i);
             if (c == groupingSep) {
                 continue;
             } else if (c == decimalSep) {
                 c = '.';
             }
             sb.append(c);
         }
         return sb.toString();
     }
 
     // -----------------------------------------------------
     //                                          NumberFormat
     //                                          ------------
     public static DecimalFormat createDecimalFormat(String pattern) {
         final Locale realLocale = chooseRealLocale(null);
         final DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(realLocale);
         return new DecimalFormat(patternsymbols);
     }
 
     // ===================================================================================
     //                                                                             Integer
     //                                                                             =======
     

Parameters:
obj The resource value to integer. (NullAllowed)
Returns:
The value as integer. (NullAllowed: if null or empty argument, returns null)
Throws:
java.lang.NumberFormatException When the object cannot be parsed.
 
     public static Integer toInteger(Object obj) {
         return doConvertToInteger(objnull);
     }
 
     public static Integer toInteger(Object objString pattern) {
         assertPatternNotNull("toInteger()"pattern);
         return doConvertToInteger(objpattern);
     }
 
     protected static Integer doConvertToInteger(Object objString pattern) {
         if (obj == null) {
             return null;
         } else if (obj instanceof Integer) {
             return (Integerobj;
         } else if (obj instanceof Number) {
             return Integer.valueOf(((Numberobj).intValue());
         } else if (obj instanceof String) {
             return doParseStringAsInteger((Stringobj);
         } else if (obj instanceof java.util.Date) {
             if (pattern != null) {
                 final DateFormat dateFormat = createDateFormat(pattern);
                 return Integer.valueOf(dateFormat.format(obj));
             }
             return Integer.valueOf((int) ((java.util.Dateobj).getTime());
         } else if (obj instanceof Boolean) {
             return ((Booleanobj).booleanValue() ? Integer.valueOf(1) : Integer.valueOf(0);
         } else if (obj instanceof byte[]) {
             return toInteger(toSerializable((byte[]) obj)); // recursive
         } else {
             return doParseStringAsInteger(obj.toString());
         }
     }
 
     protected static Integer doParseStringAsInteger(String str) {
         if (str == null || str.trim().length() == 0) {
             return null;
         }
         return Integer.valueOf(normalize(str));
     }
 
     public static int toPrimitiveInt(Object obj) {
         return doConvertToPrimitiveInt(objnull);
     }
 
     public static int toPrimitiveInt(Object objString pattern) {
         assertPatternNotNull("toPrimitiveInt()"pattern);
         return doConvertToPrimitiveInt(objpattern);
     }
 
     protected static int doConvertToPrimitiveInt(Object objString pattern) {
         final Integer wrapper = doConvertToInteger(objpattern);
         return wrapper != null ? wrapper.intValue() : 0;
     }
 
     // ===================================================================================
     //                                                                                Long
     //                                                                                ====
     

Parameters:
obj The resource value to long. (NullAllowed)
Returns:
The value as long. (NullAllowed: if null or empty argument, returns null)
Throws:
java.lang.NumberFormatException When the object cannot be parsed.
 
     public static Long toLong(Object obj) {
         return doConvertToLong(objnull);
     }
 
     public static Long toLong(Object objString pattern) {
         assertPatternNotNull("toLong()"pattern);
         return doConvertToLong(objpattern);
     }
 
     protected static Long doConvertToLong(Object objString pattern) {
         if (obj == null) {
             return null;
         } else if (obj instanceof Long) {
             return (Longobj;
         } else if (obj instanceof Number) {
             return Long.valueOf(((Numberobj).longValue());
         } else if (obj instanceof String) {
             return doParseStringAsLong((Stringobj);
         } else if (obj instanceof java.util.Date) {
             if (pattern != null) {
                 final DateFormat dateFormat = createDateFormat(pattern);
                 return Long.valueOf(dateFormat.format(obj));
             }
             return Long.valueOf(((java.util.Dateobj).getTime());
         } else if (obj instanceof Boolean) {
             return ((Booleanobj).booleanValue() ? Long.valueOf(1) : Long.valueOf(0);
         } else if (obj instanceof byte[]) {
             return toLong(toSerializable((byte[]) obj)); // recursive
         } else {
             return doParseStringAsLong(obj.toString());
         }
     }
 
     protected static Long doParseStringAsLong(String str) {
         if (str == null || str.trim().length() == 0) {
             return null;
         }
         return new Long(normalize(str));
     }
 
     public static long toPrimitiveLong(Object obj) {
         return doConvertToPrimitiveLong(objnull);
     }
 
     public static long toPrimitiveLong(Object objString pattern) {
         assertPatternNotNull("toPrimitiveLong()"pattern);
         return doConvertToPrimitiveLong(objpattern);
     }
 
     protected static long doConvertToPrimitiveLong(Object objString pattern) {
         final Long wrapper = doConvertToLong(objpattern);
         return wrapper != null ? wrapper.longValue() : 0L;
     }
 
     // ===================================================================================
     //                                                                              Double
     //                                                                              ======
     public static Double toDouble(Object obj) {
         return toDouble(objnull);
     }
 
     public static Double toDouble(Object objString pattern) {
         assertPatternNotNull("toDouble()"pattern);
         return doConvertToDouble(objpattern);
     }
 
     protected static Double doConvertToDouble(Object objString pattern) {
         if (obj == null) {
             return null;
         } else if (obj instanceof Double) {
             return (Doubleobj;
         } else if (obj instanceof Number) {
             return Double.valueOf(((Numberobj).doubleValue());
         } else if (obj instanceof String) {
             return doParseStringAsDouble((Stringobj);
         } else if (obj instanceof java.util.Date) {
             if (pattern != null) {
                 final DateFormat dateFormat = createDateFormat(pattern);
                 return Double.valueOf(dateFormat.format(obj));
             }
             return Double.valueOf(((java.util.Dateobj).getTime());
         } else if (obj instanceof byte[]) {
             return toDouble(toSerializable((byte[]) obj)); // recursive
         } else {
             return doParseStringAsDouble(obj.toString());
         }
     }
 
     protected static Double doParseStringAsDouble(String str) {
         if (str == null || str.trim().length() == 0) {
             return null;
         }
         return new Double(normalize(str));
     }
 
     public static double toPrimitiveDouble(Object obj) {
         return doConvertToPrimitiveDouble(objnull);
     }
 
     public static double toPrimitiveDouble(Object objString pattern) {
         assertPatternNotNull("toPrimitiveDouble()"pattern);
         return doConvertToPrimitiveDouble(objpattern);
     }
 
     protected static double doConvertToPrimitiveDouble(Object objString pattern) {
         final Double wrapper = doConvertToDouble(objpattern);
         return wrapper != null ? wrapper.doubleValue() : 0;
     }
 
     // ===================================================================================
     //                                                                               Float
     //                                                                               =====
     public static Float toFloat(Object obj) {
         return doConvertToFloat(objnull);
     }
 
     public static Float toFloat(Object objString pattern) {
         assertPatternNotNull("toFloat()"pattern);
         return doConvertToFloat(objpattern);
     }
 
     protected static Float doConvertToFloat(Object objString pattern) {
         if (obj == null) {
             return null;
         } else if (obj instanceof Float) {
             return (Floatobj;
         } else if (obj instanceof Number) {
             return Float.valueOf(((Numberobj).floatValue());
         } else if (obj instanceof String) {
             return doParseStringAsFloat((Stringobj);
         } else if (obj instanceof java.util.Date) {
             if (pattern != null) {
                 final DateFormat dateFormat = createDateFormat(pattern);
                 return Float.valueOf(dateFormat.format(obj));
             }
             return Float.valueOf(((java.util.Dateobj).getTime());
         } else if (obj instanceof byte[]) {
             return toFloat(toSerializable((byte[]) obj)); // recursive
         } else {
             return doParseStringAsFloat(obj.toString());
         }
     }
 
     protected static Float doParseStringAsFloat(String str) {
         if (str == null || str.trim().length() == 0) {
             return null;
         }
         return new Float(normalize(str));
     }
 
     public static float toPrimitiveFloat(Object obj) {
         return doConvertToPrimitiveFloat(objnull);
     }
 
     public static float toPrimitiveFloat(Object objString pattern) {
         assertPatternNotNull("toPrimitiveFloat()"pattern);
         return doConvertToPrimitiveFloat(objpattern);
     }
 
     protected static float doConvertToPrimitiveFloat(Object objString pattern) {
         final Float wrapper = doConvertToFloat(objpattern);
         return wrapper != null ? wrapper.floatValue() : 0;
     }
 
     // ===================================================================================
     //                                                                               Short
     //                                                                               =====
     public static Short toShort(Object obj) {
         return doConvertToShort(objnull);
     }
 
     public static Short toShort(Object objString pattern) {
         assertPatternNotNull("toShort()"pattern);
         return doConvertToShort(objpattern);
     }
 
     protected static Short doConvertToShort(Object objString pattern) {
         if (obj == null) {
             return null;
         } else if (obj instanceof Short) {
             return (Shortobj;
         } else if (obj instanceof Number) {
             return Short.valueOf(((Numberobj).shortValue());
         } else if (obj instanceof String) {
             return toShort((Stringobj);
         } else if (obj instanceof java.util.Date) {
             if (pattern != null) {
                 final DateFormat dateFormat = createDateFormat(pattern);
                 return Short.valueOf(dateFormat.format(obj));
             }
             return Short.valueOf((short) ((java.util.Dateobj).getTime());
         } else if (obj instanceof Boolean) {
             return ((Booleanobj).booleanValue() ? Short.valueOf((short) 1) : Short.valueOf((short) 0);
         } else if (obj instanceof byte[]) {
             return toShort(toSerializable((byte[]) obj)); // recursive
         } else {
             return toShort(obj.toString());
         }
     }
 
     protected static Short toShort(String str) {
         if (str == null || str.trim().length() == 0) {
             return null;
         }
         return new Short(normalize(str));
     }
 
     public static short toPrimitiveShort(Object obj) {
         return toPrimitiveShort(objnull);
     }
 
     public static short toPrimitiveShort(Object objString pattern) {
         assertPatternNotNull("toPrimitiveShort()"pattern);
         return doConvertToPrimitiveShort(objpattern);
     }
 
     protected static short doConvertToPrimitiveShort(Object objString pattern) {
         final Short wrapper = doConvertToShort(objpattern);
         return wrapper != null ? wrapper.shortValue() : 0;
     }
 
     // ===================================================================================
     //                                                                                Byte
     //                                                                                ====
     public static Byte toByte(Object obj) {
         return doConvertToByte(objnull);
     }
 
     public static Byte toByte(Object objString pattern) {
         assertPatternNotNull("toByte()"pattern);
         return doConvertToByte(objpattern);
     }
 
     protected static Byte doConvertToByte(Object objString pattern) {
         if (obj == null) {
             return null;
         } else if (obj instanceof Byte) {
             return (Byteobj;
         } else if (obj instanceof Number) {
             return Byte.valueOf(((Numberobj).byteValue());
         } else if (obj instanceof String) {
             return toByte((Stringobj);
         } else if (obj instanceof java.util.Date) {
             if (pattern != null) {
                 final DateFormat dateFormat = createDateFormat(pattern);
                 return Byte.valueOf(dateFormat.format(obj));
             }
             return Byte.valueOf((byte) ((java.util.Dateobj).getTime());
         } else if (obj instanceof Boolean) {
             return ((Booleanobj).booleanValue() ? Byte.valueOf((byte) 1) : Byte.valueOf((byte) 0);
         } else if (obj instanceof byte[]) {
             return toByte(toSerializable((byte[]) obj)); // recursive
         } else {
             return toByte(obj.toString());
         }
     }
 
     protected static Byte toByte(String str) {
         if (str == null || str.trim().length() == 0) {
             return null;
         }
         return new Byte(normalize(str));
     }
 
     public static byte toPrimitiveByte(Object obj) {
         return doConvertToPrimitiveByte(objnull);
     }
 
     public static byte toPrimitiveByte(Object objString pattern) {
         assertPatternNotNull("toPrimitiveByte()"pattern);
         return doConvertToPrimitiveByte(objpattern);
     }
 
     protected static byte doConvertToPrimitiveByte(Object objString pattern) {
         final Byte wrapper = doConvertToByte(objpattern);
         return wrapper != null ? wrapper.byteValue() : 0;
     }
 
     // -----------------------------------------------------
     //                                                 Bytes
     //                                                 -----
     public static byte[] toBytes(String strString encoding) {
         if (str == null) {
             return null;
         }
         try {
             return str.getBytes(encoding);
         } catch (UnsupportedEncodingException e) {
             String msg = "The encoding is invalid: encoding=" + encoding + " str=" + str;
             throw new IllegalStateException(msg);
         }
     }
 
     // ===================================================================================
     //                                                                          BigDecimal
     //                                                                          ==========
     public static BigDecimal toBigDecimal(Object obj) {
         return doConvertToBigDecimal(objnull);
     }
 
     public static BigDecimal toBigDecimal(Object objString pattern) {
         assertPatternNotNull("toBigDecimal()"pattern);
         return doConvertToBigDecimal(objpattern);
     }
 
     protected static BigDecimal doConvertToBigDecimal(Object objString pattern) {
         if (obj == null) {
             return null;
         } else if (obj instanceof BigDecimal) {
             final BigDecimal paramBigDecimal = (BigDecimalobj;
             if (BigDecimal.class.equals(paramBigDecimal.getClass())) { // pure big-decimal
                 return paramBigDecimal;
             } else { // sub class
                 // because the big-decimal type is not final class.
                 return new BigDecimal(paramBigDecimal.toPlainString());
             }
         } else if (obj instanceof java.util.Date) {
             if (pattern != null) {
                 final DateFormat dateFormat = createDateFormat(pattern);
                 return new BigDecimal(dateFormat.format(obj));
             }
             return BigDecimal.valueOf(((java.util.Dateobj).getTime());
         } else if (obj instanceof String) {
             final String str = (Stringobj;
             if (str == null || str.trim().length() == 0) {
                 return null;
             }
             return new BigDecimal(new BigDecimal(str).toPlainString());
         } else if (obj instanceof byte[]) {
             return toBigDecimal(toSerializable((byte[]) obj)); // recursive
         } else {
             return new BigDecimal(new BigDecimal(obj.toString()).toPlainString());
         }
     }
 
     // ===================================================================================
     //                                                                          BigInteger
     //                                                                          ==========
     public static BigInteger toBigInteger(Object obj) {
         return doConvertToBigInteger(objnull);
     }
 
     public static BigInteger toBigInteger(Object objString pattern) {
         assertPatternNotNull("toBigInteger()"pattern);
         return doConvertToBigInteger(objpattern);
     }
 
     protected static BigInteger doConvertToBigInteger(Object objString pattern) {
         if (obj == null) {
             return null;
         } else if (obj instanceof BigInteger) {
             final BigInteger paramBigInteger = (BigIntegerobj;
             if (BigInteger.class.equals(paramBigInteger.getClass())) { // pure big-integer
                 return paramBigInteger;
             } else { // sub class
                 // because the big-integer type is not final class.
                 return new BigDecimal(paramBigInteger).toBigInteger();
             }
         } else if (obj instanceof BigDecimal) {
             return ((BigDecimalobj).toBigInteger();
         } else if (obj instanceof String) {
             final String str = (Stringobj;
             if (str.trim().length() == 0) {
                 return null;
             }
             return toBigDecimal(normalize(str)).toBigInteger();
         } else {
             Long lg = doConvertToLong(objpattern);
             if (lg == null) {
                 return null;
             }
             return BigInteger.valueOf(lg.longValue());
         }
     }
 
     // ===================================================================================
     //                                                                            Time API
     //                                                                            ========
     // -----------------------------------------------------
     //                                             LocalDate
     //                                             ---------
     
Convert the object to the instance that is date for the default time-zone.
This method uses default date pattern based on 'yyyy-MM-dd HH:mm:ss.SSS' with flexible-parsing if the object is string type.

If string expression is specified, The year, month, ... parts are parsed from the string. Then the time-zone is not used in conversion. It uses LocalDate.of().

Parameters:
obj The object to be converted. (NullAllowed: if null, returns null)
Returns:
The local date. (NullAllowed: when the argument is null)
Throws:
DfTypeUtil.ParseDateException When it failed to parse the string to date.
DfTypeUtil.ParseDateNumberFormatException When it failed to format the elements as number.
 
     public static LocalDate toLocalDate(Object obj) { // #date_parade
         return doConvertToLocalDate(obj, (Stringnull, (TimeZonenull);
     }

    
Convert the object to the instance that is date for the default time-zone.
This method uses the specified date pattern if the object is string type.

If string expression is specified, The year, month, ... parts are parsed from the string. Then the time-zone is not used in conversion. It uses LocalDate.parse().

Parameters:
obj The object to be converted. (NullAllowed: if null, returns null)
pattern The pattern format to parse when the object is string. (NotNull)
Returns:
The local date. (NullAllowed: when the argument is null)
Throws:
DfTypeUtil.ParseDateException When it failed to parse the string to date.
DfTypeUtil.ParseDateNumberFormatException When it failed to format the elements as number.
 
     public static LocalDate toLocalDate(Object objString pattern) {
         assertPatternNotNull("toLocalDate()"pattern);
         return doConvertToLocalDate(objpattern, (TimeZonenull);
     }

    
Convert the object to the instance that is date for the specified time-zone.
This method uses default date pattern based on 'yyyy-MM-dd HH:mm:ss.SSS' with flexible-parsing if the object is string type.

If string expression is specified, The year, month, ... parts are parsed from the string. Then the time-zone is not used in conversion. It uses LocalDate.of(). and millisecond handling is following:

Parameters:
obj The object to be converted. (NullAllowed: if null, returns null)
timeZone The time-zone for the local date. (NotNull: no used when string is specified)
Returns:
The local date. (NullAllowed: when the argument is null)
Throws:
DfTypeUtil.ParseDateException When it failed to parse the string to date.
DfTypeUtil.ParseDateNumberFormatException When it failed to format the elements as number.
    public static LocalDate toLocalDate(Object objTimeZone timeZone) {
        assertTimeZoneNotNull("toLocalDate()"timeZone);
        return doConvertToLocalDate(obj, (StringnulltimeZone);
    }

    
Convert the object to the instance that is date for the specified time-zone.
This method uses the specified date pattern if the object is string type.

If string expression is specified, The year, month, ... parts are parsed from the string. Then the time-zone is not used in conversion. It uses LocalDate.parse().

Parameters:
obj The object to be converted. (NullAllowed: if null, returns null)
pattern The pattern format to parse when the object is string. (NotNull)
timeZone The time-zone for the local date. (NotNull: no used when string is specified)
Returns:
The local date. (NullAllowed: when the argument is null)
Throws:
DfTypeUtil.ParseDateException When it failed to parse the string to date.
DfTypeUtil.ParseDateNumberFormatException When it failed to format the elements as number.
    public static LocalDate toLocalDate(Object objString patternTimeZone timeZone) {
        assertPatternNotNull("toLocalDate()"pattern);
        assertTimeZoneNotNull("toLocalDate()"timeZone);
        return doConvertToLocalDate(objpatterntimeZone);
    }
    protected static LocalDate doConvertToLocalDate(Object objString patternTimeZone timeZone) {
        if (obj instanceof String) {
            return doParseStringAsLocalDate((Stringobjpattern); // no need time-zone
        } else if (obj instanceof LocalDate) {
            return (LocalDateobj;
        } else if (obj instanceof LocalDateTime) {
            return ((LocalDateTimeobj).toLocalDate();
        }
        final TimeZone realZone = chooseRealZone(timeZone);
        final Date zonedResourceDate = toZonedResourceDate(objrealZone);
        return zonedResourceDate != null ? toZonedDateTime(zonedResourceDaterealZone).toLocalDate() : null;
    }
    protected static LocalDate doParseStringAsLocalDate(String strString pattern) {
        if (str == null || str.trim().length() == 0) {
            return null;
        }
        final boolean includeTime = false;
        final boolean includeMillis = false;
        final boolean keepMillisMore = false;
        if (pattern != null) {
            try {
                return LocalDate.parse(str, DateTimeFormatter.ofPattern(pattern));
            } catch (DateTimeParseException e) {
                throw new ParseDateException("Failed to parse the expression: " + str + ", pattern=" + patterne);
            }
        } else {
            String filtered = filterDateStringValueFlexibly(strincludeTimeincludeMilliskeepMillisMore);
            if (filtered.startsWith("-0000")) { // e.g. BC0001 converted to -0000
                filtered = Srl.ltrim(filtered"-"); // local date cannot parse -0000
            }
            try {
                return LocalDate.parse(filtered);
            } catch (DateTimeParseException e) {
                throw new ParseDateException("Failed to parse the expression: " + filtered + ", before-filter=" + stre);
            }
            // *cannot determine out-of-calendar by the exception from local date
        }
    }
    // -----------------------------------------------------
    //                                         LocalDateTime
    //                                         -------------
    
Convert the object to the instance that is date-time for the default time-zone.
This method uses default date pattern based on 'yyyy-MM-dd HH:mm:ss.SSS' with flexible-parsing if the object is string type.

If string expression is specified, The year, month, ... parts are parsed from the string. Then the time-zone is not used in conversion. It uses LocalDateTime.of(). and millisecond handling is following:

 e.g. millisecond and nanosecond handling
  "2014/10/28 12:34:56.789" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 789000000)
  "2014/10/28 12:34:56.7" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 007000000)
  "2014/10/28 12:34:56.78" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 078000000)
  "2014/10/28 12:34:56.7891" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 789100000)
  "2014/10/28 12:34:56.789123" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 789123000)
  "2014/10/28 12:34:56.789123456" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 789123456)
 

Parameters:
obj The object to be converted. (NullAllowed: if null, returns null)
Returns:
The local date-time. (NullAllowed: when the argument is null)
Throws:
DfTypeUtil.ParseDateException When it failed to parse the string to date.
DfTypeUtil.ParseDateNumberFormatException When it failed to format the elements as number.
    public static LocalDateTime toLocalDateTime(Object obj) {
        return doConvertToLocalDateTime(obj, (Stringnull, (TimeZonenull);
    }

    
Convert the object to the instance that is date-time for the default time-zone.
This method uses the specified date pattern if the object is string type.

If string expression is specified, The year, month, ... parts are parsed from the string. Then the time-zone is not used in conversion. It uses LocalDateTime.parse().

Parameters:
obj The object to be converted. (NullAllowed: if null, returns null)
pattern The pattern format to parse when the object is string. (NotNull)
Returns:
The local date-time. (NullAllowed: when the argument is null)
Throws:
DfTypeUtil.ParseDateException When it failed to parse the string to date.
DfTypeUtil.ParseDateNumberFormatException When it failed to format the elements as number.
    public static LocalDateTime toLocalDateTime(Object objString pattern) {
        assertPatternNotNull("toLocalDateTime()"pattern);
        return doConvertToLocalDateTime(objpattern, (TimeZonenull);
    }

    
Convert the object to the instance that is date-time for the specified time-zone.
This method uses default date pattern based on 'yyyy-MM-dd HH:mm:ss.SSS' with flexible-parsing if the object is string type.

If string expression is specified, The year, month, ... parts are parsed from the string. Then the time-zone is not used in conversion. It uses LocalDateTime.of(). and millisecond handling is following:

 e.g. millisecond and nanosecond handling
  "2014/10/28 12:34:56.789" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 789000000)
  "2014/10/28 12:34:56.7" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 007000000)
  "2014/10/28 12:34:56.78" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 078000000)
  "2014/10/28 12:34:56.7891" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 789100000)
  "2014/10/28 12:34:56.789123" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 789123000)
  "2014/10/28 12:34:56.789123456" :: same as LocalDateTime.of(2014, 10, 28, 12, 34, 56, 789123456)
 

Parameters:
obj The object to be converted. (NullAllowed: if null, returns null)
timeZone The time-zone for the local date-time. (NotNull)
Returns:
The local date-time. (NullAllowed: when the argument is null)
Throws:
DfTypeUtil.ParseDateException When it failed to parse the string to date.
DfTypeUtil.ParseDateNumberFormatException When it failed to format the elements as number.
    public static LocalDateTime toLocalDateTime(Object objTimeZone timeZone) {
        assertTimeZoneNotNull("toLocalDateTime()"timeZone);
        return doConvertToLocalDateTime(obj, (StringnulltimeZone);
    }

    
Convert the object to the instance that is date-time for the specified time-zone.
This method uses the specified date pattern if the object is string type.

If string expression is specified, The year, month, ... parts are parsed from the string. Then the time-zone is not used in conversion. It uses LocalDate.parse().

Parameters:
obj The object to be converted. (NullAllowed: if null, returns null)
pattern The pattern format to parse when the object is string. (NotNull)
timeZone The time-zone for the local date-time. (NotNull)
Returns:
The local date-time. (NullAllowed: when the argument is null)
Throws:
DfTypeUtil.ParseDateException When it failed to parse the string to date.
DfTypeUtil.ParseDateNumberFormatException When it failed to format the elements as number.
    public static LocalDateTime toLocalDateTime(Object objString patternTimeZone timeZone) {
        assertTimeZoneNotNull("toLocalDateTime()"timeZone);
        return doConvertToLocalDateTime(obj, (StringnulltimeZone);
    }
    protected static LocalDateTime doConvertToLocalDateTime(Object objString patternTimeZone timeZone) {
        if (obj instanceof String) {
            return doParseStringAsLocalDateTime((Stringobjpattern); // no need time-zone
        } else if (obj instanceof LocalDate) {