|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--comparatorreflector.ComparatorReflector
Comparator| Field Summary | |
private String |
attributeName
beanClass Attribute name that will be used for comparisions. |
private String[] |
attributes
Attribute names that will be used for comparisions. |
private Class |
beanClass
Base Class who will be compared. |
private Method |
getterMethod
Getter Method related to attribute indicated by attributeName. |
private Method[] |
gettersMethods
Getters Methods related to attributes indicated by attributes array. |
(package private) Logger |
logger
|
| Constructor Summary | |
ComparatorReflector()
Default Constructor. |
|
ComparatorReflector(Class beanClass)
Constructor with class to be used. |
|
ComparatorReflector(Class beanClass,
String[] attributes)
Constructor with class and attribute name. |
|
| Method Summary | |
int |
compare(Object o1,
Object o2)
Compare two Ojects (so-called from class determined by beanClass) according with attributes determined by attributes array. |
private int |
compareAttributes(Object o1,
Object o2)
Compare two Objects (not nulls) according their attibutes. |
boolean |
equals(Object obj)
Compare this ComparatorReflector with another object (presumably another ComparatorReflector). |
String |
getAttributeName()
Deprecated. Use getAttributes instead. |
String[] |
getAttributes()
|
private Object |
getAttributeValue(Object obj,
Method method)
Returns attributevalue in a determinaded object. |
Class |
getBeanClass()
|
private Object |
getFilledObject(Object value)
Create a beanClass instance with attributeBean filled. |
private Method |
getGetter(String fieldName)
Returns a beanClass getter method from a name of attribute. |
private Method |
getGetterMethod(String attributeName)
Returns a beanClass getter method from a attribute name. |
private String |
getGetterMethodName(String name)
Create a getter method name from a attribute name [Cria o nome de um método getter a partir do nome de um atributo.] |
private List |
getList(Collection col)
Create a List from a Collection. |
Object |
getMax(Collection col)
Returns item from a Collection that contains maximum value according setted attribute. |
Object |
getMin(Collection col)
Returns item from a Collection that contains minimum value according setted attribute. |
private String |
getSetterMethodName(String name)
Create a setter method name from a attribute name [Cria o nome de um método setter a partir do nome de um atributo.] |
List |
getSortedList(Collection col)
Create a Sorted List according attribute setted by attributeName from a Collection. |
int |
hashCode()
|
private boolean |
isComparable(Class candidateClass)
Verifies if a class implements Comparable interface. |
private boolean |
isCompatibles(Object object,
Class klass)
Verify if a certain object is compatible with a certain class. |
private void |
makeGettersArray()
Creates the getters methods array to be used, gettersMethods, from attributes name array, attribute. |
Collection |
search(Collection col,
Object key)
Search for a Object in a Collection. |
Collection |
searchByAttribute(Collection col,
Object key)
Procura por algum objeto cujo valor do atributo setado seja igual ao do objeto Dado um objeto da mesma classe |
void |
setAttributeName(String value)
Change beanClass attribute name that will be used for comparisions. |
void |
setAttributes(String[] strings)
|
void |
setBeanClass(Class value)
It sets base class that will be compared. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
Logger logger
private Class beanClass
Classprivate String attributeName
private Method getterMethod
Methodprivate String[] attributes
private Method[] gettersMethods
Method| Constructor Detail |
public ComparatorReflector()
public ComparatorReflector(Class beanClass)
throws ComparatorReflectorException
beanClass - Class who will be compared.
[Classe que será usada.]
public ComparatorReflector(Class beanClass,
String[] attributes)
throws ComparatorReflectorException
beanClass - Class who will be compared.
[Classe base que que será comparada.]| Method Detail |
private Method getGetter(String fieldName)
throws ComparatorReflectorException
fieldName - A (so-called) beanClass attribute name.
[Nome de um (suposto) atributo de beanClass.]
ComparatorReflectorException - If there is not a getter method or
this method is not public.
[Se não existir método getter ou este método não for público.]getGetterMethodName(java.lang.String)
private Method getGetterMethod(String attributeName)
throws ComparatorReflectorException
attributeName -
ComparatorReflectorException - If there is not a getter method or
this method is not public.
[Se não existir método getter ou este método não for público.]getGetter(java.lang.String)
private String getGetterMethodName(String name)
throws ComparatorReflectorException
name - Attribute name.
[Nome do atibuto.]
ComparatorReflectorException - If name was null or
empty.
[Se nome for null ou vazio.]
private String getSetterMethodName(String name)
throws ComparatorReflectorException
name - Attribute name.
[Nome do atibuto.]
ComparatorReflectorException - If name was null or
empty.
[Se nome for null ou vazio.]getGetterMethodName(java.lang.String)
private Object getAttributeValue(Object obj,
Method method)
throws ComparatorReflectorException
obj - Object (beanClass instance) from where will be extracted
setted attribute value.
[Objeto (instância de banClass) de onde será extraído o valor do atributo
setado.]
ComparatorReflectorException - If getter method is not public or it has arguments or it throws a
exception.
[Se o método getter não for publico ou tiver argumentos ou disparar uma
exceção.]private List getList(Collection col)
col - Source Collection.
[Colecao inicial.]
private boolean isComparable(Class candidateClass)
candidateClass - analisable class.
[Classe a ser analisada.]
true if class is Comparacle itself or implements
it. false otherwise.
[true se a classe for a própria Comparable ou
implementá-la. false caso contrário.]Comparable
private boolean isCompatibles(Object object,
Class klass)
object - Object to be analized
[Objeto a ser analizado.]klass - Class to be compared with object.
[Classe a ser comparada com object.]
true if object is a instance of klass or its
derivated or if klass is a primitive and class object is its respective
wrapper; false otherwise.
[true se object for uma instancia de klass ou alguma
derivada dessa ou se klass for uma primitiva e a classe de object for
uma instancia de seu respectivo wrapper.]
private Object getFilledObject(Object value)
throws ComparatorReflectorException
value - attributeBean value
[Valor a ser atribuido a attributeBean.]
ComparatorReflectorException - If it is not possible create a
beanClass Instance or setter method referent to attributeBean is not
public or this setter method throws a Exception.
[Se nao for possivel criar uma instancia de beanClass ou se não existir
metodo setter referente a attributeBean ou se este metodo setter
disparar uma excecao.]private void makeGettersArray()
ComparatorReflectorException - If there is not a getter method or
this method is not public.
[Se não existir método getter ou este método não for público.]
private int compareAttributes(Object o1,
Object o2)
nulls) according their attibutes.
o1 - First Object (not nulls) to be compared.o2 - Second Object (not nulls) to be compared with o1.
Comparable.compareTo(java.lang.Object)public String[] getAttributes()
public String getAttributeName()
public Class getBeanClass()
public void setAttributes(String[] strings)
strings - Attribute names that will be used for comparisions.
[Nome dos atributos que serão usados para comparações.]
public void setAttributeName(String value)
throws ComparatorReflectorException
value - A beanClass attribute name that will be used for
comparisions.
[Nome de um dos atributos de beanClass que servira de base para
comparacao.]
ComparatorReflectorException - If there is not difinied class;
If there is not a getter method for attribute indicated by value. It can
indicate that there is not this attribute.
[Se não há classe definida; Se não existir um método getter para o
atributo indicado por value. Isto pode indicar que tal atributo
simplesmente não existe.]
public void setBeanClass(Class value)
throws ComparatorReflectorException
value - Base Class who will be compared.
[Classe que será comparada.]
ComparatorReflectorExceptionpublic Object getMax(Collection col)
col - Collection where will be make search.
[Colecao onde será feita a busca.]
public int compare(Object o1,
Object o2)
throws ComparatorReflectorException
compare in interface Comparatoro1 - First Object (so-called a beanClass instance).
[Primeiro Objeto (presumivelmente uma instancia de beanClass).]o2 - Object that will be compared with o1 (so-called a beanClass
instance too).
[Objeto a ser comparado com o1 (presumivelmente uma instancia de
beanClass também).]
null: returns 0;
[Tanto o1 quanto o2 são null: retorna 0;]
o1 is not null and o2 is null: returns
+1, because o1 will be "bigger" than o2.
[o1 é não null e o2 é null: retorna +1, pois o1
seria "maior" que o2]
o1 is null and o2 is not null: returns
-1, because o1 will be "lesser" than o2;
[o1 é nulo e o2 é não nulo: retorna -1, pois o1 seria "menor" que o2]
both o1 and o2 are not null: result is going to
depend of attribute determined by values of attributes determinated by
attributes array:
[o1 e o2 não são nulos: O resultado vai depender dos valores dos
atributos determinados pelo array de atributos:]
null: returns 0;
[Tanto valor1 e valor2 são nulos: retorna 0;]
value1 is not null and value2 is: return +1, because
value1 will be "bigger" than value2;
[valor1 é não nulo e valor2 é nulo: retorna +1, pois valor1 seria
"maior" que valor2;]
value1 is null and value2 is not: return -1, because
value1 will be "lesser" than value2;
[valor1 é nulo e valor2 é não nulo: retorna -1, pois valor1 seria "menor"
que valor2;]
Both value1 and value2 are not null: value1 is
compared with value2 according these class.
[valor1 e valor2 não são nulos: valor1 é comparado com valor2 de acordo
com suas classes.]
ComparatorReflectorExceptioncompareAttributes(java.lang.Object, java.lang.Object)public Object getMin(Collection col)
col - Collection where will be make search.
[Colecao onde será feita a busca.]
public List getSortedList(Collection col)
col - Source Collection
[Coleção base]
public Collection search(Collection col,
Object key)
throws ComparatorReflectorException
col - Collection where will be made the search.
[Coleção onde será feita a busca.]key - beanClass instance where
[Objeto procurado]
null if this
object does not exist.
[Objeto da Coleção equivalente a key ou null se este objeto
não existir.]
ComparatorReflectorException - If key is not from same class (or
sub-class) definied by beanClass
[Se key não for da mesma classe (ou sub-classe) definida por beanClass.]getBeanClass(),
getAttributeName()
public Collection searchByAttribute(Collection col,
Object key)
throws ComparatorReflectorException
col - Colection where will be made the search.
[Colecao onde será feita a busca.]key - Objeto da mesma classe do objeto setado
ComparatorReflectorException - If it is not possible create a
beanClass Instance or setter method referent to attributeBean is not
public or this setter method throws a Exception or if key class is not
equals than attributeBean class
[Se nao for possivel criar uma instancia de beanClass ou se não existir
metodo setter referente a attributeBean ou se este metodo setter
disparar uma excecao.]public boolean equals(Object obj)
equals in interface Comparatorequals in class Objectobj - Object (presumably another ComparatorReflector) that this
ComparatorReflector compared.
[Objeto (presumivelmente outro ComparatorReflector) com o qual este
ComparatorReflector será comparado.]
true in these conditions: 1) obj is exactly the
same instance of this ComparatorReflector; 2) obj is a instance of
ComparatorReflector with same beanClass and attributeName of this
ComparatorReflector. false otherwise.
[true nas seguites condições: 1) obj é exatamente a mesma
instancia deste ComparatorReflector; 2) obj é uma instancia de
ComparatorReflector com o mesmo beanClass e attributeName deste
ComparatorReflector. Caso nenhuma das duas condições sejam satisfeitas,
é retornado false.]public int hashCode()
hashCode in class ObjectObject.hashCode()public String toString()
toString in class Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||