Compact Class For Java – CCClass


Compact Class is a collection of common functions and classes that can make your code more concise, fast, and precise.

utility

Class CCClass

java.lang.Object

extended by

utility.CCClass

public class CCClassextends java.lang.Object

CCClass is a collection of method is used to manipulate the class or field to
obtain the information contained in it.

Special thanks to: Irwan
Suryanto
.

Since:
10.03.17
Version:
12.03.17
Author:
Yosua Onesimus


Constructor Detail

CCClass

public CCClass()


Method Detail

get

public static java.lang.Object get(java.lang.reflect.Type type,
                                   java.lang.Object object)
Returns a Object with a value represented by the specified Object.

 

Parameters:
type
object

 

Returns:the type value represented by the Object.


getClass

public static java.lang.Class getClass(java.lang.String className)
Returns the Class object associated with the class or interface with the
given string name.

 

Parameters:
className – the fully qualified name of the desired class.

 

Returns:the Class object for the class with the specified name.


instanceOf

public static boolean instanceOf(java.lang.Class parent,
                                 java.lang.Class child)
Determines if the class or interface represented by this Class object is
either the same as, or is a superclass or superinterface of, the class or
interface represented by the specified Class parameter. It returns true
if so; otherwise it returns false. If this Class object represents a
primitive type, this method returns true if the specified Class parameter
is exactly this Class object; otherwise it returns false.

 

Parameters:
parent
child – the Class object to be checked.

 

Returns:the boolean value indicating whether objects of the type cls can
be assigned to objects of this class.


getTableName

public static java.lang.String getTableName(java.lang.Class clazz)
Return the table name associated with the class.

 

Parameters:
clazz

 

Returns:String table name.


getColumnName

public static java.lang.String getColumnName(java.lang.reflect.Field field)
Return the column name associated with the field.

 

Parameters:
field

 

Returns:String column name.


getObject

public static java.lang.Object getObject(java.lang.Class clazz)
Creates a new instance of the class represented by this Class object. The
class is instantiated as if by a new expression with an empty argument
list. The class is initialized if it has not already been initialized.

 

Parameters:
clazz

 

Returns:a newly allocated instance of the class represented by this
object.


getObject

public static java.lang.Object getObject(java.lang.String className)
Creates a new instance of the class represented by this Class object. The
class is instantiated as if by a new expression with an empty argument
list. The class is initialized if it has not already been
initialized.
Same as :
 getObject(getClass(className));

 

Parameters:
className – the fully qualified name of the desired class.

 

Returns:a newly allocated instance of the class represented by this
object.


getObject

public static java.lang.Object getObject(java.lang.Class clazz,
                                         java.lang.Class[] parameterTypes,
                                         java.lang.Object[] initargs)
Uses the constructor represented by this Constructor object to create and
initialize a new instance of the constructor’s declaring class, with the
specified initialization parameters. Individual parameters are
automatically unwrapped to match primitive formal parameters, and both
primitive and reference parameters are subject to method invocation
conversions as necessary.

 

Parameters:
clazz
parameterTypes– the parameter array.
initargs – array of objects to be passed as arguments to the
constructor call; values of primitive types are wrapped in a wrapper
object of the appropriate type (e.g. a float in a Float).

 

Returns:a new object created by calling the constructor this object
represents.


getObject

public static java.lang.Object getObject(java.lang.String className,
                                         java.lang.Class[] parameterTypes,
                                         java.lang.Object[] initargs)
Uses the constructor represented by this Constructor object to create and
initialize a new instance of the constructor’s declaring class, with the
specified initialization parameters. Individual parameters are
automatically unwrapped to match primitive formal parameters, and both
primitive and reference parameters are subject to method invocation
conversions as necessary.
Same as :
 getObject(getClass(className), parameterTypes, initargs);

 

Parameters:
className– the fully qualified name of the desired class.
parameterTypes– the parameter array.
initargs – array of objects to be passed as arguments to the
constructor call; values of primitive types are wrapped in a wrapper
object of the appropriate type (e.g. a float in a Float).

 

Returns:a new object created by calling the constructor this object
represents.


getObject

public static java.lang.Object getObject(java.lang.Class clazz,
                                         java.lang.Object... initargs)
Uses the constructor represented by this Constructor object to create and
initialize a new instance of the constructor’s declaring class, with the
specified initialization parameters. Individual parameters are
automatically unwrapped to match primitive formal parameters, and both
primitive and reference parameters are subject to method invocation
conversions as necessary.

 

