All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.andyshao.convert.Convert Maven / Gradle / Ivy

package com.github.andyshao.convert;

import java.util.Objects;

/**
 * General convert interface.
 * Title:
* Descript:
* Copyright: Copryright(c) Jun 14, 2014
* Encoding:UNIX UTF-8 * * @author Andy.Shao * * @param the input * @param the output */ @FunctionalInterface public interface Convert { /** Will change it become private */ @Deprecated public static final Convert BYTE_2_HEX = ConvertByte2Str.byte2Char(ConvertByte2Str.BYTE_HEX); public static final Convert BYTES_2_HEX = (Byte[] in) -> { StringBuilder builder = new StringBuilder(); for (Byte b : in) { builder.append(Convert.BYTE_2_HEX.convert(b)); } return builder.toString(); }; public static final Convert HEX_2_BYTES = new ConvertStr2Byte(); public static final Convert OB_2_BOOLEAN = (Object in) -> { String str = Convert.OB_2_STR.convert(in); return str == null ? null : Boolean.valueOf(str); }; public static final Convert OB_2_CHAR = (Object in) -> { String str = Convert.OB_2_STR.convert(in); return str.charAt(0); }; public static final Convert OB_2_DOUBLE = (Object in) -> { String str = Convert.OB_2_STR.convert(in); return str == null ? null : Double.valueOf(str); }; public static final Convert OB_2_FLOAT = (Object in) -> { String str = Convert.OB_2_STR.convert(in); return str == null ? null : Float.valueOf(str); }; public static final Convert OB_2_INT = (Object in) -> { String str = Convert.OB_2_STR.convert(in); return str == null ? null : Integer.valueOf(str); }; public static final Convert OB_2_LONG = (Object in) -> { String str = Convert.OB_2_STR.convert(in); return str == null ? null : Long.valueOf(str); }; public static final Convert OB_2_OB = (Object in) -> { return in; }; public static final Convert OB_2_SHORT = (Object in) -> { String str = Convert.OB_2_STR.convert(in); return str == null ? null : Short.valueOf(str); }; public static final Convert OB_2_STR = (Object in) -> { return Objects.toString(in , null); }; OUT convert(IN in); }