- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
public CustomCollection<T> wherePropertyIs(String propertyName, Object value) {
CustomCollection<T> lstTemp = new CustomCollection <T>();
if (this.size() > 0) {
Field foundField = null;
for (Field f : this.get(0).getClass().getDeclaredFields()){
if (f.getName().equals(propertyName)){
foundField = f;
break;
}
}
if (foundField != null) {
foundField.setAccessible(true);
try {
for(T obj : this){
if (foundField.get(obj).equals(value)){
lstTemp.add(obj);
}
}
}catch (IllegalAccessException e){
System.out.println(e.getMessage());
}
}
}
return lstTemp;
}