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

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

The newest version!
package com.github.andyshao.convert;

import java.util.Objects;
import java.util.function.Function;

/**
 * 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 extends Function{ public static final Convert BYTES_2_HEX = (Byte[] in) -> { StringBuilder builder = new StringBuilder(); for (Byte b : in) { builder.append(ConvertByte2Str.byte2Char(ConvertByte2Str.BYTE_HEX).apply(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.apply(in); return str == null ? null : Boolean.valueOf(str); }; public static final Convert OB_2_CHAR = (Object in) -> { String str = Convert.OB_2_STR.apply(in); return str.charAt(0); }; public static final Convert OB_2_DOUBLE = (Object in) -> { String str = Convert.OB_2_STR.apply(in); return str == null ? null : Double.valueOf(str); }; public static final Convert OB_2_FLOAT = (Object in) -> { String str = Convert.OB_2_STR.apply(in); return str == null ? null : Float.valueOf(str); }; public static final Convert OB_2_INT = (Object in) -> { String str = Convert.OB_2_STR.apply(in); return str == null ? null : Integer.valueOf(str); }; public static final Convert OB_2_LONG = (Object in) -> { String str = Convert.OB_2_STR.apply(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.apply(in); return str == null ? null : Short.valueOf(str); }; public static final Convert OB_2_STR = (Object in) -> { return Objects.toString(in , null); }; @Override OUT apply(IN in); public static OUT converting(IN in, Convert convert){ return convert.apply(in); } }