com.groupdocs.annotation.utils
Class Utils

java.lang.Object
  extended by com.groupdocs.annotation.utils.Utils

public final class Utils
extends Object

Utils methods

Author:
Alex Bobkov

Nested Class Summary
static interface Utils.IDistinct<T>
          Interface for check values
static interface Utils.IExcept<T>
          Interface for check values
static interface Utils.IFirst<T>
          Interface for select values
static interface Utils.ILast<T>
          Interface for select values
static interface Utils.ISelect<T,R>
          Interface for check values
static interface Utils.ISortListBy<T,R>
          Interface for sort values
static interface Utils.IWhere<T>
          Interface for check values
 
Method Summary
static
<T extends com.groupdocs.annotation.db.tables.ITable>
T
assetEntity(T t)
          Asset entity for null
static
<T extends com.groupdocs.annotation.db.tables.ITable>
T
assetEntity(T t, String errorMessage)
          Asset entity for null
static void closeStreams(Object... streams)
          For each parameters if it extends @{InputStream} or @{OutputStream} will call .close() method
static int colorToInt(com.aspose.pdf.Color color)
          Convert color object to int value
static int colorToInt(Color color)
          Convert color object to int value
static int colorToInt(float red, float green, float blue)
          Convert color to int value
static
<T> List<T>
distinct(List<T> values, Utils.IDistinct<T> distinct)
          Return unique values if distinct will check elements by equals
static String dt2s(Date date)
          Date to String format for database
static
<T> List<T>
except(List<T> sources, List<T> excepts, Utils.IExcept<T> except)
          Return list with values which exists in sources and don't exists in except list
static
<T> T
first(List<T> values, Utils.IFirst<T> first)
          Return first value for which check method return true, or null
static
<T> T
fromJson(String jsonString, Class<T> clazz)
          Convert json to object
static String getBody(javax.servlet.http.HttpServletRequest request)
          Get body from HTTP servlet request
static
<T> T
getObjectData(String request, Class<T> clazz)
          Get object from request
static String getTempPath()
           
static Color intToColor(int value)
           
static boolean isNullOrEmpty(String inputString)
          Check that string null or empty
static boolean isNullOrEmpty(String inputString, boolean spaceIsEmpty)
          Check that string null or empty
static
<T> T
last(List<T> values, Utils.ILast<T> last)
          Return first value for which check method return true, or null
static String makeAppPath(javax.servlet.http.HttpServletRequest request)
          Make base application path using parameters from request object
static int makeUniqueId()
           
static
<T,R> List<R>
ofType(List<T> values, Class<R> clazz)
          Return list of R type from values
static
<T> T
or(T source1, T source2)
          Return source2 if source1 is null else source1
static String processTemplate(String templateName, Map<String,Object> replaceValues)
          Process template (replace all ${some_word|default_value} to value in params map)
static Double round(Double value, int count)
           
static Date s2dt(String strDate)
          Parse String to Date format (default date format "yyyy-MM-dd HH:mm:ss" )
static Date s2dt(String strDate, String dateFormat)
          Parse String to Date format
static
<T,R> List<R>
select(List<T> values, Utils.ISelect<T,R> select)
          Return list with values which will be provided by select object for each element from values
static void setTempPath(String tempPath)
           
static
<T,R> List<T>
sortBy(List<T> values, boolean descending, Utils.ISortListBy<T,R> sortBy)
           
static
<K,V,R> Map<K,V>
sortBy(Map<K,V> values, boolean descending, Comparator<Map.Entry<K,V>> comparator)
          Return new sorted map by provided from sortBy object
static String toJson(com.google.gson.Gson gson, Object obj)
          Convert object to json
static String toJson(Object obj)
          Convert object to json
static long utcToLocal(long utcTime)
          Convert UTC time to local time using TimeZone.getDefault()
static
<T> List<T>
where(List<T> values, Utils.IWhere where)
          Return list with values, for which 'where' object return true
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setTempPath

public static void setTempPath(String tempPath)

getTempPath

public static String getTempPath()

processTemplate

public static String processTemplate(String templateName,
                                     Map<String,Object> replaceValues)
                              throws IOException
Process template (replace all ${some_word|default_value} to value in params map)

Parameters:
templateName - template name
replaceValues - map with params
Returns:
processed output
Throws:
IOException

getObjectData

public static <T> T getObjectData(String request,
                                  Class<T> clazz)
                       throws AnnotationException
Get object from request

Type Parameters:
T - object type
Parameters:
request - request
clazz - class type
Returns:
object with parsed and filled data from request
Throws:
AnnotationException - annotation exception

getBody

public static String getBody(javax.servlet.http.HttpServletRequest request)
                      throws AnnotationException
Get body from HTTP servlet request

Parameters:
request - HTTP servlet request
Returns:
body request body string
Throws:
AnnotationException - annotation exception

toJson

public static String toJson(Object obj)
Convert object to json

Parameters:
obj - object to convert
Returns:
converted object as json

toJson

public static String toJson(com.google.gson.Gson gson,
                            Object obj)
Convert object to json

Parameters:
gson - Gson oblect to serialize
obj - object to convert
Returns:
converted object as json

fromJson

public static <T> T fromJson(String jsonString,
                             Class<T> clazz)
Convert json to object

Type Parameters:
T - object type
Parameters:
jsonString - json
clazz - object type class
Returns:
object created from json

assetEntity

