-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/com/schibsted/spt/data/jslt/impl/AbstractFunction.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,25 @@ | ||
|
||
// Copyright 2018 Schibsted Marketplaces Products & Technology As | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.schibsted.spt.data.jslt.impl; | ||
|
||
import com.schibsted.spt.data.jslt.Function; | ||
|
||
public abstract class AbstractFunction extends AbstractCallable implements Function { | ||
|
||
public AbstractFunction(String name, int min, int max) { | ||
super(name, min, max); | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/schibsted/spt/data/jslt/impl/OptimizedStaticContainsFunction.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,45 @@ | ||
|
||
// Copyright 2019 Schibsted Marketplaces Products & Technology As | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.schibsted.spt.data.jslt.impl; | ||
|
||
import java.util.Set; | ||
import java.util.HashSet; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.BooleanNode; | ||
|
||
/** | ||
* An optimized version of contains(a, b) which is used when b is an | ||
* array literal with a large number of values, so that a linear | ||
* search becomes a performance drag. | ||
*/ | ||
public class OptimizedStaticContainsFunction extends AbstractFunction { | ||
private Set<JsonNode> values; | ||
|
||
public OptimizedStaticContainsFunction(JsonNode array) { | ||
super("optimized-static-contains", 2, 2); | ||
|
||
this.values = new HashSet(); | ||
for (int ix = 0; ix < array.size(); ix++) | ||
values.add(array.get(ix)); | ||
} | ||
|
||
public JsonNode call(JsonNode input, JsonNode[] arguments) { | ||
if (values.contains(arguments[0])) | ||
return BooleanNode.TRUE; | ||
else | ||
return BooleanNode.FALSE; | ||
} | ||
} |