sugar4j.lang
Class Lang

java.lang.Object
  extended by sugar4j.lang.Lang

public class Lang
extends Object

Extension methods for all classes that reside in java.lang.

Version:
$Id: Lang.java,v 1.11 2008/02/12 00:44:52 krizzdewizz Exp $
Author:
krizzdewizz

Nested Class Summary
static interface Lang.PairMethod
          Code to run for a pair.
 
Method Summary
static String capitalize(String s)
          Converts the first character of s to uppercase.
static String decorate(String s)
          Decorates s by appending it's last character.
static
<T> Throwable
findThrowable(Throwable t, Class<T> throwableClass)
           
static
<E> void
forEachPair(Iterable<E> iterable, Lang.PairMethod method)
          Runs the given method for every pair in the given iterator.
static
<T> void
forEachPair(Object[] array, Lang.PairMethod method)
          Runs the given method for every pair in the given array.
static String htmlColorize(String code)
          htmlColorize with "keyword" css-class and "comment" css-class.
static String htmlColorize(String code, String cssKeywordSpanClass, String cssCommentSpanClass)
          Highlights all keywords/comments in code using the html 'span' tag.
static boolean isSet(String s)
          Returns whether the given string is not null and not empty.
static
<T> List<T>
list(List<?> list)
          Provides an unchecked but typed version of the given list.
static String toIdentifier(String name)
          Returns a String suitable for use as a Java identifier.
 

Method Detail

forEachPair

public static <E> void forEachPair(Iterable<E> iterable,
                                   Lang.PairMethod method)
Runs the given method for every pair in the given iterator.

Type Parameters:
E - Element type of the iterator
Parameters:
iterable -
method -

forEachPair

public static <T> void forEachPair(Object[] array,
                                   Lang.PairMethod method)
Runs the given method for every pair in the given array.

Parameters:
array -
method -

capitalize

public static String capitalize(String s)
Converts the first character of s to uppercase.
Does nothing if s is empty.

Parameters:
s -
Returns:
String

decorate

public static String decorate(String s)
Decorates s by appending it's last character.
Does nothing if s is empty.

Parameters:
s -
Returns:
String

toIdentifier

public static String toIdentifier(String name)
Returns a String suitable for use as a Java identifier.

Parameters:
name -
Returns:
I.e. from customer-name to customerName

findThrowable

public static <T> Throwable findThrowable(Throwable t,
                                          Class<T> throwableClass)

htmlColorize

public static String htmlColorize(String code,
                                  String cssKeywordSpanClass,
                                  String cssCommentSpanClass)
Highlights all keywords/comments in code using the html 'span' tag. Every java keyword in code is enclosed within an 'span' tag. The result can be embedded in a html document. Known limitations: keywords in comments are also being highlighted, highlights only javadoc comments

Parameters:
code -
cssKeywordSpanClass - Css class name for the 'span' element to use for keywords
cssCommentSpanClass - Css class name for the 'span' element to use for comments
Returns:
html code

isSet

public static boolean isSet(String s)
Returns whether the given string is not null and not empty.

Parameters:
s -
Returns:
true if s is not null and not empty

htmlColorize

public static String htmlColorize(String code)
htmlColorize with "keyword" css-class and "comment" css-class.

Parameters:
code -
Returns:
html code

list

public static <T> List<T> list(List<?> list)
Provides an unchecked but typed version of the given list.
The list's content is not checked, so ClassCastException is likely to occur if the element's type do not match.

Parameters:
list -
Returns:
List