Parameters:
clazz
initargs – array of objects to be passed as arguments to the
constructor call; values of primitive types are wrapped in a wrapper
object of the appropriate type (e.g. a float in a Float).

 

Returns:a new object created by calling the constructor this object
represents.


getObject

public static java.lang.Object getObject(java.lang.String className,
                                         java.lang.Object... initargs)
Uses the constructor represented by this Constructor object to create and
initialize a new instance of the constructor’s declaring class, with the
specified initialization parameters. Individual parameters are
automatically unwrapped to match primitive formal parameters, and both
primitive and reference parameters are subject to method invocation
conversions as necessary.
Same as :
 getObject(getClass(className), initargs);

 

Parameters:
className– the fully qualified name of the desired class.
initargs – array of objects to be passed as arguments to the
constructor call; values of primitive types are wrapped in a wrapper
object of the appropriate type (e.g. a float in a Float).

 

Returns:a new object created by calling the constructor this object
represents.


getField

public static java.lang.reflect.Field getField(java.lang.Class clazz,
                                               java.lang.String fieldName)
Returns a Field object that reflects the specified declared field of the
class or interface represented by this Class object. The name parameter
is a String that specifies the simple name of the desired field. Note
that this method will not reflect the length field of an array class.

 

Parameters:
clazz
fieldName – the name of the field.

 

Returns:the Field object for the specified field in this class.


getField

public static java.lang.reflect.Field getField(java.lang.Object object,
                                               java.lang.String fieldName)
Returns a Field object that reflects the specified declared field of the
class or interface represented by this Class object. The name parameter
is a String that specifies the simple name of the desired field. Note
that this method will not reflect the length field of an array
class.
Same as :
 getField(object.getClass(), fieldName);

 

Parameters:
object – object from which the represented field’s value is to be
extracted.
fieldName – the name of the field.

 

Returns:the Field object for the specified field in this class.


getFields

public static java.lang.reflect.Field[] getFields(java.lang.Class clazz)
Returns an array of Field objects reflecting all the fields declared by
the class or interface represented by this Class object. This includes
public, protected, default (package) access, and private fields, but
excludes inherited fields. The elements in the array returned are not
sorted and are not in any particular order. This method returns an array
of length 0 if the class or interface declares no fields, or if this
Class object represents a primitive type, an array class, or void.

 

Parameters:
clazz

 

Returns:the array of Field objects representing all the declared fields
of this class.


getFields

public static java.lang.reflect.Field[] getFields(java.lang.Object object)
Returns an array of Field objects reflecting all the fields declared by
the class or interface represented by this Class object. This includes
public, protected, default (package) access, and private fields, but
excludes inherited fields. The elements in the array returned are not
sorted and are not in any particular order. This method returns an array
of length 0 if the class or interface declares no fields, or if this
Class object represents a primitive type, an array class, or void.

Same as :

 getFields(object.getClass());

 

Parameters:
object – object from which the represented field’s value is to be
extracted.

 

Returns:the array of Field objects representing all the declared fields
of this class.


getValue

public static java.lang.Object getValue(java.lang.reflect.Field field,
                                        java.lang.Object object)
Returns the value of the field represented by this Field, on the
specified object. The value is automatically wrapped in an object if it
has a primitive type.

 

Parameters:
field
object – object from which the represented field’s value is to be
extracted.

 

Returns:the value of the represented field in object obj; primitive
values are wrapped in an appropriate object before being returned.


getValue

public static java.lang.Object getValue(java.lang.Object object,
                                        java.lang.String fieldName)
Returns the value of the field represented by this Field, on the
specified object. The value is automatically wrapped in an object if it
has a primitive type.
Same as :
 getValue(getField(object, fieldName), object);

 

Parameters:
object – object from which the represented field’s value is to be
extracted.
fieldName – the name of the field.

 

Returns:the value of the represented field in object obj; primitive
values are wrapped in an appropriate object before being returned.


setValue

public static boolean setValue(java.lang.reflect.Field field,
                               java.lang.Object object,
                               java.lang.Object value)
Sets the field represented by this Field object on the specified object
argument to the specified new value. The new value is automatically
unwrapped if the underlying field has a primitive type.

 

Parameters:
field
object– the object whose field should be modified.
value – the new value for the field of obj being modified.

 

