public static <E> void batchExecute(int totalSize, int batchSize, Collection<E> collection, Executor<E> executor) { for (int i = 0; i <= totalSize / batchSize; i++) { List<E> list = BatchUtils.getBatchList(i, batchSize, collection); if (CollectionUtils.isNotEmpty(list)) { if (!executor.execute(list)) { break; } } } }
private Authenticator getAuthenticator() { if (!StringUtils.isEmpty(userName)) { return new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }; } else { return null; } }
/** * 执行HTTP GET请求。 * * @param url 请求地址 * @param params 请求参数 * @return 响应字符串 */ public static String doGet(String url, Map<String, String> params) throws IOException { return doGet(url, params, DEFAULT_CHARSET); }
/** * 使用默认的UTF-8字符集反编码请求参数值。 * * @param value 参数值 * @return 反编码后的参数值 */ public static String decode(String value) { return decode(value, DEFAULT_CHARSET); }
/** * Capitalize a {@code String}, changing the first letter to * upper case as per {@link Character#toUpperCase(char)}. * No other letters are changed. * @param str the {@code String} to capitalize, may be {@code null} * @return the capitalized {@code String}, or {@code null} if the supplied * string is {@code null} */ public static String capitalize(String str) { return changeFirstCharacterCase(str, true); }
/** * 执行HTTP POST请求。 * * @param url 请求地址 * @param params 请求参数 * @param charset 字符集,如UTF-8, GBK, GB2312 * @return 响应字符串 */ public static String doPost(String url, Map<String, String> params, String charset, int connectTimeout, int readTimeout) throws IOException { return doPost(url, params, charset, connectTimeout, readTimeout, null); }
public static void doQuietly(Callable callable) { try { callable.call(); } catch (Exception ignored) { } }
/** * 通过反射,获得Field泛型参数的实际类型. 如: public Map<String, Buyer> names; * * @param field 字段 * @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回<code>Object.class</code> */ public static Class getFieldGenericType(Field field) { return getFieldGenericType(field, 0); } }
/** * 使用默认的UTF-8字符集编码请求参数值。 * * @param value 参数值 * @return 编码后的参数值 */ public static String encode(String value) { return encode(value, DEFAULT_CHARSET); }
/** * 通过反射,获得方法输入参数第一个输入参数的所有泛型参数的实际类型. 如: public void add(Map<String, Buyer> maps, List<String> names){} * * @param method 方法 * @return 输入参数的泛型参数的实际类型集合, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回空集合 */ public static List<Class> getMethodGenericParameterTypes(Method method) { return getMethodGenericParameterTypes(method, 0); } /**
/** * 通过反射,获得方法返回值第一个泛型参数的实际类型. 如: public Map<String, Buyer> getNames(){} * * @param method 方法 * @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回<code>Object.class</code> */ public static Class getMethodGenericReturnType(Method method) { return getMethodGenericReturnType(method, 0); }
@SuppressWarnings("unchecked") public <T> T deserialize(Object object, Type type) { return PrimitiveTypeUtils.convert(object, type); } }
public static <E> void batchExecute(int totalSize, int batchSize, Collection<E> collection, Executor<E> executor) { for (int i = 0; i <= totalSize / batchSize; i++) { List<E> list = BatchUtils.getBatchList(i, batchSize, collection); if (CollectionUtils.isNotEmpty(list)) { if (!executor.execute(list)) { break; } } } }
private Authenticator getAuthenticator() { if (!StringUtils.isEmpty(userName)) { return new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }; } else { return null; } }
/** * 执行HTTP GET请求。 * * @param url 请求地址 * @param params 请求参数 * @return 响应字符串 */ public static String doGet(String url, Map<String, String> params) throws IOException { return doGet(url, params, DEFAULT_CHARSET); }
/** * 使用默认的UTF-8字符集反编码请求参数值。 * * @param value 参数值 * @return 反编码后的参数值 */ public static String decode(String value) { return decode(value, DEFAULT_CHARSET); }
/** * Uncapitalize a {@code String}, changing the first letter to * lower case as per {@link Character#toLowerCase(char)}. * No other letters are changed. * @param str the {@code String} to uncapitalize, may be {@code null} * @return the uncapitalized {@code String}, or {@code null} if the supplied * string is {@code null} */ public static String uncapitalize(String str) { return changeFirstCharacterCase(str, false); }
public static boolean isNotEmpty(String... strs) { if (strs != null) { for (String s : strs) { if (isEmpty(s)) { return false; } } return true; } return false; }