-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from turkraft/3.x.x
ParseContext + FieldMapper
- Loading branch information
Showing
9 changed files
with
136 additions
and
50 deletions.
There are no files selected for viewing
8 changes: 7 additions & 1 deletion
8
core/src/main/java/com/turkraft/springfilter/converter/FilterStringConverter.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
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
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
7 changes: 6 additions & 1 deletion
7
core/src/main/java/com/turkraft/springfilter/parser/FilterParser.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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package com.turkraft.springfilter.parser; | ||
|
||
import com.turkraft.springfilter.parser.node.FilterNode; | ||
import org.springframework.lang.Nullable; | ||
|
||
public interface FilterParser { | ||
|
||
FilterNode parse(String input); | ||
FilterNode parse(String input, @Nullable ParseContext ctx); | ||
|
||
default FilterNode parse(String input) { | ||
return parse(input, null); | ||
} | ||
|
||
} |
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
11 changes: 11 additions & 0 deletions
11
core/src/main/java/com/turkraft/springfilter/parser/ParseContext.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,11 @@ | ||
package com.turkraft.springfilter.parser; | ||
|
||
import java.util.function.UnaryOperator; | ||
|
||
public interface ParseContext { | ||
|
||
default UnaryOperator<String> getFieldMapper() { | ||
return UnaryOperator.identity(); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
core/src/main/java/com/turkraft/springfilter/parser/ParseContextImpl.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,18 @@ | ||
package com.turkraft.springfilter.parser; | ||
|
||
import java.util.function.UnaryOperator; | ||
|
||
public class ParseContextImpl implements ParseContext { | ||
|
||
private final UnaryOperator<String> fieldMapper; | ||
|
||
public ParseContextImpl(UnaryOperator<String> fieldMapper) { | ||
this.fieldMapper = fieldMapper; | ||
} | ||
|
||
@Override | ||
public UnaryOperator<String> getFieldMapper() { | ||
return fieldMapper; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
core/src/test/java/com/turkraft/springfilter/FieldMapperTest.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,41 @@ | ||
package com.turkraft.springfilter; | ||
|
||
import com.turkraft.springfilter.converter.FilterStringConverter; | ||
import com.turkraft.springfilter.parser.FilterParser; | ||
import com.turkraft.springfilter.parser.ParseContextImpl; | ||
import com.turkraft.springfilter.parser.node.FilterNode; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
public class FieldMapperTest { | ||
|
||
@Configuration | ||
@ComponentScan("com.turkraft.springfilter") | ||
static class Config { | ||
|
||
} | ||
|
||
@Autowired | ||
private FilterParser filterParser; | ||
|
||
@Autowired | ||
private FilterStringConverter filterStringConverter; | ||
|
||
@Test | ||
void test() { | ||
|
||
FilterNode node = filterParser.parse("x : y : z", new ParseContextImpl( | ||
(String field) -> field.equalsIgnoreCase("x") ? "a" | ||
: field.equalsIgnoreCase("y") ? "b" : field)); | ||
|
||
Assertions.assertEquals("a : b : z", filterStringConverter.convert(node)); | ||
|
||
} | ||
|
||
} |
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