public static <T extends com.groupdocs.annotation.db.tables.ITable> T assetEntity(T t)
                                                                       throws AnnotationException
Asset entity for null

Type Parameters:
T - entity type
Parameters:
t - entity
Returns:
entity
Throws:
AnnotationException - annotation exception

assetEntity

public static <T extends com.groupdocs.annotation.db.tables.ITable> T assetEntity(T t,
                                                                                  String errorMessage)
                                                                       throws AnnotationException
Asset entity for null

Type Parameters:
T - entity type
Parameters:
t - entity
errorMessage - error message
Returns:
entity
Throws:
AnnotationException - annotation exception

dt2s

public static String dt2s(Date date)
Date to String format for database

Parameters:
date - input date
Returns:
date as String

s2dt

public static Date s2dt(String strDate)
Parse String to Date format (default date format "yyyy-MM-dd HH:mm:ss" )

Parameters:
strDate - date as String
Returns:
parsed date or null

s2dt

public static Date s2dt(String strDate,
                        String dateFormat)
Parse String to Date format

Parameters:
strDate - date as String
dateFormat - date format to parse (sample "yyyy-MM-dd HH:mm:ss" )
Returns:
parsed date or null

closeStreams

public static void closeStreams(Object... streams)
For each parameters if it extends @{InputStream} or @{OutputStream} will call .close() method

Parameters:
streams - streams to close

utcToLocal

public static long utcToLocal(long utcTime)
Convert UTC time to local time using TimeZone.getDefault()

Parameters:
utcTime - UTC time
Returns:
local time

makeAppPath

public static String makeAppPath(javax.servlet.http.HttpServletRequest request)
Make base application path using parameters from request object

Parameters:
request - http servlet request
Returns:
base application path with context (like http://annotation.local:8080/context-path/ )

colorToInt

public static int colorToInt(com.aspose.pdf.Color color)
Convert color object to int value

Parameters:
color - com.aspose.pdf.Color object
Returns:
int value

colorToInt

public static int colorToInt(Color color)
Convert color object to int value

Parameters:
color - java.awt.Color object
Returns:
int value

colorToInt

public static int colorToInt(float red,
                             float green,
                             float blue)
Convert color to int value

Parameters:
red - red part of color
green - green part of color
blue - blue part of color
Returns:
int value

round

public static Double round(Double value,
                           int count)

or

public static <T> T or(T source1,
                       T source2)
Return source2 if source1 is null else source1

Type Parameters:
T - parameters type
Parameters:
source1 - object1 for check to null
source2 - object to return if source1 is null
Returns:
result

makeUniqueId

public static int makeUniqueId()

where

public static <T> List<T> where(List<T> values,
                                Utils.IWhere where)
Return list with values, for which 'where' object return true

Type Parameters:
T - type of values to check
Parameters:
values - values to filter
where - object to check each values
Returns:
filtered list

except

public static <T> List<T> except(List<T> sources,
                                 List<T> excepts,
                                 Utils.IExcept<T> except)
Return list with values which exists in sources and don't exists in except list

Type Parameters:
T -
Parameters:
sources - list to filter
excepts - elements which should be filtered
except - object to
Returns:

select

public static <T,R> List<R> select(List<T> values,
                                   Utils.ISelect<T,R> select)
Return list with values which will be provided by select object for each element from values

Type Parameters:
T - source type
R - result type
Parameters:
values - list to check
select - object to return value
Returns:
list with values

distinct

public static <T> List<T> distinct(List<T> values,
                                   Utils.IDistinct<T> distinct)
Return unique values if distinct will check elements by equals

Type Parameters:
T - list type
Parameters:
values - list to check
distinct - check object
Returns:
result list

sortBy

public static <K,V,R> Map<K,V> sortBy(Map<K,V> values,
                                      boolean descending,
                                      Comparator<Map.Entry<K,V>> comparator)
Return new sorted map by provided from sortBy object

Parameters:
values - map to sort
descending -
comparator - object for compare values
Returns:
sorted map

sortBy

public static <T,R> List<T> sortBy(List<T> values,
                                   boolean descending,
                                   Utils.ISortListBy<T,R> sortBy)
Type Parameters:
T -
R -
Parameters:
values -
descending -
sortBy -
Returns:

first

public static <T> T first(List<T> values,
                          Utils.IFirst<T> first)
Return first value for which check method return true, or null

Type Parameters:
T - type of objects in list
Parameters:
values - values to check
first - object for checkung
Returns:
first object with true checking or null

last

public static <T> T last(List<T> values,
                         Utils.ILast<T> last)
Return first value for which check method return true, or null

Type Parameters:
T - type of objects in list
Parameters:
values - values to check
last - object for checkung
Returns:
first object with true checking or null

ofType

public static <T,R> List<R> ofType(List<T> values,
                                   Class<R> clazz)
Return list of R type from values

Type Parameters:
T - input type
R - output type
Parameters:
values - to filter
clazz - filtered class
Returns:
filtered list

intToColor

public static Color intToColor(int value)

isNullOrEmpty

public static boolean isNullOrEmpty(String inputString)
Check that string null or empty

Parameters:
inputString - input string
Returns:
result

isNullOrEmpty

public static boolean isNullOrEmpty(String inputString,
                                    boolean spaceIsEmpty)
Check that string null or empty

Parameters:
inputString - input string
spaceIsEmpty - space equals to empty
Returns:


Copyright © 2014. All rights reserved.