public class Utils extends Object
| 构造器和说明 |
|---|
Utils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static List<String> |
chunks(CharSequence s) |
static Exception |
close(Closeable closeable)
Close the closeable and catch any exception thrown.
|
static Exception |
close(Connection connection)
Close the connection and catch any exception thrown.
|
static Exception |
close(Context context)
Close the context and catch any exception thrown.
|
static Exception |
close(ResultSet rs)
Close the result set and catch any exception thrown.
|
static Exception |
close(Socket socket)
<<<<<<< HEAD
Close the socket and catch any exception thrown.
|
static Exception |
close(Statement statement)
Close the statement and catch any exception thrown.
|
static void |
copy(InputStream in,
OutputStream out) |
static boolean |
equals(Object o1,
Object o2) |
static String |
findLongestCommonPrefix(CharSequence... seqs) |
static String |
findLongestCommonPrefix(Iterable<? extends CharSequence> seqs)
Find the longest possible common prefix of the provided char sequence.
|
static <E> E |
first(Iterable<E> elements) |
static Exception |
flush(Flushable flushable)
Flush the flushable and catch any exception thrown.
|
static File |
getCurrentDirectory() |
static String |
globexToRegex(String globex)
Create a pattern that transforms a glob expression into a regular expression, the following task are supported
* : Match any number of unknown characters
?
|
static int |
indexOf(CharSequence s,
int off,
char c) |
static boolean |
instanceOf(Class c,
List<String> types) |
static boolean |
instanceOf(Class c,
String type) |
static String |
interpolate(String interpolated,
Map<?,?> context)
Interpolate a string and replace the occurence from a context map, the syntax for a variable
is
${} and it can accept a default value used when the variable cannot be resolved
with the :- separator:
{} + "foo" => "foo"
{} + "${foo}" => ""
{} + "\\${foo}" => "${foo}"
{foo:bar} + "${foo}" => "bar"
{} + "${foo:-bar}" => "bar"
|
static <E> Iterator<E> |
iterator() |
static <E> Iterator<E> |
iterator(E element) |
static String |
join(Iterable<String> strings,
String separator) |
static <E> List<E> |
list(E... elements) |
static <E> List<E> |
list(Iterable<E> iterable) |
static <E> List<E> |
list(Iterator<E> iterator) |
static <K,V> HashMap<K,V> |
map(K key,
V value) |
static <K,V,M extends Map<K,V>> |
map(M map,
K key,
V value) |
static boolean |
notBlank(String s) |
static boolean |
notEquals(Object o1,
Object o2) |
static int |
notNegative(int value)
Return the value when it is positive otherwise return 0.
|
static <E> E |
notNull(E e1,
E e2) |
static byte[] |
readAsBytes(InputStream in) |
static String |
readAsUTF8(InputStream in) |
static Type |
resolve(Type implementation,
Class<?> type,
int parameterIndex)
A simplistic implementation, it may not handle all cases but it should handle enough.
|
static Class |
resolveToClass(Type type) |
static Class<?> |
resolveToClass(Type implementation,
Class<?> type,
int parameterIndex) |
static <T extends Throwable> |
rethrow(Class<T> throwableClass,
Throwable cause) |
static <E> HashSet<E> |
set(E... elements) |
static String[] |
split(CharSequence s,
char separator) |
static String[] |
split(CharSequence s,
char separator,
int rightPadding) |
static File |
toFile(URL url) |
static String |
trimLeft(String s) |
public static final Charset UTF_8
public static <E> Iterator<E> iterator()
public static <E> Iterator<E> iterator(E element)
public static <E> E first(Iterable<E> elements)
public static <K,V,M extends Map<K,V>> M map(M map, K key, V value)
public static <K,V> HashMap<K,V> map(K key, V value)
public static <E> HashSet<E> set(E... elements)
public static <E> List<E> list(E... elements)
public static int indexOf(CharSequence s, int off, char c)
public static boolean notBlank(String s)
public static <E> E notNull(E e1,
E e2)
public static int notNegative(int value)
value - the valuepublic static String globexToRegex(String globex) throws NullPointerException
globex - the glob expressionNullPointerException - when the globex argument is nullpublic static Exception close(Socket socket)
socket - the socket to closeclose operationpublic static Exception close(Closeable closeable)
closeable - the closeable to closeclose operationpublic static Exception close(Connection connection)
connection - the socket to closeclose operationpublic static Exception close(Statement statement)
statement - the statement to closeclose operationpublic static Exception close(ResultSet rs)
rs - the result set to closeclose operationpublic static Exception close(Context context)
context - the context to closeclose operationpublic static <T extends Throwable> void rethrow(Class<T> throwableClass, Throwable cause) throws T extends Throwable
T extends Throwablepublic static Exception flush(Flushable flushable)
flushable - the flushable to flushflush operationpublic static List<String> chunks(CharSequence s)
public static String[] split(CharSequence s, char separator)
public static String[] split(CharSequence s, char separator, int rightPadding)
public static String findLongestCommonPrefix(CharSequence... seqs)
public static String findLongestCommonPrefix(Iterable<? extends CharSequence> seqs)
seqs - the sequencespublic static byte[] readAsBytes(InputStream in) throws IOException
IOExceptionpublic static String readAsUTF8(InputStream in)
public static void copy(InputStream in, OutputStream out) throws IOException
IOExceptionpublic static File toFile(URL url) throws IllegalArgumentException, NullPointerException
public static Class<?> resolveToClass(Type implementation, Class<?> type, int parameterIndex)
public static Type resolve(Type implementation, Class<?> type, int parameterIndex)
implementation - the type for which the parameter requires a resolutiontype - the type that owns the parameterparameterIndex - the parameter indexpublic static String interpolate(String interpolated, Map<?,?> context) throws NullPointerException
${} and it can accept a default value used when the variable cannot be resolved
with the :- separator:
{} + "foo" => "foo"{} + "${foo}" => ""{} + "\\${foo}" => "${foo}"{foo:bar} + "${foo}" => "bar"{} + "${foo:-bar}" => "bar"interpolated - the value to interpolatecontext - the contextNullPointerException - if the interpolated argument is nullpublic static File getCurrentDirectory()
Copyright © 2018. All rights reserved.