Generic Filter for enum

Generic Filter for enum

Following is my class

Following is my class

public final class Test {
enum Animal {DOG,CAT};
enum COLOR {RED,YELLOW};

class Meaningless { String animal,color; } public void filter(List<Meaningless> meaninglesses){ meaninglesses.stream() .filter(meaningless -> { try { Animal.valueOf(meaningless.animal); return true; }catch(Exception e){ return false; } }) .filter(meaningless -> { try { COLOR.valueOf(meaningless.color); return true; }catch(Exception e){ return false; } }) .collect(Collectors.toList()); }

}

The 2 iterations of filter methods essentially filters out the invalid enum types. How can I remove the code duplication from this ? The check should be generic enough so that I dont have to change the isValidEnum when there is a new enum introduced.

Ideally I would like to do something like

 meaninglesses.stream()
            .filter(meaningless -> isValidEnum(meaningless.animal,Animal.class))
            .filter(meaningless -> isValidEnum(meaningless.color,COLOR.class))


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Java Fundamentals: Learn Java for absolute beginners |Simpliv

Java Fundamentals: Learn Java for absolute beginners

Java Essentials : Learn Core Java From Basic to Advance

Learn Java Programming Using Practical Assignments. Start Building Back-end Web Applications Robust Test Automation Frameworks By End Of The Course. Learn More!

Fundamentos de Java: Aprende Java desde cero, sin misterios | Simpliv

Fundamentos de Java: Aprende Java desde cero, sin misterios