Skip to content

Commit

Permalink
Fix test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
shijinglu committed Apr 26, 2019
1 parent 8a8ac03 commit 9b08338
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/main/java/org/shijinglu/lure/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ public ContextBuilder addStringContext(String ctxKey, String ctxVal) {

public ContextBuilder addCustomizedContext(
String ctxKey, String ctxValRaw, String typeName) {
_context.put(
ctxKey,
ExtensionManager.EXT_DATA_TYPES.get(typeName).create(ctxValRaw, typeName));
_context.put(ctxKey, ExtensionManager.getDataFactor(typeName).create(ctxValRaw));
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/shijinglu/lure/core/NodeFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public IData evaluate(final Map<String, IData> context) {
.collect(Collectors.toList());
// left node string serves as the function name
final String fname = left.data.toString();
IFunction function = ExtensionManager.FUNCTIONS.get(fname);
IFunction function = ExtensionManager.getFunction(fname);
if (function == null) {
return BoolData.FALSE;
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/shijinglu/lure/extensions/ExtensionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.concurrent.ConcurrentMap;

public class ExtensionManager {
public static final ConcurrentMap<String, IFunction> FUNCTIONS;
public static final ConcurrentMap<String, IDataFactory> EXT_DATA_TYPES;
private static final ConcurrentMap<String, IFunction> FUNCTIONS;
private static final ConcurrentMap<String, IDataFactory> EXT_DATA_TYPES;

static {
FUNCTIONS = new ConcurrentHashMap<>();
Expand All @@ -14,7 +14,11 @@ public class ExtensionManager {
addDataFactory(new VersionData.VersionDataBuilder());
}

static void addFunction(IFunction f) {
public static IFunction getFunction(String fname) {
return FUNCTIONS.get(fname);
}

public static void addFunction(IFunction f) {
String fname = f.functionName();
if (FUNCTIONS.containsKey(fname)) {
throw new IllegalArgumentException(
Expand All @@ -25,7 +29,11 @@ static void addFunction(IFunction f) {
FUNCTIONS.put(fname, f);
}

static void addDataFactory(IDataFactory df) {
public static IDataFactory getDataFactor(String dfName) {
return EXT_DATA_TYPES.get(dfName);
}

public static void addDataFactory(IDataFactory df) {
String extKey = df.extKey();
if (EXT_DATA_TYPES.containsKey(extKey)) {
throw new IllegalArgumentException(
Expand Down

0 comments on commit 9b08338

Please sign in to comment.