|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crsh.util.Utils
public class Utils
Field Summary | |
---|---|
private static Pattern |
blankPattern
|
private static int |
DOLLAR
. |
private static Iterator |
EMPTY_ITERATOR
. |
private static int |
ESCAPE
. |
private static int |
EVALUATING
. |
private static Pattern |
FOO
|
private static Pattern |
p
. |
private static int |
SCANNING
. |
static Charset |
UTF_8
. |
Constructor Summary | |
---|---|
Utils()
|
Method Summary | ||
---|---|---|
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
|
first(Iterable<E> elements)
|
|
static Exception |
flush(Flushable flushable)
Flush the flushable and catch any exception thrown. |
|
private static String[] |
foo(CharSequence s,
char separator,
int count,
int from,
int rightPadding)
|
|
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 ? : Match one unknown character [characters] : Match a character as part of a group of characters \ : Escape character |
|
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
|
iterator()
|
|
static
|
iterator(E element)
|
|
static String |
join(Iterable<String> strings,
String separator)
|
|
static
|
list(E... elements)
|
|
static
|
list(Iterable<E> iterable)
|
|
static
|
list(Iterator<E> iterator)
|
|
static
|
map(K key,
V value)
|
|
static
|
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
|
notNull(E e1,
E e2)
|
|
private static ByteArrayOutputStream |
read(InputStream in)
|
|
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
|
rethrow(Class<T> throwableClass,
Throwable cause)
|
|
static
|
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)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Iterator EMPTY_ITERATOR
private static final Pattern p
private static final Pattern blankPattern
private static final Pattern FOO
private static final int ESCAPE
private static final int SCANNING
private static final int DOLLAR
private static final int EVALUATING
public static final Charset UTF_8
Constructor Detail |
---|
public Utils()
Method Detail |
---|
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 <E> List<E> list(Iterable<E> iterable)
public static <E> List<E> list(Iterator<E> iterator)
public static int indexOf(CharSequence s, int off, char c)
public static String trimLeft(String s)
public static boolean notBlank(String s)
public static <E> E notNull(E e1, E e2)
public static int notNegative(int value)
value
- the value
public static String globexToRegex(String globex) throws NullPointerException
globex
- the glob expression
NullPointerException
- when the globex argument is nullpublic static Exception close(Socket socket)
socket
- the socket to close
close
operationpublic static Exception close(Closeable closeable)
closeable
- the closeable to close
close
operationpublic static Exception close(Connection connection)
connection
- the socket to close
close
operationpublic static Exception close(Statement statement)
statement
- the statement to close
close
operationpublic static Exception close(ResultSet rs)
rs
- the result set to close
close
operationpublic static Exception close(Context context)
context
- the context to close
close
operationpublic static <T extends Throwable> void rethrow(Class<T> throwableClass, Throwable cause) throws T extends Throwable
T extends Throwable
public static boolean equals(Object o1, Object o2)
public static boolean notEquals(Object o1, Object o2)
public static Exception flush(Flushable flushable)
flushable
- the flushable to flush
flush
operationpublic static List<String> chunks(CharSequence s)
public static String join(Iterable<String> strings, String separator)
public static String[] split(CharSequence s, char separator)
public static String[] split(CharSequence s, char separator, int rightPadding)
private static String[] foo(CharSequence s, char separator, int count, int from, int rightPadding)
public static String findLongestCommonPrefix(CharSequence... seqs)
findLongestCommonPrefix(Iterable)
public static String findLongestCommonPrefix(Iterable<? extends CharSequence> seqs)
seqs
- the sequences
public static byte[] readAsBytes(InputStream in) throws IOException
IOException
public static String readAsUTF8(InputStream in)
public static void copy(InputStream in, OutputStream out) throws IOException
IOException
private static ByteArrayOutputStream read(InputStream in) throws IOException
IOException
public static File toFile(URL url) throws IllegalArgumentException, NullPointerException
IllegalArgumentException
NullPointerException
public static Class<?> resolveToClass(Type implementation, Class<?> type, int parameterIndex)
public static Class resolveToClass(Type type)
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 index
public static boolean instanceOf(Class c, List<String> types)
public static boolean instanceOf(Class c, String type)
public 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 context
NullPointerException
- if the interpolated argument is nullpublic static File getCurrentDirectory()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |