程序包 org.coodex.util

类 Common

java.lang.Object
org.coodex.util.Common

public class Common extends Object
作者:
davidoff
  • 字段详细资料

    • PATH_SEPARATOR

      public static final String PATH_SEPARATOR
    • FILE_SEPARATOR

      public static final String FILE_SEPARATOR
      另请参阅:
    • USER_DIR

      public static final String USER_DIR
    • DEFAULT_DATE_FORMAT

      public static final String DEFAULT_DATE_FORMAT
      另请参阅:
    • DEFAULT_TIME_FORMAT

      public static final String DEFAULT_TIME_FORMAT
      另请参阅:
    • DEFAULT_DATETIME_FORMAT

      public static final String DEFAULT_DATETIME_FORMAT
      另请参阅:
    • SYSTEM_START_TIME

      public static final Long SYSTEM_START_TIME
    • PROCESSOR_COUNT

      public static final int PROCESSOR_COUNT
    • RANDOM

      public static final Random RANDOM
  • 方法详细资料

    • isWindows

      public static boolean isWindows()
    • toAbsolutePath

      public static String toAbsolutePath(String path)
    • isDebug

      public static boolean isDebug()
    • toBytes

      public static byte[] toBytes(long l, int wide, Endianness endianness)
    • arrayToSet

      public static <T> Set<T> arrayToSet(T[] array)
    • getUUIDStr

      @Deprecated public static String getUUIDStr()
      已过时。
      作为id时,使用IDGenerator.newId()替代

      获取uuid时,使用UUIDHelper.getUUIDString()

      返回:
      uuid
    • sha1

      public static String sha1(String content)
    • sha1

      public static String sha1(String content, Charset charset)
    • inArray

      public static <T> boolean inArray(T el, T[] array)
    • findInArray

      @Deprecated public static <T> int findInArray(T el, T[] array)
    • nullToStr

      public static String nullToStr(String str)
    • serialize

      public static byte[] serialize(Object object) throws IOException
      抛出:
      IOException
    • deserialize

      public static Object deserialize(byte[] buf) throws IOException, ClassNotFoundException
      抛出:
      IOException
      ClassNotFoundException
    • deepCopy

      public static <T extends Serializable> T deepCopy(T object) throws IOException, ClassNotFoundException
      抛出:
      IOException
      ClassNotFoundException
    • random

      public static int random(int max)
      参数:
      max - 正整数
      返回:
      [0, max)的随机数
    • randomC

      public static int randomC(int max)
      参数:
      max - 非负正数
      返回:
      [0, max]的随机数
    • random

      public static int random(int min, int max)
    • randomC

      public static int randomC(int min, int max)
    • random

      public static long random(long min, long max)
    • random

      public static long random(long max)
    • randomC

      public static long randomC(long max)
    • randomC

      public static long randomC(long min, long max)
    • random

      public static double random(double min, double max)
    • copyMap

      public static <K extends Serializable, V extends Serializable> void copyMap(Map<K,V> org, Map<K,V> target)
    • isBlank

      public static boolean isBlank(String s)
    • firstValuable

      @SafeVarargs public static <T> T firstValuable(T... s)
    • isEmpty

      public static boolean isEmpty(Collection<?> collection)
    • notEmpty

      public static boolean notEmpty(Collection<?> collection)
    • copyStream

      public static void copyStream(InputStream is, OutputStream os) throws IOException
      抛出:
      IOException
    • copyStream

      public static void copyStream(InputStream is, OutputStream os, int blockSize, boolean flushPerBlock, int bps) throws IOException
      抛出:
      IOException
    • checkNull

      @Deprecated public static void checkNull(Object o, String msg)
      已过时。
    • between

      @Deprecated public static <T extends Comparable<T>> boolean between(T t, T bound1, T bound2)
    • max

      @SafeVarargs public static <T extends Comparable<T>> T max(T c1, T c2, T... others)
    • byte2hex

      @Deprecated public static String byte2hex(byte[] b)
      已过时。
    • byte2hex

      @Deprecated public static String byte2hex(byte[] b, int offset, int length)
      已过时。
    • byte2hex

      @Deprecated public static String byte2hex(byte[] b, int col, String split)
      已过时。
    • byte2hex

      @Deprecated public static String byte2hex(byte[] b, int offset, int length, int col, String split)
      已过时。
    • base16Encode

      public static String base16Encode(byte[] b)
      参数:
      b - 需要编码的字节数组
      返回:
      编码后的字符串
    • base16Encode

      public static String base16Encode(byte[] b, int offset, int length)
      参数:
      b - 需要编码的字节数组
      offset - 编码字节数组偏移
      length - 编码字节数组长度
      返回:
      编码后的字符串
    • base16Encode

      public static String base16Encode(byte[] b, int col, String split)
      参数:
      b - 需要编码的字节数组
      col - 每个字节编码后算一列,此参数用来指定编码后每行多少列,行与行之间使用系统变量line.separator来分隔
      split - 列于列之间的分隔字符传串,行首行尾不加
      返回:
      编码后的字符串
    • base16Encode

      public static String base16Encode(byte[] b, Function<Integer,Integer> colFunction, String split)
      参数:
      b - 需要编码的字节数组
      colFunction - 每个字节编码后算一列,此参数用来指定编码后各行多少列,行与行之间使用系统变量line.separator来分隔
      split - 列于列之间的分隔字符传串,行首行尾不加
      返回:
      编码后的字符串
    • base16Encode

      public static String base16Encode(byte[] b, int offset, int length, int col, String split)
      参数:
      b - 需要编码的字节数组
      offset - 编码字节数组偏移
      length - 编码字节数组长度
      col - 每个字节编码后算一列,此参数用来指定编码后每行多少列,行与行之间使用系统变量line.separator来分隔
      split - 列于列之间的分隔字符传串,行首行尾不加
      返回:
      编码后的字符串
    • base16Encode

      public static String base16Encode(byte[] b, int offset, int length, Function<Integer,Integer> colFunction, String split)
      参数:
      b - 需要编码的字节数组
      offset - 编码字节数组偏移
      length - 编码字节数组长度
      colFunction - 每个字节编码后算一列,此参数用来指定编码后各行多少列,行与行之间使用系统变量line.separator来分隔
      split - 列于列之间的分隔字符传串,行首行尾不加
      返回:
      编码后的字符串
    • formatArray

      public static <T> String formatArray(T[] array, int offset, int length, Function<Integer,Integer> colFunction, String split, Function<T,String> encoder)
    • hex2byte

      @Deprecated public static byte[] hex2byte(String hexString)
      已过时。
    • hex2byte

      @Deprecated public static byte[] hex2byte(String hexString, String ignoreChars)
      已过时。
    • base16Decode

      public static byte[] base16Decode(String hexString)
    • base16Decode

      public static byte[] base16Decode(String hexString, String ignoreChars)
    • intersection

      public static <T> Set<T> intersection(Set<T> set1, Set<T> set2)
      交集
      参数:
      set1 - set1
      set2 - set2
      返回:
      交集
    • difference

      public static <T> Set<T> difference(Set<T> org, Set<T> todiv)
      差集 org - todiv
      参数:
      org - org
      todiv - todiv
      返回:
      差集 org - todiv
    • join

      @SafeVarargs public static <T, C extends Collection<T>> C join(C instance, Collection<? extends T>... collections)
    • native2AscII

      public static String native2AscII(String str)
    • getNewFile

      @Deprecated public static File getNewFile(String fileName) throws IOException
      已过时。
      抛出:
      IOException
    • newFile

      public static File newFile(String fileName) throws IOException
      抛出:
      IOException
    • getResource

      public static URL getResource(String resource, ClassLoader... classLoaders)
    • indexOf

      public static <T> int indexOf(T[] array, T t)
    • concat

      public static String concat(Collection<String> list, String split)
    • to

      public static <T> T to(String str, T value)
    • toInt

      public static int toInt(String str, Supplier<Integer> valueSupplier)
    • toInt

      public static int toInt(String str, int value)
    • toLong

      public static long toLong(String str, Supplier<Long> value)
    • toLong

      public static long toLong(String str, long value)
    • toBool

      public static boolean toBool(String str, Supplier<Boolean> v)
    • toBool

      public static boolean toBool(String str, boolean v)
    • toArray

      public static List<String> toArray(String str, String delim, List<String> v)
    • toArray

      public static String[] toArray(String str, String delim, Supplier<String[]> v)
    • toArray

      public static String[] toArray(String str, String delim, String[] v)
    • trim

      public static String trim(String str, char... trimChars)
    • trim

      public static String trim(String str, String toTrim)
    • sameString

      @Deprecated public static boolean sameString(String str1, String str2)
      已过时。
    • randomGB2312Char

      public static char randomGB2312Char()
      返回:
      一个随机的中文字符(GB2312的一级文字)
    • randomChar

      public static char randomChar(String s)
    • random

      public static <T> T random(T[] range)
    • random

      public static byte random(byte[] range)
    • random

      public static short random(short[] range)
    • random

      public static int random(int[] range)
    • random

      public static long random(long[] range)
    • random

      public static float random(float[] range)
    • random

      public static double random(double[] range)
    • randomStr

      public static String randomStr(int min, int max, String range)
    • copy

      public static Calendar copy(Calendar calendar)
    • lowerFirstChar

      public static String lowerFirstChar(String string)
    • upperFirstChar

      public static String upperFirstChar(String string)
    • camelCase

      public static String camelCase(String s)
    • camelCase

      public static String camelCase(String s, String delimiters)
    • camelCase

      public static String camelCase(String s, boolean firstCharUpperCase)
    • camelCase

      public static String camelCase(String s, boolean firstCharUpperCase, String delimiters)
    • similarity

      public static double similarity(String s1, String s2)
      参数:
      s1 - s1
      s2 - s2
      返回:
      两个字符串的相似度
    • subMap

      public static <T> Map<String,T> subMap(String prefix, Map<String,T> map)
    • calendarToStr

      public static String calendarToStr(Calendar calendar, String format)
    • calendarToStr

      public static String calendarToStr(Calendar calendar)
    • dateToStr

      public static String dateToStr(Date date, String format)
    • dateToStr

      public static String dateToStr(Date date)
    • getSafetyDateFormat

      public static DateFormat getSafetyDateFormat(String format)
    • strToDate

      public static Date strToDate(String str, String format) throws ParseException
      抛出:
      ParseException
    • strToDate

      public static Date strToDate(String str) throws ParseException
      抛出:
      ParseException
    • strToCalendar

      public static Calendar strToCalendar(String str, String format) throws ParseException
      抛出:
      ParseException
    • long2Bytes

      public static byte[] long2Bytes(long data)
    • longToDateStr

      public static String longToDateStr(long l)
    • longToDateStr

      public static String longToDateStr(long l, String format)
    • longToCalendar

      public static Calendar longToCalendar(long l)
    • dateToCalendar

      public static Calendar dateToCalendar(Date date)
    • min

      @SafeVarargs public static <T extends Comparable<T>> T min(T c1, T c2, T... others)
    • calendar

      public static Calendar calendar(int year)
    • calendar

      public static Calendar calendar(int year, int month)
    • calendar

      public static Calendar calendar(int year, int month, int date)
    • calendar

      public static Calendar calendar(int year, int month, int date, int hour)
    • calendar

      public static Calendar calendar(int year, int month, int date, int hour, int minute)
    • calendar

      public static Calendar calendar(int year, int month, int date, int hour, int minute, int second)
    • calendar

      public static Calendar calendar(int year, int month, int date, int hour, int minute, int second, int millisecond)
    • truncate

      public static Calendar truncate(Calendar calendar, int fromField)
    • now

      public static String now()
    • now

      public static String now(String format)
    • rte

      public static RuntimeException rte(Throwable th)
    • getSystemStart

      public static Long getSystemStart()
    • cast

      public static <T> T cast(Object obj)
    • sleep

      public static void sleep(long ms)
    • forEachBlock

      public static <T> void forEachBlock(T[] all, int blockSize, boolean continuous, float redundancy, BiConsumer<Integer,Integer> consumer)
      对一个大数组进行分块操作
      类型参数:
      T - 元素类型
      参数:
      all - 所有的数据
      blockSize - 块大小
      continuous - 是否连续,[0,100),[100, last]为不连续,[0,100][100, last]为连续
      redundancy - 最后一块的冗余比例
      consumer - 每块数据如何处理
    • forEachBlock

      public static <T> void forEachBlock(T[] all, int blockSize, boolean continuous, float redundancy, IntFunction<T[]> arrayProvider, Consumer<T[]> consumer)
      对一个大数组进行分块操作
      类型参数:
      T - T
      参数:
      all - 所有元素
      blockSize - 块大小
      continuous - 是否连续,[0,100),[100, last]为不连续,[0,100][100, last]为连续
      redundancy - 最后一块的冗余比例
      arrayProvider - 新数组如何创建
      consumer - 数组处理逻辑
    • slice

      public static <T> Collection<Common.ArrayBlockRef> slice(T[] all, int blockSize, boolean continuous, float redundancy)
      将一个大数组分块
      类型参数:
      T - T
      参数:
      all - 大数组
      blockSize - 块大小
      continuous - 是否连续,[0,100),[100, last]为不连续,[0,100][100, last]为连续
      redundancy - 最后一块的冗余比例
      返回:
      拆分后的数组描述(从哪个下标开始 , 长度)
    • isJava9AndLast

      public static boolean isJava9AndLast()
    • scale

      public static long scale(double d)
    • scale

      public static long scale(double d, RoundingMode roundingMode)
    • scale2I

      public static int scale2I(double d)
    • scale2I

      public static int scale2I(double d, RoundingMode roundingMode)
    • scale2F

      public static float scale2F(double d, int scale)
    • scale2F

      public static float scale2F(double d, int scale, RoundingMode roundingMode)
    • scale

      public static double scale(double d, int scale)
    • scale

      public static double scale(double d, int scale, RoundingMode roundingMode)
    • sort

      public static <T> List<T> sort(List<T> list, Comparator<T> comparator)