Skip to content

Commit

Permalink
Add KeyParserFactory that operates on an enum (#2007)
Browse files Browse the repository at this point in the history
  • Loading branch information
apmoriarty authored Jun 27, 2023
1 parent ebdbc40 commit a8d4311
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
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;
}
}
}
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);
}

}

0 comments on commit a8d4311

Please sign in to comment.