Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Converting this function to using generics
- public static <T extends Enum<T> & SomeInterface> EnumSet<T> convertToES(long val) {
- EnumSet<T> es = EnumSet.noneOf(T.class);
- for(T t : values()) {
- if(t.getSomeProperty() > 0)
- es.add(t);
- }
- return es;
- }
- public static EnumSet<SomeType> convertToES(long val) {
- EnumSet<SomeType> es = EnumSet.noneOf(SomeType.class);
- for (SomeType p : values()) {
- if (p.getSomeThing())) > 0) {
- es.add(p);
- }
- }
- return es;
- }
- public static <T extends Enum<T> & SomeInterface> EnumSet<T> convertToES(
- long val,
- Class<T> tClass)
- {
- EnumSet<T> es = EnumSet.noneOf(tClass);
- for(T t : tClass.getEnumConstants()) {
- ....
- public static <T extends Enum<T> & SomeInterface> EnumSet<T> convertToES(Class<T> clazz, long val) {
- EnumSet<T> es = EnumSet.noneOf(clazz);
- for(T t : clazz.getEnumConstants()) {
- if(t.getSomeProperty() > 0)
- es.add(t);
- }
- return es;
- }
- public static <T extends Enum<T> & SomeInterface> //
- EnumSet<T> convertToES(Class<T> tClass, long val) {
- EnumSet<T> set = EnumSet.noneOf(tClass);
- for (T t : EnumSet.allOf(tClass)) {
- if (t.getSomeProperty() == val) {
- set.add(t);
- }
- }
- return set;
- }
- EnumSet<Foo> x = convertToES(Foo.class, 3);
- for(Foo suitableFoo: convertToES(Foo.class, 5)) {
- print(suitableFoo + " has a property of 5!");
- }
Advertisement
Add Comment
Please, Sign In to add comment