I would like to get subsets of elements of a Java List by specifying some of their parameters. Each element has different characteristics, e.g. x-position, y-position, width, height and type. Now I want to get all elements, which position is in a specific interval, or which width or height is not greater than a given value, or which type equals some String.
My actual solution is, that I wrote a bunch of subset()-functions to apply in each different case.
public List<Element> subsetByPositionX(
List<Element> elements, int minX, int maxX) { /*...*/ }
public List<Element> subsetByPositionY(
List<Element> elements, int minY, int maxY) { /*...*/ }
public List<Element> subsetByMaxWidth(
List<Element> elements, int maxWidth) { /*...*/ }
// some more subset methods for height and width
public List<Element> subsetByType(
List<Element> elements, String... types) { /*...*/ }
I'm a bit unlucky about this, because it is not very generic. Is there a more elegant way to subset elements by different kinds of characteristics?