JTheque Utils‎ > ‎

Usage

1. Collections and arrays

1.1 ArrayUtils

The ArrayUtils class provide several methods to manipulate arrays. The Javadoc is available here : org.jtheque.utils.collections.ArrayUtils

Here are the main methods of the class : 
  • void reverse(Object[] array) : Inverse the content of the array. 
  • int indexOf(Object object, Object[] tab) : Return the index of the object in the array of -1 if the object isn't contained in the array. 
  • boolean isEmpty(Object[] array) : Indicate if the array is empty or contains only null values. 
  • T[] copyOf(T[] array) : Create a copy of the array. 

1.2. CollectionUtils

The CollectionUtils class provide several methods to manipulate collections. The Javadoc is available here : org.jtheque.utils.collections.CollectionUtils

Here are the utility methods of this class : 
  • List<T> copyOf(Collection<T> list) : Create a copy of the collection. 
  • List<T> emptyList() : Return an empty list. The list is only created once and is unmodifiable. 
  • Collection<T> expand(Collection<S> collection, Expander<S,T> expander) : Expand a List from one content to other content using an Expander on each element of the source list. 
  • void filter(Collection<T> collection, Filter<T> filter) : Filter the list. 
  • T first(Iterable<T> collection) : Return the first element of the Iterable. 
  • void forAllDo(Iterable<T> collection, Closure<T> closure) : Execute the given closure for each element of the collection. 
  • void goToFirst(ListIterator<T> iterator) : Move the iterator to the first element. 
  • void goToLast(Iterator<T> iterator) : Move the iterator to the last element. 
  • void reverse(List list) : Reverse the order of the list. 
  • void sort(List<T> list, Comparator<T> comparator) : Sort the list using the given comparator. 
  • Collection<T> toCollection(Enumeration<T> enumeration) : Transform the enumeration to a collection. 

2. Counting

2.1. Counter

The Counter class enable to manipulate an integer counter. 

You can manipulate the counter using the given methods : 
  • void add(int i) : Add i to the counter. 
  • void clear() : Set 0 as the value of the counter. 
  • void decrement() : Decrement the counter. 
  • void increment() : Increment the counter. 
  • int getValue() : Return the value of the counter. 

2.2. Counters

The Counters class manage a set of Counter element. We can manipulate it with these methods : 

  • void addCounter(String name) : Add a counter with the given name. 
  • Counter getCounter(String name) : Return the counter with the specified name or null if there is no counter with this name. 
  • Counter getCounterOrAdd(String name) : Return the counter with the given name or create it and return it.  
  • Iterator<Map.Entry<String,Counter>> iterator() : Iterate the counters. 

This class is Iterable, so you can iterate over the counter on a foreach loop. 

3. Miscellaneous

3.1. StringUtils

The StringUtils class enable to manipulate String object. 

  • boolean endsWithOneOf(String value, String... ends)
  • boolean isEmpty(CharSequence string)
  • boolean isEmpty(String[] strings)
  • boolean isNotEmpty(CharSequence string)
  • boolean isNotEmpty(String[] strings)
  • boolean isStringSurroundedWith(CharSequence str, char c)
  • String removeHTMLEntities(String htmlString)
  • void removeLastSpace(StringBuilder builder)
  • String removeNumbers(CharSequence value)
  • String removeSurroundedChars(String str)
  • String removeUnicode(String value)
  • String setFirstLetterOnlyUpper(String word)
  • String setFirstLetterUpper(String word)

4. Beans

4.1. ReflectionUtils

The ReflectionUtils class provide methods to manipulate beans using Reflection : 

  • String getGetter(String property)
  • Method getGetterMethod(Object bean, String property)
  • PropertyDescriptor[] getProperties(Object bean)
  • Object getProperty(Object bean, PropertyDescriptor property)
  • Object getProperty(Object bean, String property)
  • Object getPropertyValue(Object bean, String property)

4.2 Duration

The Duration class represent a duration : 

  • Duration(int minutes)
  • int getHours()
  • int getMinutes()
  • void setHours(int hours)
  • void setMinutes(int minutes)

The equals(Object o)hashCode() and toString() methods are fully implemented.