I have a project where in different scenarios I have to work with different subsets of a large data set. As I wrote the code, there is a Collector interface and a DataCollector implements Collector class. The DataCollector class is created with the condition of creating a subset, and these conditions are enumerations.
Let's say a data set is a set of 1 million English words, and I want to work on a subset of words consisting of an odd number of letters. Then I do the following:
DataCollector dataCollector = new DataCollector(CollectionType.WORDS_OF_ODD_LENGTH); Set<String> fourLetteredWords = dataCollector.collect();
where CollectionType is an enumeration class
enum CollectionType { WORDS_OF_ODD_LENGTH, WORDS_OF_EVEN_LENGTH, STARTING_WITH_VOWEL, STARTING_WITH_CONSONANT, .... }
The data collector calls java.util.Predicate depending on the enumeration with which it was created.
Until now, this approach has been quite strong and flexible, but now I come across increasingly complex scenarios (for example, they collect words of even length, starting with a vowel). I would like to avoid adding a new CollectionType for each such scenario. I noticed that many of these complex scenarios are just logical operations on simpler ones (for example, condition_1 && (condition_2 || condition_3) ).
The end user is the one who sets these conditions, and the only control I have is that I can specify a set of such conditions. As with the case, the end user can only select CollectionType . Right now I'm trying to generalize the possibility of choosing only one condition for the possibility of choosing one or more. For this I need something like
DataCollector dataCollector = new DataCollector(WORDS_OF_ODD_LENGTH && STARTING_WITH_VOWEL);
Is there a way that I model my enumerations to perform such operations? I am open to other ideas (like, I should just abandon this enum-based approach for something else, etc.).