public static long parseLong(String value, long defaultValue, String paramName) { if (value == null || "".equals(value.trim())) return defaultValue; try { return Long.parseLong(value); } catch (Exception e) { ApiLogger.error("parseLong error name=" + paramName + ",value=" + value, e); } return defaultValue; }
public static boolean parseBoolean(String value, boolean defaultValue) { if (value == null || "".equals(value)) return defaultValue; try { return Boolean.valueOf(value); } catch (Exception e) { ApiLogger.error(e); } return defaultValue; }
public static int parseInteger(String value, int defaultValue) { if (value == null || "".equals(value.trim())) return defaultValue; try { return Integer.parseInt(value); } catch (Exception e) { ApiLogger.error(e); } return defaultValue; }
public static int getHash4split(String id, int splitCount) { try { CRC32 crc = crc32Provider.get(); crc.reset(); crc.update(String.valueOf(id).getBytes("utf-8")); long h = crc.getValue(); if (h < 0) { h = -1 * h; } int hash = (int) (h / splitCount % splitCount); return hash; } catch (UnsupportedEncodingException e) { ApiLogger.warn( new StringBuilder(64) .append("Error: when hash4split, id=") .append(id) .append(", splitCount=") .append(splitCount), e); return -1; } }