|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.internet2.middleware.subject.SubjectUtils
public class SubjectUtils
Field Summary | |
---|---|
static String |
DATE_FORMAT
string format of dates |
static String |
DATE_MINUTES_SECONDS_FORMAT
format including minutes and seconds: yyyy/MM/dd HH:mm:ss |
static String |
DATE_MINUTES_SECONDS_NO_SLASH_FORMAT
format including minutes and seconds: yyyyMMdd HH:mm:ss |
static int |
DEFAULT_BUFFER_SIZE
The name says it all. |
static int |
NOT_FOUND
special number when a number is not found |
static String |
TIMESTAMP_FORMAT
format on screen of config for milestone: yyyy/MM/dd HH:mm:ss.SSS |
static String |
TIMESTAMP_NO_SLASH_FORMAT
format on screen of config for milestone: yyyyMMdd HH:mm:ss.SSS |
Constructor Summary | |
---|---|
SubjectUtils()
|
Method Summary | ||
---|---|---|
static void |
assertion(boolean isTrue,
String reason)
If false, throw an assertException, and give a reason |
|
static void |
assignField(Class theClass,
Object invokeOn,
String fieldName,
Object dataToAssign,
boolean callOnSupers,
boolean overrideSecurity,
boolean typeCast,
Class<? extends Annotation> annotationWithValueOverride)
assign data to a field |
|
static void |
assignField(Class theClass,
Object invokeOn,
String fieldName,
Object dataToAssign,
Class<? extends Annotation> annotationWithValueOverride)
assign data to a field. |
|
static void |
assignField(Field field,
Object invokeOn,
Object dataToAssign,
boolean overrideSecurity,
boolean typeCast)
assign data to a field |
|
static void |
assignField(Field field,
Object invokeOn,
Object dataToAssign,
boolean overrideSecurity,
boolean typeCast,
Class<? extends Annotation> annotationWithValueOverride)
assign data to a field |
|
static void |
assignField(Object invokeOn,
String fieldName,
Object dataToAssign)
assign data to a field. |
|
static BigDecimal |
bigDecimalObjectValue(Object input)
Convert an object to a byte, allow nulls |
|
static Boolean |
booleanObjectValue(Object object)
get the Boolean value for an object |
|
static boolean |
booleanValue(Object object)
get the boolean value for an object, cant be null or blank |
|
static boolean |
booleanValue(Object object,
boolean defaultBoolean)
get the boolean value for an object |
|
static Byte |
byteObjectValue(Object input)
Convert an object to a byte, allow nulls |
|
static byte |
byteValue(Object input)
convert an object to a byte |
|
static Character |
charObjectValue(Object input)
get the Character wrapper value for the input |
|
static char |
charValue(Object input)
convert an object to a char |
|
static ClassLoader |
classLoader()
fast class loader |
|
static String |
className(Object object)
null safe classname method, gets the unenhanced name |
|
static String |
classNameCollection(Object object)
null safe classname method, max out at 20 |
|
static void |
closeQuietly(Connection connection)
close a connection null safe and dont throw exception |
|
static void |
closeQuietly(InputStream input)
Unconditionally close an InputStream . |
|
static void |
closeQuietly(OutputStream output)
Unconditionally close an OutputStream . |
|
static void |
closeQuietly(Reader input)
Unconditionally close an Reader . |
|
static void |
closeQuietly(ResultSet resultSet)
close a resultSet null safe and dont throw exception |
|
static void |
closeQuietly(org.hsqldb.Session session)
close a session null safe and dont throw exception |
|
static void |
closeQuietly(Statement statement)
close a statement null safe and dont throw exception |
|
static void |
closeQuietly(Writer writer)
close a writer quietly |
|
static URL |
computeUrl(String resourceName,
boolean canBeNull)
compute a url of a resource |
|
static void |
copy(InputStream input,
Writer output,
String encoding)
Copy and convert bytes from an InputStream to chars on a
Writer , using the specified encoding. |
|
static int |
copy(Reader input,
Writer output)
Copy chars from a Reader to a Writer . |
|
static Date |
dateValue(Object inputObject)
Convert an object to a java.util.Date. |
|
static String |
defaultIfBlank(String string,
String defaultStringIfBlank)
return the string or the other if the first is blank |
|
static
|
defaultIfNull(T theValue,
T defaultIfTheValueIsNull)
genericized method to see if first is null, if so then return second, else first. |
|
static Double |
doubleObjectValue(Object input,
boolean allowNullBlank)
get the Double value of an object |
|
static double |
doubleValue(Object input)
get the double value of an object |
|
static double |
doubleValueNoError(Object input)
get the double value of an object, do not throw an exception if there is an error |
|
static Field |
field(Class theClass,
String fieldName,
boolean callOnSupers,
boolean throwExceptionIfNotFound)
get a field object for a class, potentially in superclasses |
|
static String |
fileCanonicalPath(File file)
get canonical path of file |
|
static File |
fileFromResourceName(String resourceName)
get a file name from a resource name |
|
static Float |
floatObjectValue(Object input,
boolean allowNullBlank)
get the Float value of an object |
|
static float |
floatValue(Object input)
get the float value of an object |
|
static float |
floatValueNoError(Object input)
get the float value of an object, do not throw an exception if there is an error |
|
static Class |
forName(String origClassName)
Returns the class object. |
|
static boolean |
injectInException(Throwable t,
String message)
If we can, inject this into the exception, else return false |
|
static Integer |
intObjectValue(Object input,
boolean allowNullBlank)
get the Integer value of an object |
|
static int |
intValue(Object input)
convert an object to a int |
|
static int |
intValue(Object input,
int valueIfNull)
convert an object to a int |
|
static int |
intValueNoError(Object input)
get the int value of an object, do not throw an exception if there is an error |
|
static boolean |
isBlank(Object input)
See if the input is null or if string, if it is empty or blank (whitespace) |
|
static Iterator |
iterator(Object collection)
null safe iterator getter if the type if collection |
|
static int |
length(Object arrayOrCollection)
Null safe array length or map |
|
static Long |
longObjectValue(Object input,
boolean allowNullBlank)
get the Long value of an object |
|
static long |
longValue(Object input)
convert an object to a long |
|
static long |
longValue(Object input,
long valueIfNull)
convert an object to a long |
|
static long |
longValueNoError(Object input)
get the long value of an object, do not throw an exception if there is an error |
|
static
|
newInstance(Class<T> theClass)
Construct a class |
|
static Object |
next(Object arrayOrCollection,
Iterator iterator,
int index)
If array, get the element based on index, if Collection, get it based on iterator. |
|
static boolean |
nullOrBlank(Object object)
is an object null or blank |
|
static Properties |
propertiesFromResourceName(String resourceName)
read properties from a resource, dont modify the properties returned since they are cached |
|
static Short |
shortObjectValue(Object input)
get the Short value of an object. |
|
static short |
shortValue(Object input)
convert an object to a short |
|
static Timestamp |
stringToTimestamp(String input)
convert a string to timestamp based on the following formats: yyyyMMdd yyyy/MM/dd HH:mm:ss yyyy/MM/dd HH:mm:ss.SSS yyyy/MM/dd HH:mm:ss.SSSSSS |
|
static String |
stringValue(Date date)
convert a date to the standard string yyyymmdd |
|
static String |
stringValue(Object input)
convert an object to a string |
|
static String |
substituteExpressionLanguage(String stringToParse,
Map<String,Object> variableMap)
substitute an EL for objects |
|
static String |
timestampToString(Date timestamp)
Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSS |
|
static String |
toString(InputStream input,
String encoding)
Get the contents of an InputStream as a String. |
|
static String |
toStringForLog(Object object)
print out various types of objects |
|
static String |
toStringForLog(Object object,
int maxChars)
print out various types of objects |
|
static Timestamp |
toTimestamp(Object input)
Convert a string or object to a timestamp (could be string, date, timestamp, etc) yyyymmdd or yyyy/MM/dd HH:mm:ss or yyyy/MM/dd HH:mm:ss.SSS or yyyy/MM/dd HH:mm:ss.SSSSSS |
|
static
|
typeCast(Object value,
Class<T> theClass)
If necessary, convert an object to another type. |
|
static
|
typeCast(Object value,
Class<T> theClass,
boolean convertNullToDefaultPrimitive,
boolean useNewInstanceHooks)
If necessary, convert an object to another type. |
|
static Class |
unenhanceClass(Class theClass)
if a class is enhanced, get the unenhanced version |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DATE_FORMAT
public static final String DATE_MINUTES_SECONDS_FORMAT
public static final String DATE_MINUTES_SECONDS_NO_SLASH_FORMAT
public static final String TIMESTAMP_FORMAT
public static final String TIMESTAMP_NO_SLASH_FORMAT
public static final int NOT_FOUND
public static final int DEFAULT_BUFFER_SIZE
Constructor Detail |
---|
public SubjectUtils()
Method Detail |
---|
public static boolean injectInException(Throwable t, String message)
t
- message
-
public static void assignField(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, boolean callOnSupers, boolean overrideSecurity, boolean typeCast, Class<? extends Annotation> annotationWithValueOverride)
theClass
- the class which has the methodinvokeOn
- to call on or null for staticfieldName
- method name to calldataToAssign
- datacallOnSupers
- if static and method not exists, try on supersoverrideSecurity
- true to call on protected or private etc methodstypeCast
- true if we should typecastannotationWithValueOverride
- annotation with value of overridepublic static void assignField(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, Class<? extends Annotation> annotationWithValueOverride)
theClass
- the class which has the methodinvokeOn
- to call on or null for staticfieldName
- method name to calldataToAssign
- dataannotationWithValueOverride
- annotation with value of overridepublic static void assignField(Field field, Object invokeOn, Object dataToAssign, boolean overrideSecurity, boolean typeCast)
field
- is the field to assign toinvokeOn
- to call on or null for staticdataToAssign
- dataoverrideSecurity
- true to call on protected or private etc methodstypeCast
- true if we should typecastpublic static void assignField(Field field, Object invokeOn, Object dataToAssign, boolean overrideSecurity, boolean typeCast, Class<? extends Annotation> annotationWithValueOverride)
field
- is the field to assign toinvokeOn
- to call on or null for staticdataToAssign
- dataoverrideSecurity
- true to call on protected or private etc methodstypeCast
- true if we should typecastannotationWithValueOverride
- annotation with value of override, or null if nonepublic static void assignField(Object invokeOn, String fieldName, Object dataToAssign)
invokeOn
- to call on or null for staticfieldName
- method name to calldataToAssign
- datapublic static Field field(Class theClass, String fieldName, boolean callOnSupers, boolean throwExceptionIfNotFound)
theClass
- fieldName
- callOnSupers
- true if superclasses should be looked in for the fieldthrowExceptionIfNotFound
- will throw runtime exception if not found
public static <T> T typeCast(Object value, Class<T> theClass)
T
- is template typevalue
- theClass
-
public static <T> T typeCast(Object value, Class<T> theClass, boolean convertNullToDefaultPrimitive, boolean useNewInstanceHooks)
T
- is the type to returnvalue
- theClass
- convertNullToDefaultPrimitive
- if the value is null, and theClass is primitive, should we
convert the null to a primitive default valueuseNewInstanceHooks
- if theClass is not recognized, then honor the string "null", "newInstance",
or get a constructor with one param, and call it
public static Date dateValue(Object inputObject)
Convert an object to a java.util.Date. allows, dates, null, blank, yyyymmdd or yyyymmdd hh24:mm:ss or yyyy/MM/dd HH:mm:ss.SSS
inputObject
- is the String or Date to convert
public static boolean isBlank(Object input)
input
-
public static Integer intObjectValue(Object input, boolean allowNullBlank)
input
- is a number or StringallowNullBlank
- true if convert null or blank to null
public static int intValue(Object input)
input
-
public static int intValue(Object input, int valueIfNull)
input
- valueIfNull
- is if the input is null or empty, return this value
public static int intValueNoError(Object input)
input
- is a number or String
public static String stringValue(Date date)
date
-
public static String stringValue(Object input)
input
- is the object to convert
public static String timestampToString(Date timestamp)
timestamp
-
public static String toString(InputStream input, String encoding) throws IOException
InputStream
as a String.
input
- the InputStream
to read fromencoding
- The name of a supported character encoding. See the
IANA
Charset Registry for a list of valid encoding types.
String
IOException
- In case of an I/O problempublic static Timestamp toTimestamp(Object input)
Convert a string or object to a timestamp (could be string, date, timestamp, etc) yyyymmdd or yyyy/MM/dd HH:mm:ss or yyyy/MM/dd HH:mm:ss.SSS or yyyy/MM/dd HH:mm:ss.SSSSSS
input
-
RuntimeException
- if invalid formatpublic static String className(Object object)
object
-
public static String classNameCollection(Object object)
object
-
public static BigDecimal bigDecimalObjectValue(Object input)
input
-
public static Boolean booleanObjectValue(Object object)
object
-
public static boolean booleanValue(Object object)
object
-
public static boolean booleanValue(Object object, boolean defaultBoolean)
object
- defaultBoolean
- if object is null or empty
public static Byte byteObjectValue(Object input)
input
-
public static byte byteValue(Object input)
input
-
public static Character charObjectValue(Object input)
input
- allow null, return null
public static char charValue(Object input)
input
-
public static Double doubleObjectValue(Object input, boolean allowNullBlank)
input
- is a number or StringallowNullBlank
- used to default to false, if true, return null if nul inputted
public static double doubleValue(Object input)
input
- is a number or String
public static double doubleValueNoError(Object input)
input
- is a number or String
public static Float floatObjectValue(Object input, boolean allowNullBlank)
input
- is a number or StringallowNullBlank
- true if allow null or blank
public static float floatValue(Object input)
input
- is a number or String
public static float floatValueNoError(Object input)
input
- is a number or String
public static Long longObjectValue(Object input, boolean allowNullBlank)
input
- is a number or StringallowNullBlank
- true if null or blank converts to null
public static long longValue(Object input)
input
-
public static long longValue(Object input, long valueIfNull)
input
- valueIfNull
- is if the input is null or empty, return this value
public static long longValueNoError(Object input)
input
- is a number or String
public static Short shortObjectValue(Object input)
input
- is a number or String
public static short shortValue(Object input)
input
-
public static Class forName(String origClassName)
Returns the class object.
origClassName
- is fully qualified
public static <T> T newInstance(Class<T> theClass)
T
- template typetheClass
-
public static String toStringForLog(Object object)
object
-
public static String toStringForLog(Object object, int maxChars)
object
- maxChars
- is the max chars that should be returned (abbreviate if longer), or -1 for any amount
public static int copy(Reader input, Writer output) throws IOException
Reader
to a Writer
.
input
- the Reader
to read fromoutput
- the Writer
to write to
IOException
- In case of an I/O problempublic static void copy(InputStream input, Writer output, String encoding) throws IOException
InputStream
to chars on a
Writer
, using the specified encoding.
input
- the InputStream
to read fromoutput
- the Writer
to write toencoding
- The name of a supported character encoding. See the
IANA
Charset Registry for a list of valid encoding types.
IOException
- In case of an I/O problempublic static Timestamp stringToTimestamp(String input)
convert a string to timestamp based on the following formats: yyyyMMdd yyyy/MM/dd HH:mm:ss yyyy/MM/dd HH:mm:ss.SSS yyyy/MM/dd HH:mm:ss.SSSSSS
input
-
public static Class unenhanceClass(Class theClass)
theClass
-
public static Iterator iterator(Object collection)
collection
-
public static int length(Object arrayOrCollection)
arrayOrCollection
-
public static Object next(Object arrayOrCollection, Iterator iterator, int index)
arrayOrCollection
- iterator
- index
-
public static boolean nullOrBlank(Object object)
object
-
public static <T> T defaultIfNull(T theValue, T defaultIfTheValueIsNull)
T
- theValue
- first inputdefaultIfTheValueIsNull
- second input
public static String defaultIfBlank(String string, String defaultStringIfBlank)
string
- defaultStringIfBlank
-
public static Properties propertiesFromResourceName(String resourceName)
resourceName
-
public static URL computeUrl(String resourceName, boolean canBeNull)
resourceName
- canBeNull
- if cant be null, throw runtime
public static ClassLoader classLoader()
public static void closeQuietly(Connection connection)
connection
- public static void closeQuietly(InputStream input)
InputStream
.
Equivalent to InputStream.close()
, except any exceptions will be ignored.
input
- A (possibly null) InputStreampublic static void closeQuietly(OutputStream output)
OutputStream
.
Equivalent to OutputStream.close()
, except any exceptions will be ignored.
output
- A (possibly null) OutputStreampublic static void closeQuietly(Reader input)
Reader
.
Equivalent to Reader.close()
, except any exceptions will be ignored.
input
- A (possibly null) Readerpublic static void closeQuietly(ResultSet resultSet)
resultSet
- public static void closeQuietly(org.hsqldb.Session session)
session
- public static void closeQuietly(Statement statement)
statement
- public static void closeQuietly(Writer writer)
writer
- public static File fileFromResourceName(String resourceName)
resourceName
- is the classpath location
public static String fileCanonicalPath(File file)
file
-
public static String substituteExpressionLanguage(String stringToParse, Map<String,Object> variableMap)
stringToParse
- variableMap
-
public static void assertion(boolean isTrue, String reason)
isTrue
- reason
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |