Lets say we have person class :
class Person{
long id;
String username;
String password
String firstName;
String lastName;
String address;
String phoneNumber;
// setters and getters..
}
And we have a hashmap full of objects of type person hashMap<String,Person>
with string being the object's username.
I want to way to search for the object with specified attributes (one or more), FOR EXAMPLE :
username:jim54 and address:UK
or
firstName: Jimmy with last name : tornabone and address :Poland
or
those who lives in UK ( address :UK )
Without writing ton of overloaded methods..
my method uses reflection to find the mutators of a single attribute :
Method getter=getDeclaredMethodIgnoreCase(Person.class,"get"+"attribute");
Method setter=getDeclaredMethodIgnoreCase(Person.class,"set"+"attribute");
then compares and changes
Aucun commentaire:
Enregistrer un commentaire