-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add KeyParserFactory that operates on an enum (#2007)
- Loading branch information
1 parent
ebdbc40
commit a8d4311
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
warehouse/query-core/src/main/java/datawave/query/data/parsers/KeyParserFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
warehouse/query-core/src/test/java/datawave/query/data/parsers/KeyParserFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |