org.crsh.util
Class Utils

java.lang.Object
  extended by org.crsh.util.Utils

public class Utils
extends Object


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
<E> E
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
<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>>
M
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)
           
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
<T extends Throwable>
void
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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ITERATOR

private static final Iterator EMPTY_ITERATOR
.


p

private static final Pattern p
.


blankPattern

private static final Pattern blankPattern

FOO

private static final Pattern FOO

ESCAPE

private static final int ESCAPE
.

See Also:
Constant Field Values

SCANNING

private static final int SCANNING
.

See Also:
Constant Field Values

DOLLAR

private static final int DOLLAR
.

See Also:
Constant Field Values

EVALUATING

private static final int EVALUATING
.

See Also:
Constant Field Values

UTF_8

public static final Charset UTF_8
.

Constructor Detail

Utils

public Utils()
Method Detail

iterator

public static <E> Iterator<E> iterator()

iterator

public static <E> Iterator<E> iterator(E element)

first

public static <E> E first(Iterable<E> elements)

map

public static <K,V,M extends Map<K,V>> M map(M map,
                                             K key,
                                             V value)

map

public static <K,V> HashMap<K,V> map(K key,
                                     V value)

set

public static <E> HashSet<E> set(E... elements)

list

public static <E> List<E> list(E... elements)

list

public static <E> List<E> list(Iterable<E> iterable)

list

public static <E> List<E> list(Iterator<E> iterator)

indexOf

public static int indexOf(CharSequence s,
                          int off,
                          char c)

trimLeft

public static String trimLeft(String s)

notBlank

public static boolean notBlank(String s)

notNull

public static <E> E notNull(E e1,
                            E e2)

notNegative

public static int notNegative(int value)
Return the value when it is positive otherwise return 0.

Parameters:
value - the value
Returns:
the non negative value

globexToRegex

public static String globexToRegex(String globex)
                            throws NullPointerException
Create a pattern that transforms a glob expression into a regular expression, the following task are supported

Parameters:
globex - the glob expression
Returns:
the regular expression
Throws:
NullPointerException - when the globex argument is null

close

public static Exception close(Socket socket)
<<<<<<< HEAD Close the socket and catch any exception thrown.

Parameters:
socket - the socket to close
Returns:
any Exception thrown during the close operation

close

public static Exception close(Closeable closeable)
Close the closeable and catch any exception thrown.

Parameters:
closeable - the closeable to close
Returns:
any Exception thrown during the close operation

close

public static Exception close(Connection connection)
Close the connection and catch any exception thrown.

Parameters:
connection - the socket to close
Returns:
any Exception thrown during the close operation

close

public static Exception close(Statement statement)
Close the statement and catch any exception thrown.

Parameters:
statement - the statement to close
Returns:
any Exception thrown during the close operation

close

public static Exception close(ResultSet rs)
Close the result set and catch any exception thrown.

Parameters:
rs - the result set to close
Returns:
any Exception thrown during the close operation

close

public static Exception close(Context context)
Close the context and catch any exception thrown.

Parameters:
context - the context to close
Returns:
any Exception thrown during the close operation

rethrow

public static <T extends Throwable> void rethrow(Class<T> throwableClass,
                                                 Throwable cause)
                    throws T extends Throwable
Throws:
T extends Throwable

equals

public static boolean equals(Object o1,
                             Object o2)

notEquals

public static boolean notEquals(Object o1,
                                Object o2)

flush

public static Exception flush(Flushable flushable)
Flush the flushable and catch any exception thrown.

Parameters:
flushable - the flushable to flush
Returns:
any Exception thrown during the flush operation

chunks

public static List<String> chunks(CharSequence s)

join

public static String join(Iterable<String> strings,
                          String separator)

split

public static String[] split(CharSequence s,
                             char separator)

split

public static String[] split(CharSequence s,
                             char separator,
                             int rightPadding)

foo

private static String[] foo(CharSequence s,
                            char separator,
                            int count,
                            int from,
                            int rightPadding)

findLongestCommonPrefix

public static String findLongestCommonPrefix(CharSequence... seqs)
See Also:
findLongestCommonPrefix(Iterable)

findLongestCommonPrefix

public static String findLongestCommonPrefix(Iterable<? extends CharSequence> seqs)
Find the longest possible common prefix of the provided char sequence.

Parameters:
seqs - the sequences
Returns:
the longest possible prefix

readAsBytes

public static byte[] readAsBytes(InputStream in)
                          throws IOException
Throws:
IOException

readAsUTF8

public static String readAsUTF8(InputStream in)

copy

public static void copy(InputStream in,
                        OutputStream out)
                 throws IOException
Throws:
IOException

read

private static ByteArrayOutputStream read(InputStream in)
                                   throws IOException
Throws:
IOException

toFile

public static File toFile(URL url)
                   throws IllegalArgumentException,
                          NullPointerException
Throws:
IllegalArgumentException
NullPointerException

resolveToClass

public static Class<?> resolveToClass(Type implementation,
                                      Class<?> type,
                                      int parameterIndex)

resolveToClass

public static Class resolveToClass(Type type)

resolve

public static Type resolve(Type implementation,
                           Class<?> type,
                           int parameterIndex)
A simplistic implementation, it may not handle all cases but it should handle enough.

Parameters:
implementation - the type for which the parameter requires a resolution
type - the type that owns the parameter
parameterIndex - the parameter index
Returns:
the resolved type

instanceOf

public static boolean instanceOf(Class c,
                                 List<String> types)

instanceOf

public static boolean instanceOf(Class c,
                                 String type)

interpolate

public static String interpolate(String interpolated,
                                 Map<?,?> context)
                          throws NullPointerException
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:

Parameters:
interpolated - the value to interpolate
context - the context
Returns:
the interpolated string
Throws:
NullPointerException - if the interpolated argument is null

getCurrentDirectory

public static File getCurrentDirectory()
Returns:
the current user directory


Copyright © 2015 eXo Platform SAS. All Rights Reserved.