From a8d4311ca3d62dfc8aa54ef5183df80c61006b7c Mon Sep 17 00:00:00 2001 From: Moriarty <22225248+apmoriarty@users.noreply.github.com> Date: Tue, 27 Jun 2023 08:21:21 -0400 Subject: [PATCH] Add KeyParserFactory that operates on an enum (#2007) --- .../query/data/parsers/KeyParserFactory.java | 35 +++++++++++++++++++ .../data/parsers/KeyParserFactoryTest.java | 28 +++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 warehouse/query-core/src/main/java/datawave/query/data/parsers/KeyParserFactory.java create mode 100644 warehouse/query-core/src/test/java/datawave/query/data/parsers/KeyParserFactoryTest.java diff --git a/warehouse/query-core/src/main/java/datawave/query/data/parsers/KeyParserFactory.java b/warehouse/query-core/src/main/java/datawave/query/data/parsers/KeyParserFactory.java new file mode 100644 index 00000000000..9aeb32f0723 --- /dev/null +++ b/warehouse/query-core/src/main/java/datawave/query/data/parsers/KeyParserFactory.java @@ -0,0 +1,35 @@ +package datawave.query.data.parsers; + +/** + * Utility to create a {@link KeyParser} from a {@link PARSER_TYPE} + */ +public class KeyParserFactory { + + public enum PARSER_TYPE { + FIELD_INDEX, EVENT, TERM_FREQUENCY + } + + private KeyParserFactory() { + // static utility + } + + /** + * Create a KeyParser from the provided type + * + * @param type + * the kind of key parser to create + * @return a key parser + */ + public static KeyParser create(PARSER_TYPE type) { + switch (type) { + case FIELD_INDEX: + return new FieldIndexKey(); + case EVENT: + return new EventKey(); + case TERM_FREQUENCY: + return new TermFrequencyKey(); + default: + return null; + } + } +} diff --git a/warehouse/query-core/src/test/java/datawave/query/data/parsers/KeyParserFactoryTest.java b/warehouse/query-core/src/test/java/datawave/query/data/parsers/KeyParserFactoryTest.java new file mode 100644 index 00000000000..e9395e2c9a0 --- /dev/null +++ b/warehouse/query-core/src/test/java/datawave/query/data/parsers/KeyParserFactoryTest.java @@ -0,0 +1,28 @@ +package datawave.query.data.parsers; + +import datawave.query.data.parsers.KeyParserFactory.PARSER_TYPE; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class KeyParserFactoryTest { + + @Test + public void testCreateFieldIndexKey() { + KeyParser parser = KeyParserFactory.create(PARSER_TYPE.FIELD_INDEX); + assertTrue(parser instanceof FieldIndexKey); + } + + @Test + public void testCreateEventKey() { + KeyParser parser = KeyParserFactory.create(PARSER_TYPE.EVENT); + assertTrue(parser instanceof EventKey); + } + + @Test + public void testCreateTermFrequencyKey() { + KeyParser parser = KeyParserFactory.create(PARSER_TYPE.TERM_FREQUENCY); + assertTrue(parser instanceof TermFrequencyKey); + } + +}