I'm surprised to see whether it's possible to do the following with Google Collections
The data structure Collection<Person> holds the list or persons and I wanted to find out person with name "X". This "X" can be passed to an API and that function should filter the collections based on that "X".
But I come to know if "X" is fixed, then we can filter the Collection<Person> like
com.google.common.base.Predicate<Person> predicate = new com.google.common.base.Predicate<Person>()
{
public boolean apply(Person person)
{
if(person.getName().equals("Suresh")
return true;
else
return false;
}
}
public Collection<Person> filterPerson()
{
com.google.common.collect.Collections2.filter(personList, predicate);
//personList is Collection<Person>
}
It's very difficult to identify how to filter the persons collection by supplying name as an argument to filterPerson method like filterPerson(String name).
Can anyone know how to do this?
The data structure Collection<Person> holds the list or persons and I wanted to find out person with name "X". This "X" can be passed to an API and that function should filter the collections based on that "X".
But I come to know if "X" is fixed, then we can filter the Collection<Person> like
com.google.common.base.Predicate<Person> predicate = new com.google.common.base.Predicate<Person>()
{
public boolean apply(Person person)
{
if(person.getName().equals("Suresh")
return true;
else
return false;
}
}
public Collection<Person> filterPerson()
{
com.google.common.collect.Collections2.filter(personList, predicate);
//personList is Collection<Person>
}
It's very difficult to identify how to filter the persons collection by supplying name as an argument to filterPerson method like filterPerson(String name).
Can anyone know how to do this?