Returns:boolean


setValue

public static boolean setValue(java.lang.Object object,
                               java.lang.String fieldName,
                               java.lang.Object value)
Sets the field represented by this Field object on the specified object
argument to the specified new value. The new value is automatically
unwrapped if the underlying field has a primitive type.
Same as :
 setValue(getField(object, fieldName), object, value);

 

Parameters:
object– the object whose field should be modified.
fieldName– the name of the field.
value – the new value for the field of obj being modified.

 

Returns:boolean


getCCField

public static CCClass.CCField getCCField(java.lang.Class clazz,
                                         java.lang.String fieldName)
Returns a CCField.

 

Parameters:
clazz
fieldName

 

Returns:a CCField


getCCField

public static CCClass.CCField getCCField(java.lang.Object object,
                                         java.lang.String fieldName)
Returns a CCField.

 

Parameters:
object
fieldName

 

Returns:a CCField


getCCFields

public static java.util.List<CCClass.CCField> getCCFields(java.lang.Class clazz)
Returns a List of CCField.

 

Parameters:
clazz

 

Returns:a List of CCField


getCCFields

public static java.util.List<CCClass.CCField> getCCFields(java.lang.Object object)
Returns a List of CCField.

 

Parameters:
object

 

Returns:a List of CCField


getCCField

public static CCClass.CCField getCCField(java.util.List<CCClass.CCField> cCFields,
                                         java.lang.String fieldName)
Returns a CCField.

 

Parameters:
cCFields
fieldName

 

Returns:a CCField


copy

public static void copy(java.lang.Object source,
                        java.lang.Object destination)
Copy value of field from source to destination.

 

Parameters:
source
destination

 


getIds

public static java.util.List<java.lang.Long> getIds(java.util.List list)
Get ids form list.

 

Parameters:
list

 

Returns:ids


getSysRef

public static java.lang.String getSysRef(java.lang.Class clazz,
                                         java.lang.Long id)
Parameters:
clazz
id

Returns:sysRef clazz.getName() + “:” + id;


getSysRef

public static java.lang.String getSysRef(java.lang.Object object)
Same as :
 getSysRef(object.getClass(), CCFormat.getLong(getValue(object, CCEntitySetting.FIELD_ID)));

 

Parameters:
object

 

Returns:sysRef clazz.getName() + “:” + id;


getObjectBySysRef

public static java.lang.Object getObjectBySysRef(java.lang.String sysRef)
Parameters:
sysRef – clazz.getName() + “:” + id;

Returns:Object


getObjectById

public static java.lang.Object getObjectById(java.lang.Class clazz,
                                             java.lang.Long id)
Same as :
 getObjectBySysRef(getSysRef(clazz, id));

 

Parameters:
clazz
id

 

Returns:object


objToString

public static java.lang.String objToString(java.lang.Object object,
                                           java.lang.Integer maxField)
Create String from object.

 

Parameters:
object
maxField

 

Returns:String


objToHashs

public static java.util.List objToHashs(java.lang.Object object,
                                        java.lang.Class<? extends CCEntityHash> hashClass)
Create hashs from object.

 

Parameters:
object
hashClass

 

Returns:hashs


hashsToObj

public static java.lang.Object hashsToObj(java.util.List hashs,
                                          java.lang.Class clazz)
Create object from hashs.

 

Parameters:
hashs
clazz

 

Returns:object


getClassName

public static java.lang.String getClassName(int index)
Parameters:
index

Returns:String


getCurrentClassName

public static java.lang.String getCurrentClassName()
Get the name of the current class.

 

Returns:
String

 


getCallerClassName

public static java.lang.String getCallerClassName()
Get the name of the class that calls this method.

 

Returns:
String

 


getLineNumber

public static int getLineNumber(int index)
Parameters:
index

Returns:int


getCurrentLineNumber

public static int getCurrentLineNumber()
Get the line number of the current class.

 

Returns:
int

 


getCallerLineNumber

public static int getCallerLineNumber()
Get the line number of the class that calls this method.

 

Returns:
int

 


getMethodName

public static java.lang.String getMethodName(int index)
Parameters:
index

Returns:String


getCurrentMethodName

public static java.lang.String getCurrentMethodName()
Get the method name of the current class.

 

Returns:
String

 


getCallerMethodName

public static java.lang.String getCallerMethodName()
Get the method name of the class that calls this method.

 

Returns:
String

 

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: