Commit fb0bc5ce authored by Matija Obreza's avatar Matija Obreza

Added normalize() method to filters

parent 1a176cad
...@@ -283,4 +283,33 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten ...@@ -283,4 +283,33 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten
} }
return NOTNULL; return NOTNULL;
} }
/**
* Prepare filter for use. NULL and NOTNULLs will clear any actual values
* provided for those properties.
*
* @param <Q> any BasicModelFilter subtype
* @param filter the filter
* @return
*/
public static <Q extends BasicModelFilter<?, ?>> Q normalize(final Q filter) {
Set<String> toClear = new HashSet<>();
if (filter.NULL != null) {
toClear.addAll(filter.NULL);
}
if (filter.NOTNULL != null) {
toClear.addAll(filter.NOTNULL);
}
for (String path: toClear) {
try {
filter.clearFilter(path, false);
} catch (NoSuchFieldException | IllegalAccessException e) {
System.err.println("Error while clearing filter: " + e.getMessage());
}
}
return filter;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment