asfgit closed pull request #1298: METRON-1934 fix errorprone messages, remove
logical unreachable statements
URL: https://github.com/apache/metron/pull/1298
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/metron-stellar/stellar-3rd-party-example/src/main/java/org/apache/metron/stellar/external/TimeFunction.java
b/metron-stellar/stellar-3rd-party-example/src/main/java/org/apache/metron/stellar/external/TimeFunction.java
index 887531ec11..0e689d211a 100644
---
a/metron-stellar/stellar-3rd-party-example/src/main/java/org/apache/metron/stellar/external/TimeFunction.java
+++
b/metron-stellar/stellar-3rd-party-example/src/main/java/org/apache/metron/stellar/external/TimeFunction.java
@@ -30,13 +30,15 @@
returns="Timestamp"
)
public static class Now implements StellarFunction {
-
+ @Override
public Object apply(List<Object> list, Context context) throws
ParseException {
return System.currentTimeMillis();
}
-
+
+ @Override
public void initialize(Context context) { }
-
+
+ @Override
public boolean isInitialized() {
return true;
}
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/CachingStellarProcessor.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/CachingStellarProcessor.java
index 28d69b300c..cf2ba3dae8 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/CachingStellarProcessor.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/CachingStellarProcessor.java
@@ -134,6 +134,7 @@ public String toString() {
* @return The value of the evaluated Stellar expression, {@code expression}.
*/
@Override
+ @SuppressWarnings("unchecked")
public Object parse(
String expression,
VariableResolver variableResolver,
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/Constants.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/Constants.java
index 50ad830442..f536fed72e 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/Constants.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/Constants.java
@@ -25,11 +25,6 @@
public static final String ZOOKEEPER_ROOT = "/metron";
public static final String ZOOKEEPER_TOPOLOGY_ROOT = ZOOKEEPER_ROOT +
"/topology";
public static final long DEFAULT_CONFIGURED_BOLT_TIMEOUT = 5000;
-/* public static final String SENSOR_TYPE = "source.type";
- public static final String ENRICHMENT_TOPIC = "enrichments";
- public static final String INDEXING_TOPIC = "indexing";
- public static final String SIMPLE_HBASE_ENRICHMENT = "hbaseEnrichment";
- public static final String SIMPLE_HBASE_THREAT_INTEL = "hbaseThreatIntel"; */
public static final String ERROR_STREAM = "error";
public static final String GUID = "guid";
@@ -61,6 +56,7 @@
this.name = name;
}
+ @Override
public String getName() {
return name;
}
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/StellarCompiler.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/StellarCompiler.java
index ac5412b3da..1a507c8d10 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/StellarCompiler.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/StellarCompiler.java
@@ -446,12 +446,13 @@ public void
exitNInExpressionStatement(StellarParser.NInExpressionStatementConte
}
@Override
+ @SuppressWarnings("unchecked")
public void exitNotFunc(StellarParser.NotFuncContext ctx) {
final FrameContext.Context context = getArgContext();
- expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
- Token<Boolean> arg = (Token<Boolean>) popDeque(tokenDeque);
- Boolean v = Optional.ofNullable(ConversionUtils.convert(arg.getValue(),
Boolean.class)).orElse(false);
- tokenDeque.push(new Token<>(!v, Boolean.class, context));
+ expression.tokenDeque.push(new Token<>((tokenDeque, state) -> {
+ Token<Boolean> arg = (Token<Boolean>) popDeque(tokenDeque);
+ Boolean v = Optional.ofNullable(ConversionUtils.convert(arg.getValue(),
Boolean.class)).orElse(false);
+ tokenDeque.push(new Token<>(!v, Boolean.class, context));
}, DeferredFunction.class, context));
}
@@ -600,10 +601,11 @@ private void enterLambdaVariables() {
expression.tokenDeque.push(LAMBDA_VARIABLES);
}
+ @SuppressWarnings("ReferenceEquality")
private void exitLambdaVariables() {
Token<?> t = expression.tokenDeque.pop();
LinkedList<String> variables = new LinkedList<>();
- for(; !expression.tokenDeque.isEmpty() && t != LAMBDA_VARIABLES; t =
expression.tokenDeque.pop()) {
+ for (; !expression.tokenDeque.isEmpty() && t != LAMBDA_VARIABLES; t =
expression.tokenDeque.pop()) {
variables.addFirst(t.getValue().toString());
}
expression.tokenDeque.push(new Token<>(variables, List.class,
getArgContext()));
@@ -613,6 +615,7 @@ private void enterLambda() {
expression.tokenDeque.push(EXPRESSION_REFERENCE);
}
+ @SuppressWarnings({"unchecked","ReferenceEquality"})
private void exitLambda(boolean hasArgs) {
final FrameContext.Context context = getArgContext();
Token<?> t = expression.tokenDeque.pop();
@@ -620,11 +623,11 @@ private void exitLambda(boolean hasArgs) {
for(; !expression.tokenDeque.isEmpty() && t != EXPRESSION_REFERENCE; t =
expression.tokenDeque.pop()) {
instanceDeque.addLast(t);
}
- final List<String> variables = hasArgs? (List<String>)
instanceDeque.removeLast().getValue() :new ArrayList<>();
- expression.tokenDeque.push(new Token<>( (tokenDeque, state) -> {
+ final List<String> variables = hasArgs ? (List<String>)
instanceDeque.removeLast().getValue() :new ArrayList<>();
+ expression.tokenDeque.push(new Token<>((tokenDeque, state) -> {
LambdaExpression expr = new LambdaExpression(variables, instanceDeque,
state);
tokenDeque.push(new Token<>(expr, Object.class, context));
- }, DeferredFunction.class, context) );
+ }, DeferredFunction.class, context));
}
@Override
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/benchmark/StellarMicrobenchmark.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/benchmark/StellarMicrobenchmark.java
index 914105ebfe..50ee403d3b 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/benchmark/StellarMicrobenchmark.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/benchmark/StellarMicrobenchmark.java
@@ -20,11 +20,15 @@
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.io.Files;
+
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
@@ -229,22 +233,22 @@ public static void main(String... argv) throws
IOException {
);
List<String> lines = Files.readLines(expressionsFile,
Charset.defaultCharset());
Map<String, Object> variables = new HashMap<>();
- if(variablesFile.isPresent()) {
+ if (variablesFile.isPresent()) {
variables = JSONUtils.INSTANCE.load(new
FileInputStream(variablesFile.get()), JSONUtils.MAP_SUPPLIER);
}
int numTimes = DEFAULT_NUM_TIMES;
- if(BenchmarkOptions.NUM_TIMES.has(cli)) {
+ if (BenchmarkOptions.NUM_TIMES.has(cli)) {
numTimes = Integer.parseInt(BenchmarkOptions.NUM_TIMES.get(cli));
}
int warmup = DEFAULT_WARMUP;
- if(BenchmarkOptions.WARMUP.has(cli)) {
+ if (BenchmarkOptions.WARMUP.has(cli)) {
warmup = Integer.parseInt(BenchmarkOptions.WARMUP.get(cli));
}
Double[] percentiles = DEFAULT_PERCENTILES;
- if(BenchmarkOptions.PERCENTILES.has(cli)) {
+ if (BenchmarkOptions.PERCENTILES.has(cli)) {
List<Double> percentileList = new ArrayList<>();
- for(String token :
Splitter.on(",").split(BenchmarkOptions.PERCENTILES.get(cli))) {
- if(token.trim().isEmpty()) {
+ for (String token :
Splitter.on(",").split(BenchmarkOptions.PERCENTILES.get(cli))) {
+ if (token.trim().isEmpty()) {
continue;
}
Double d = Double.parseDouble(token.trim());
@@ -252,12 +256,12 @@ public static void main(String... argv) throws
IOException {
}
percentiles = (Double[])percentileList.toArray();
}
- PrintWriter out = new PrintWriter(System.out);
- if(output.isPresent()) {
- out = new PrintWriter(output.get());
+ PrintWriter out = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(System.out, StandardCharsets.UTF_8)));
+ if (output.isPresent()) {
+ out = new PrintWriter(output.get(), StandardCharsets.UTF_8.name());
}
- for(String statement : lines) {
- if(statement.trim().startsWith("#") || statement.trim().isEmpty()) {
+ for (String statement : lines) {
+ if (statement.trim().startsWith("#") || statement.trim().isEmpty()) {
continue;
}
Microbenchmark.StellarStatement s = new
Microbenchmark.StellarStatement();
@@ -269,7 +273,7 @@ public static void main(String... argv) throws IOException {
out.println("Expression: " + statement);
out.println(Microbenchmark.describe(stats, percentiles));
}
- if(argv.length > 2) {
+ if (argv.length > 2) {
out.close();
}
}
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/configuration/ConfigurationsUtils.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/configuration/ConfigurationsUtils.java
index 1add3ab428..399e5d1554 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/configuration/ConfigurationsUtils.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/configuration/ConfigurationsUtils.java
@@ -30,6 +30,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
@@ -62,7 +63,7 @@ public static void writeGlobalConfigToZookeeper(byte[]
globalConfig, String zook
}
public static void writeGlobalConfigToZookeeper(byte[] globalConfig,
CuratorFramework client) throws Exception {
- GLOBAL.deserialize(new String(globalConfig));
+ GLOBAL.deserialize(new String(globalConfig, StandardCharsets.UTF_8));
writeToZookeeper(GLOBAL.getZookeeperRoot(), globalConfig, client);
}
@@ -100,53 +101,17 @@ public static void writeToZookeeper(String path, byte[]
configData, CuratorFrame
return new byte[]{};
}
-/* public static void uploadConfigsToZookeeper(String globalConfigPath,
- String parsersConfigPath,
- String enrichmentsConfigPath,
- String indexingConfigPath,
- String profilerConfigPath,
- String zookeeperUrl) throws
Exception {
- try(CuratorFramework client = getClient(zookeeperUrl)) {
- client.start();
- uploadConfigsToZookeeper(globalConfigPath, parsersConfigPath,
enrichmentsConfigPath, indexingConfigPath, profilerConfigPath, client);
- }
- }
-
- public static void uploadConfigsToZookeeper(String rootFilePath,
CuratorFramework client) throws Exception {
- uploadConfigsToZookeeper(rootFilePath, rootFilePath, rootFilePath,
rootFilePath, rootFilePath, client);
- }
-
- public static void uploadConfigsToZookeeper(String globalConfigPath,
- String parsersConfigPath,
- String enrichmentsConfigPath,
- String indexingConfigPath,
- String profilerConfigPath,
- CuratorFramework client) throws
Exception {
-
- // global
- if (globalConfigPath != null) {
- final byte[] globalConfig = readGlobalConfigFromFile(globalConfigPath);
- if (globalConfig.length > 0) {
- setupStellarStatically(client, Optional.of(new String(globalConfig)));
-
ConfigurationsUtils.writeGlobalConfigToZookeeper(readGlobalConfigFromFile(globalConfigPath),
client);
- }
- }
- }
- */
-
public static void setupStellarStatically(CuratorFramework client) throws
Exception {
byte[] ret = null;
try {
ret = readGlobalConfigBytesFromZookeeper(client);
- }
- catch(KeeperException.NoNodeException nne) {
+ } catch (KeeperException.NoNodeException nne) {
//can't find the node
}
- if(ret == null || ret.length == 0) {
+ if (ret == null || ret.length == 0) {
setupStellarStatically(client, Optional.empty());
- }
- else {
- setupStellarStatically(client, Optional.of(new String(ret)));
+ } else {
+ setupStellarStatically(client, Optional.of(new String(ret,
StandardCharsets.UTF_8)));
}
}
@@ -177,7 +142,7 @@ public static void setupStellarStatically(CuratorFramework
client, Optional<Stri
return globalConfig;
}
- public interface ConfigurationVisitor{
+ public interface ConfigurationVisitor {
void visit(ConfigurationType configurationType, String name, String data);
}
@@ -194,7 +159,7 @@ public static void visitConfigs(CuratorFramework client,
ConfigurationVisitor ca
if (configType.equals(GLOBAL)) {
byte[] globalConfigData =
client.getData().forPath(configType.getZookeeperRoot());
- callback.visit(configType, "global", new String(globalConfigData));
+ callback.visit(configType, "global", new String(globalConfigData,
StandardCharsets.UTF_8));
}
}
}
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/evaluators/NumberLiteralEvaluator.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/evaluators/NumberLiteralEvaluator.java
index 24dccbab86..2c5d5403f3 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/evaluators/NumberLiteralEvaluator.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/evaluators/NumberLiteralEvaluator.java
@@ -52,13 +52,13 @@
}
}
- Token<? extends Number> evaluate(StellarParser.Arithmetic_operandsContext
context
- , Map<Class<? extends
StellarParser.Arithmetic_operandsContext>, NumberEvaluator> instanceMap
- , FrameContext.Context contextVariety
- )
- {
+ @SuppressWarnings("unchecked")
+ Token<? extends Number> evaluate(StellarParser.Arithmetic_operandsContext
context,
+ Map<Class<? extends
StellarParser.Arithmetic_operandsContext>, NumberEvaluator> instanceMap,
+ FrameContext.Context contextVariety
+ ) {
NumberEvaluator evaluator = instanceMap.get(context.getClass());
- if(evaluator == null) {
+ if (evaluator == null) {
throw new ParseException("Does not support evaluation for type " +
context.getClass());
}
return evaluator.evaluate(context, contextVariety);
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/shell/DefaultStellarShellExecutor.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/shell/DefaultStellarShellExecutor.java
index 352ae2b9db..99c6256041 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/shell/DefaultStellarShellExecutor.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/shell/DefaultStellarShellExecutor.java
@@ -264,6 +264,7 @@ public StellarResult execute(String expression) {
* @return The global configuration.
*/
@Override
+ @SuppressWarnings("unchecked")
public Map<String, Object> getGlobalConfig() {
Map<String, Object> globals;
Optional<Object> capability = getContext().getCapability(GLOBAL_CONFIG,
false);
@@ -294,6 +295,7 @@ public FunctionResolver getFunctionResolver() {
}
@Override
+ @SuppressWarnings("unchecked")
public Map<String, VariableResult> getState() {
return UnmodifiableMap.decorate(variables);
}
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/ConcatMap.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/ConcatMap.java
index 53a52a634f..1f17bf4d42 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/ConcatMap.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/ConcatMap.java
@@ -156,10 +156,11 @@ public void clear() {
}
@Override
+ @SuppressWarnings("unchecked")
public Set<String> keySet() {
Set<String> ret = null;
- for(Map m : variableMappings) {
- if(ret == null) {
+ for (Map m : variableMappings) {
+ if (ret == null) {
ret = m.keySet();
}
else {
@@ -174,9 +175,10 @@ public void clear() {
* @return
*/
@Override
+ @SuppressWarnings("unchecked")
public Collection<Object> values() {
Collection<Object> ret = new ArrayList<>(size());
- for(Map m : variableMappings) {
+ for (Map m : variableMappings) {
ret.addAll(m.values());
}
return ret;
@@ -188,13 +190,13 @@ public void clear() {
* @return
*/
@Override
+ @SuppressWarnings("unchecked")
public Set<Entry<String, Object>> entrySet() {
Set<Entry<String, Object>> ret = null;
- for(Map m : variableMappings) {
- if(ret == null) {
+ for (Map m : variableMappings) {
+ if (ret == null) {
ret = m.entrySet();
- }
- else {
+ } else {
ret = Sets.union(ret, m.entrySet());
}
}
@@ -202,6 +204,7 @@ public void clear() {
}
@Override
+ @SuppressWarnings("unchecked")
public String toString() {
Iterable<Iterable<Map.Entry<Object, Object>>> transformed =
Iterables.transform(variableMappings, x -> x.entrySet());
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/SerDeUtils.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/SerDeUtils.java
index eff4f88eb6..aeaa6eb712 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/SerDeUtils.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/SerDeUtils.java
@@ -132,7 +132,8 @@ public InstantiatorStrategy getFallbackInstantiatorStrategy
() {
}
@Override
- public ObjectInstantiator newInstantiatorOf (final Class type) {
+ @SuppressWarnings("unchecked")
+ public ObjectInstantiator newInstantiatorOf(final Class type) {
if (!Util.isAndroid) {
// Use ReflectASM if the class is not a non-static member class.
Class enclosingType = type.getEnclosingClass();
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/hashing/tlsh/TLSH.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/hashing/tlsh/TLSH.java
index 9913b82216..8c6d17a510 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/hashing/tlsh/TLSH.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/hashing/tlsh/TLSH.java
@@ -28,7 +28,7 @@
* The abstraction around interacting with TLSH.
*/
public class TLSH {
- TlshCreator creator;
+ private TlshCreator creator;
public TLSH(BucketOption bucketOption, ChecksumOption checksumOption) {
creator = new TlshCreator(bucketOption, checksumOption);
}
@@ -37,16 +37,20 @@ public String apply(byte[] data, boolean force) {
try {
creator.update(data);
return creator.getHash(force).getEncoded();
- }
- finally {
+ } finally {
creator.reset();
}
}
public static int distance(String hash1, String hash2, Optional<Boolean>
includeLength) {
- if(hash1 == null || hash2 == null && hash1 != hash2) {
+ if (hash1 == null || hash2 == null) {
return -1;
}
+
+ if (hash1.equals(hash2)) {
+ return 0;
+ }
+
Tlsh t1 = Tlsh.fromTlshStr(hash1);
Tlsh t2 = Tlsh.fromTlshStr(hash2);
return t1.totalDiff(t2, includeLength.orElse(false));
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/hashing/tlsh/TLSHHasher.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/hashing/tlsh/TLSHHasher.java
index b04fbc749d..f3f8e4fb3f 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/hashing/tlsh/TLSHHasher.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/hashing/tlsh/TLSHHasher.java
@@ -27,6 +27,7 @@
import org.apache.metron.stellar.common.utils.hashing.EnumConfigurable;
import org.apache.metron.stellar.common.utils.hashing.Hasher;
+import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.util.*;
@@ -69,64 +70,54 @@ public String getKey() {
public Object getHash(Object o) throws EncoderException,
NoSuchAlgorithmException {
TLSH tlsh = TLSHCache.INSTANCE.get().getTLSH(bucketOption, checksumOption);
byte[] data = null;
- if(o instanceof String) {
- data = ((String)o).getBytes();
- }
- else if(o instanceof byte[]) {
+ if (o instanceof String) {
+ data = ((String)o).getBytes(StandardCharsets.UTF_8);
+ } else if (o instanceof byte[]) {
data = (byte[])o;
- }
- else {
+ } else {
data = SerDeUtils.toBytes(o);
}
try {
String hash = tlsh.apply(data, force);
- if(hashes != null && hashes.size() > 0) {
+ if (hashes != null && hashes.size() > 0) {
Map<String, Object> ret = new HashMap<>();
ret.put(TLSH_KEY, hash);
ret.putAll(bin(hash));
return ret;
- }
- else {
+ } else {
return hash;
}
- }
- catch(IllegalStateException ise) {
- return null;
- } catch (DecoderException e) {
+ } catch (Exception e) {
return null;
}
}
public Map<String, String> bin(String hash) throws DecoderException {
Random r = new Random(0);
- byte[] h =
Hex.decodeHex(hash.substring(2*checksumOption.getChecksumLength()).toCharArray());
+ byte[] h = Hex.decodeHex(hash.substring(2 *
checksumOption.getChecksumLength()).toCharArray());
BitSet vector = BitSet.valueOf(h);
int n = vector.length();
Map<String, String> ret = new HashMap<>();
boolean singleHash = hashes.size() == 1;
- for(int numHashes : hashes) {
+ for (int numHashes : hashes) {
BitSet projection = new BitSet();
for (int i = 0; i < numHashes; ++i) {
int index = r.nextInt(n);
projection.set(i, vector.get(index));
}
String outputHash = numHashes +
Hex.encodeHexString(projection.toByteArray());
- if(singleHash) {
+ if (singleHash) {
ret.put(TLSH_BIN_KEY, outputHash);
- }
- else {
+ } else {
ret.put(TLSH_BIN_KEY + "_" + numHashes, outputHash);
}
}
return ret;
}
-
-
-
@Override
public void configure(Optional<Map<String, Object>> config) {
- if(config.isPresent() && !config.get().isEmpty()) {
+ if (config.isPresent() && !config.get().isEmpty()) {
bucketOption = Config.BUCKET_SIZE.get(config.get()
, o -> {
Integer bucketSize = ConversionUtils.convert(o, Integer.class);
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/DataStructureFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/DataStructureFunctions.java
index bebe27d5d4..fa504a7c7f 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/DataStructureFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/DataStructureFunctions.java
@@ -43,11 +43,12 @@
public static class BloomAdd extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
BloomFilter<Object> filter = (BloomFilter)args.get(0);
- for(int i = 1;i < args.size();++i) {
+ for (int i = 1;i < args.size();++i) {
Object arg = args.get(i);
- if(arg != null) {
+ if (arg != null) {
filter.add(args.get(i));
}
}
@@ -55,25 +56,26 @@ public Object apply(List<Object> args) {
}
}
- @Stellar(name="EXISTS"
- , namespace="BLOOM"
- , description="If the bloom filter contains the value"
- , params = { "bloom - The bloom filter"
- , "value - The value to check"
- }
- , returns = "True if the filter might contain the value and false
otherwise"
+ @Stellar(name = "EXISTS",
+ namespace = "BLOOM",
+ description = "If the bloom filter contains the value",
+ params = { "bloom - The bloom filter",
+ "value - The value to check"
+ },
+ returns = "True if the filter might contain the value and false
otherwise"
)
public static class BloomExists extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
- if(args.size() == 0) {
+ if (args.size() == 0) {
return false;
}
BloomFilter<Object> filter = (BloomFilter)args.get(0);
- if(args.size() > 1) {
+ if (args.size() > 1) {
Object arg = args.get(1);
- if(arg == null) {
+ if (arg == null) {
return false;
}
return filter.mightContain(arg);
@@ -82,13 +84,13 @@ public Object apply(List<Object> args) {
}
}
- @Stellar(name="INIT"
- , namespace="BLOOM"
- , description="Returns an empty bloom filter"
- , params = { "expectedInsertions - The expected insertions"
- , "falsePositiveRate - The false positive rate you are
willing to tolerate"
- }
- , returns = "Bloom Filter"
+ @Stellar(name = "INIT",
+ namespace = "BLOOM",
+ description = "Returns an empty bloom filter",
+ params = { "expectedInsertions - The expected insertions",
+ "falsePositiveRate - The false positive rate you are
willing to tolerate"
+ },
+ returns = "Bloom Filter"
)
public static class BloomInit extends BaseStellarFunction {
@@ -96,11 +98,11 @@ public Object apply(List<Object> args) {
public Object apply(List<Object> args) {
int expectedInsertions = 100000;
float falsePositiveRate = 0.01f;
- if(args.size() > 1) {
+ if (args.size() > 1) {
expectedInsertions = ConversionUtils.convert(args.get(0),
Integer.class);
}
- if(args.size() > 2) {
- falsePositiveRate= ConversionUtils.convert(args.get(1), Float.class);
+ if (args.size() > 2) {
+ falsePositiveRate = ConversionUtils.convert(args.get(1), Float.class);
}
return new BloomFilter<>(SerDeUtils.SERIALIZER, expectedInsertions,
falsePositiveRate);
}
@@ -116,17 +118,17 @@ public Object apply(List<Object> args) {
public static class BloomMerge extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
- if(args.size() > 0) {
+ if (args.size() > 0) {
Object firstArg = args.get(0);
- if(firstArg instanceof List) {
+ if (firstArg instanceof List) {
BloomFilter ret = null;
- for(Object bf : (List)firstArg) {
- if(bf instanceof BloomFilter) {
- if(ret == null) {
+ for (Object bf : (List)firstArg) {
+ if (bf instanceof BloomFilter) {
+ if (ret == null) {
ret = (BloomFilter)bf;
- }
- else {
+ } else {
ret.merge((BloomFilter)bf);
}
}
@@ -177,53 +179,49 @@ else if(o instanceof String) {
public static class ListAdd extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
if (list.size() == 0) {
return null;
}
Object o = list.get(0);
- if(list.size() == 1) {
+ if (list.size() == 1) {
return o;
}
- if(o instanceof List) {
+ if (o instanceof List) {
List l = (List)o;
Object arg = list.get(1);
l.add(arg);
return l;
- }
- else {
+ } else {
return o;
}
}
}
- @Stellar(name="LENGTH"
- , description="Returns the length of a string or size of a
collection. Returns 0 for empty or null Strings"
- , params = { "input - Object of string or collection type (e.g.
list)"}
- , returns = "Integer"
+ @Stellar(name = "LENGTH",
+ description = "Returns the length of a string or size of a
collection. Returns 0 for empty or null Strings",
+ params = { "input - Object of string or collection type (e.g.
list)"},
+ returns = "Integer"
)
public static class Length extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
- if(list.size() == 0) {
+ if (list.size() == 0) {
return 0;
}
Object o = list.get(0);
- if(o instanceof Collection) {
+ if (o instanceof Collection) {
return ((Collection)o).size();
- }
- else if(o instanceof Map) {
+ } else if (o instanceof Map) {
return ((Map)o).size();
- }
- else if(o instanceof String) {
+ } else if (o instanceof String) {
String val = (String) list.get(0);
return val == null || val.isEmpty() ? 0 : val.length();
- }
- else {
+ } else {
return 0;
}
}
}
-
-
}
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/DateFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/DateFunctions.java
index 17f5f8dcc0..7ad91b7d41 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/DateFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/DateFunctions.java
@@ -152,15 +152,16 @@ public Object apply(List<Object> objects) {
}
}
- @Stellar( name="DATE_FORMAT",
+ @Stellar(name = "DATE_FORMAT",
description = "Takes an epoch timestamp and converts it to a date
format.",
- params = {"format - DateTime format as a String."
- , "timestampField - Optional epoch time in Long format.
Defaults to now."
- , "timezone - Optional timezone in String format."},
- returns="Formatted date."
+ params = {"format - DateTime format as a String.",
+ "timestampField - Optional epoch time in Long format.
Defaults to now.",
+ "timezone - Optional timezone in String format."},
+ returns = "Formatted date."
)
public static class DateFormat extends BaseStellarFunction {
+ @Override
public Object apply(List<Object> objects) {
int size = objects.size();
Optional<Object> formatObj = Optional.ofNullable(objects.get(0));
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/FunctionalFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/FunctionalFunctions.java
index 3c5545261c..c11fa6096e 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/FunctionalFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/FunctionalFunctions.java
@@ -113,14 +113,15 @@ public Object apply(List<Object> args) {
}
}
+ @SuppressWarnings("unchecked")
private static Iterable<? extends Object> getIterable(Object o) {
- if(o == null) {
+ if (o == null) {
return null;
}
- if(o instanceof String) {
+ if (o instanceof String) {
return Lists.charactersOf((String)o);
}
- else if(o instanceof Iterable) {
+ else if (o instanceof Iterable) {
return (Iterable<Object>)o;
}
else {
@@ -171,16 +172,17 @@ public Object apply(List<Object> args) {
}
}
+ @SuppressWarnings("unchecked")
private static List<List<Object>> zip(List<Object> args, boolean jagged) {
List<List<Object>> lists = new ArrayList<>();
Integer resultSize = null;
- for(Object o : args) {
- if(o instanceof List) {
+ for (Object o : args) {
+ if (o instanceof List) {
List<Object> l = (List<Object>)o;
- if( resultSize == null) {
+ if (resultSize == null) {
resultSize = l.size();
}
- else if(jagged) {
+ else if (jagged) {
resultSize = Math.max(l.size(), resultSize);
}
else {
@@ -189,15 +191,15 @@ else if(jagged) {
lists.add(l);
}
}
- if(resultSize == null) {
+ if (resultSize == null) {
return new ArrayList<>();
}
return IntStream.range(0, resultSize)
.mapToObj(i -> {
List<Object> o = new ArrayList<>();
- for(List<Object> list : lists) {
- o.add( i < list.size() ? list.get(i): null);
+ for (List<Object> list : lists) {
+ o.add(i < list.size() ? list.get(i) : null);
}
return o;
})
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/HashFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/HashFunctions.java
index 660daf1e9b..cfa29e2808 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/HashFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/HashFunctions.java
@@ -75,6 +75,7 @@
public static class Hash extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(final List<Object> args) {
if (args == null || args.size() < 2) {
throw new IllegalArgumentException("Invalid number of arguments: " +
(args == null ? 0 : args.size()));
@@ -87,9 +88,9 @@ public Object apply(final List<Object> args) {
}
Map<String, Object> config = null;
- if(args.size() > 2) {
+ if (args.size() > 2) {
Object configObj = args.get(2);
- if(configObj instanceof Map && configObj != null) {
+ if (configObj instanceof Map && configObj != null) {
config = (Map<String, Object>)configObj;
}
}
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MapFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MapFunctions.java
index a8932a3f3b..34d442e3a4 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MapFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MapFunctions.java
@@ -63,6 +63,7 @@ public Object apply(List<Object> list) {
)
public static class MapGet extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> objects) {
Object keyObj = objects.get(0);
Object mapObj = objects.get(1);
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/OrdinalFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/OrdinalFunctions.java
index 6ac9ff515c..12ac3f81ea 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/OrdinalFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/OrdinalFunctions.java
@@ -22,8 +22,10 @@
import org.apache.metron.stellar.common.utils.ConversionUtils;
import org.apache.metron.stellar.dsl.BaseStellarFunction;
import org.apache.metron.stellar.dsl.Stellar;
+
import java.util.List;
import java.util.function.BiFunction;
+
import static org.apache.metron.stellar.common.utils.ConversionUtils.convert;
@@ -43,12 +45,13 @@
public static class Max extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
if (args.size() < 1 || args.get(0) == null) {
throw new IllegalStateException("MAX function requires at least one
argument");
}
Object firstArg = args.get(0);
- if(firstArg instanceof Ordinal) {
+ if (firstArg instanceof Ordinal) {
Ordinal stats = convert(firstArg, Ordinal.class);
return stats.getMax();
} else if (firstArg instanceof Iterable) {
@@ -62,27 +65,33 @@ public Object apply(List<Object> args) {
}
/**
- * Stellar Function: MIN
+ * Stellar Function: MIN.
+ *
* <p>
* Return the minimum value of a list of input values in a Stellar list
+ * </p>
*/
- @Stellar(name = "MIN"
- , description = "Returns the minimum value of a list of input values"
- , params = {"stats - The Stellar statistics object"
- ,"list - List of arguments. The list may only contain objects that
are mutually comparable / ordinal (implement java.lang.Comparable interface)" +
- " Multi type numeric comparisons are supported: MIN([10,15L,15.3])
would return 10, but MIN(['23',25]) will fail and return null as strings and
numbers can't be compared."}
- , returns = "The minimum value in the list or from stats, or null if
the list is empty or the input values were not comparable.")
+ @Stellar(name = "MIN",
+ description = "Returns the minimum value of a list of input values",
+ params = {"stats - The Stellar statistics object",
+ "list - List of arguments. The list may only contain objects
that are mutually comparable "
+ + "/ ordinal (implement java.lang.Comparable interface)"
+ + " Multi type numeric comparisons are supported:
MIN([10,15L,15.3]) would return 10,"
+ + "but MIN(['23',25]) will fail and return null as strings
and numbers can't be compared."},
+ returns = "The minimum value in the list or from stats, or null if
the list is empty or the input values"
+ + " were not comparable.")
public static class Min extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
if (args.size() < 1 || args.get(0) == null) {
throw new IllegalStateException("MIN function requires at least one
argument");
}
Object firstArg = args.get(0);
- if(firstArg instanceof Ordinal) {
+ if (firstArg instanceof Ordinal) {
Ordinal stats = convert(firstArg, Ordinal.class);
return stats.getMin();
- } else if (firstArg instanceof Iterable){
+ } else if (firstArg instanceof Iterable) {
Iterable<Comparable> list = (Iterable<Comparable>) args.get(0);
return orderList(list, (ret, val) -> ret.compareTo(val) > 0, "MIN");
} else {
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestConfig.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestConfig.java
index 62d89f762e..fdb69354c7 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestConfig.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestConfig.java
@@ -144,6 +144,7 @@ public Integer getSocketTimeout() {
return (Integer) get(SOCKET_TIMEOUT);
}
+ @SuppressWarnings("unchecked")
public List<Integer> getResponseCodesAllowed() {
return (List<Integer>) get(RESPONSE_CODES_ALLOWED);
}
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestFunctions.java
index 354322a497..f07d54e665 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestFunctions.java
@@ -263,6 +263,7 @@ protected Object doGet(RestConfig restConfig, HttpGet
httpGet, HttpClientContext
}
}
+ @SuppressWarnings("unchecked")
private Map<String, Object> getGlobalConfig(Context context) {
Optional<Object> globalCapability = context.getCapability(GLOBAL_CONFIG,
false);
return globalCapability.map(o -> (Map<String, Object>)
o).orElseGet(HashMap::new);
@@ -281,6 +282,7 @@ protected Object doGet(RestConfig restConfig, HttpGet
httpGet, HttpClientContext
* @return
* @throws IOException
*/
+ @SuppressWarnings("unchecked")
protected RestConfig getRestConfig(List<Object> args, Map<String, Object>
globalConfig) {
Map<String, Object> globalRestConfig = (Map<String, Object>)
globalConfig.get(STELLAR_REST_SETTINGS);
Map<String, Object> functionRestConfig = null;
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/SetFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/SetFunctions.java
index 72045ca970..87a3e3dcb5 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/SetFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/SetFunctions.java
@@ -21,7 +21,10 @@
import org.apache.metron.stellar.dsl.BaseStellarFunction;
import org.apache.metron.stellar.dsl.Stellar;
-import java.util.*;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
public class SetFunctions {
@Stellar(name="INIT"
@@ -32,15 +35,15 @@
)
public static class SetInit extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
LinkedHashSet<Object> ret = new LinkedHashSet<>();
- if(list.size() == 1) {
+ if (list.size() == 1) {
Object o = list.get(0);
- if(o != null) {
+ if (o != null) {
if (o instanceof Iterable) {
Iterables.addAll(ret, (Iterable) o);
- }
- else {
+ } else {
throw new IllegalArgumentException("Expected an Iterable, but " +
o + " is of type " + o.getClass());
}
}
@@ -50,25 +53,26 @@ public Object apply(List<Object> list) {
}
}
- @Stellar(name="ADD"
- , namespace="SET"
- , description="Adds to a set"
- , params = {"set - The set to add to"
- ,"o - object to add to set"
- }
- , returns = "A Set"
+ @Stellar(name = "ADD",
+ namespace = "SET",
+ description = "Adds to a set",
+ params = {"set - The set to add to",
+ "o - object to add to set"
+ },
+ returns = "A Set"
)
public static class SetAdd extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
- if(list.size() < 1) {
+ if (list.size() < 1) {
return null;
}
LinkedHashSet<Object> ret = (LinkedHashSet<Object>)list.get(0);
- if(ret == null) {
+ if (ret == null) {
ret = new LinkedHashSet<>();
}
- for(int i = 1;i < list.size();++i) {
+ for (int i = 1;i < list.size();++i) {
Object o = list.get(i);
if (o != null) {
ret.add(o);
@@ -88,15 +92,16 @@ public Object apply(List<Object> list) {
)
public static class SetRemove extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
- if(list.size() < 1) {
+ if (list.size() < 1) {
return null;
}
LinkedHashSet<Object> ret = (LinkedHashSet<Object>)list.get(0);
- if(ret == null) {
+ if (ret == null) {
ret = new LinkedHashSet<>();
}
- for(int i = 1;i < list.size();++i) {
+ for (int i = 1;i < list.size();++i) {
Object o = list.get(i);
if (o != null) {
ret.remove(o);
@@ -106,35 +111,30 @@ public Object apply(List<Object> list) {
}
}
- @Stellar(name="MERGE"
- , namespace="SET"
- , description="Merges a list of sets"
- , params = {"sets - A collection of sets to merge"
- }
- , returns = "A Set"
+ @Stellar(name = "MERGE",
+ namespace = "SET",
+ description = "Merges a list of sets",
+ params = {"sets - A collection of sets to merge"},
+ returns = "A Set"
)
public static class SetMerge extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
- if(list.size() < 1) {
+ if (list.size() < 1) {
return null;
}
LinkedHashSet<Object> ret = new LinkedHashSet<>();
- if(list.size() > 0) {
- Object o = list.get(0);
- if(o != null) {
- if(!(o instanceof Iterable)) {
- throw new IllegalArgumentException("Expected an Iterable, but " +
o + " is of type " + o.getClass());
- }
- Iterable<? extends Iterable> sets = (Iterable<? extends Iterable>) o;
+ Object o = list.get(0);
+ if (o != null) {
+ if (!(o instanceof Iterable)) {
+ throw new IllegalArgumentException("Expected an Iterable, but " + o
+ " is of type " + o.getClass());
+ }
+ Iterable<? extends Iterable> sets = (Iterable<? extends Iterable>) o;
- for (Iterable s : sets) {
- if (s != null) {
- if(!(s instanceof Iterable)) {
- throw new IllegalArgumentException("Expected an Iterable, but
" + s + " is of type " + s.getClass());
- }
- Iterables.addAll(ret, s);
- }
+ for (Iterable s : sets) {
+ if (s != null) {
+ Iterables.addAll(ret, s);
}
}
}
@@ -142,11 +142,11 @@ public Object apply(List<Object> list) {
}
}
- @Stellar(name="INIT"
- , namespace="MULTISET"
- , description="Creates an empty multiset, which is a map associating
objects to their instance counts."
- , params = { "input (optional) - An initialization of the multiset"}
- , returns = "A multiset"
+ @Stellar(name = "INIT",
+ namespace = "MULTISET",
+ description = "Creates an empty multiset, which is a map
associating objects to their instance counts.",
+ params = { "input (optional) - An initialization of the multiset"},
+ returns = "A multiset"
)
public static class MultiSetInit extends BaseStellarFunction {
@Override
@@ -177,15 +177,16 @@ public Object apply(List<Object> list) {
)
public static class MultiSetAdd extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
- if(list.size() < 1) {
+ if (list.size() < 1) {
return null;
}
LinkedHashMap<Object, Integer> ret = (LinkedHashMap<Object,
Integer>)list.get(0);
- if(ret == null) {
+ if (ret == null) {
ret = new LinkedHashMap<>();
}
- for(int i = 1;i < list.size();++i) {
+ for (int i = 1;i < list.size();++i) {
Object o = list.get(i);
if (o != null) {
ret.merge(o, 1, (k, one) -> k + one);
@@ -195,35 +196,35 @@ public Object apply(List<Object> list) {
}
}
- @Stellar(name="REMOVE"
- , namespace="MULTISET"
- , description="Removes from a multiset, which is a map associating
objects to their instance counts."
- , params = {"set - The multiset to add to"
- ,"o - object to remove from multiset"
- }
- , returns = "A multiset"
+ @Stellar(name = "REMOVE",
+ namespace = "MULTISET",
+ description = "Removes from a multiset, which is a map associating
objects to their instance counts.",
+ params = {"set - The multiset to add to",
+ "o - object to remove from multiset"
+ },
+ returns = "A multiset"
)
public static class MultiSetRemove extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
if(list.size() < 1) {
return null;
}
LinkedHashMap<Object, Integer> ret = (LinkedHashMap<Object,
Integer>)list.get(0);
- if(ret == null) {
+ if (ret == null) {
ret = new LinkedHashMap<>();
}
- for(int i = 1;i < list.size();++i) {
+ for (int i = 1;i < list.size();++i) {
Object o = list.get(i);
if (o != null) {
Integer cnt = ret.get(o);
- if(cnt == null) {
+ if (cnt == null) {
continue;
}
- if(cnt == 1) {
+ if (cnt == 1) {
ret.remove(o);
- }
- else {
+ } else {
ret.put(o, cnt - 1);
}
}
@@ -232,27 +233,25 @@ public Object apply(List<Object> list) {
}
}
- @Stellar(name="MERGE"
- , namespace="MULTISET"
- , description="Merges a list of multisets, which is a map
associating objects to their instance counts."
- , params = {"sets - A collection of multisets to merge"
- }
- , returns = "A multiset"
+ @Stellar(name = "MERGE",
+ namespace = "MULTISET",
+ description = "Merges a list of multisets, which is a map
associating objects to their instance counts.",
+ params = {"sets - A collection of multisets to merge"},
+ returns = "A multiset"
)
public static class MultiSetMerge extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
- if(list.size() < 1) {
+ if (list.size() < 1) {
return null;
}
LinkedHashMap<Object, Integer> ret = new LinkedHashMap<>();
- if(list.size() > 0) {
- Iterable<Map<Object, Integer>> maps = (Iterable<Map<Object,
Integer>>)list.get(0);
- for(Map<Object, Integer> s : maps) {
- if(s != null) {
- for (Map.Entry<Object, Integer> kv : s.entrySet()) {
- ret.merge(kv.getKey(), kv.getValue(), (k, cnt) -> k + cnt);
- }
+ Iterable<Map<Object, Integer>> maps = (Iterable<Map<Object, Integer>>)
list.get(0);
+ for (Map<Object, Integer> s : maps) {
+ if (s != null) {
+ for (Map.Entry<Object, Integer> kv : s.entrySet()) {
+ ret.merge(kv.getKey(), kv.getValue(), (k, cnt) -> k + cnt);
}
}
}
@@ -270,14 +269,15 @@ public Object apply(List<Object> list) {
)
public static class MultiSetToSet extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> list) {
- if(list.size() < 1) {
+ if (list.size() < 1) {
return null;
}
LinkedHashSet<Object> ret = new LinkedHashSet<>();
- if(list.size() == 1) {
+ if (list.size() == 1) {
Map<Object, Integer> multiset = (Map<Object, Integer>)list.get(0);
- if(multiset != null) {
+ if (multiset != null) {
ret.addAll(multiset.keySet());
}
}
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/ShellFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/ShellFunctions.java
index 1df4a51c5f..5eddfa8736 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/ShellFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/ShellFunctions.java
@@ -26,6 +26,8 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.invoke.MethodHandles;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -243,7 +245,7 @@ public Object apply(List<Object> args, Context context)
throws ParseException {
outFile = File.createTempFile("stellar_shell", "out");
if (args.size() > 0) {
String arg = (String) args.get(0);
- try (PrintWriter pw = new PrintWriter(outFile)) {
+ try (PrintWriter pw = new
PrintWriter(outFile,StandardCharsets.UTF_8.name())) {
IOUtils.write(arg, pw);
}
}
@@ -264,9 +266,8 @@ public Object apply(List<Object> args, Context context)
throws ParseException {
Process p = processBuilder.start();
// wait for termination.
p.waitFor();
- try (BufferedReader br = new BufferedReader(new
FileReader(outFile))) {
- String ret = IOUtils.toString(br).trim();
- return ret;
+ try (BufferedReader br = Files.newBufferedReader(outFile.toPath(),
StandardCharsets.UTF_8)) {
+ return IOUtils.toString(br).trim();
}
} catch (Exception e) {
String message = "Unable to read output: " + e.getMessage();
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java
index 2865ea745d..50198525c6 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java
@@ -139,6 +139,7 @@ public Object apply(List<Object> strings) {
)
public static class JoinFunction extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
List<Object> arg1 = (List<Object>) args.get(0);
String delim = (String) args.get(1);
@@ -153,10 +154,11 @@ public Object apply(List<Object> args) {
)
public static class SplitFunction extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
List ret = new ArrayList();
Object o1 = args.get(0);
- if(o1 != null) {
+ if (o1 != null) {
String arg1 = o1.toString();
String delim = (String) args.get(1);
Iterables.addAll(ret, Splitter.on(delim).split(arg1));
@@ -165,43 +167,46 @@ public Object apply(List<Object> args) {
}
}
- @Stellar(name="GET_LAST"
- , description="Returns the last element of the list"
- , params = { "input - List"}
- , returns = "Last element of the list"
+ @Stellar(name = "GET_LAST",
+ description = "Returns the last element of the list",
+ params = { "input - List"},
+ returns = "Last element of the list"
)
public static class GetLast extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
List<Object> arg1 = (List<Object>) args.get(0);
return Iterables.getLast(arg1, null);
}
}
- @Stellar(name="GET_FIRST"
- , description="Returns the first element of the list"
- , params = { "input - List"}
- , returns = "First element of the list"
+ @Stellar(name = "GET_FIRST",
+ description = "Returns the first element of the list",
+ params = { "input - List"},
+ returns = "First element of the list"
)
public static class GetFirst extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
List<Object> arg1 = (List<Object>) args.get(0);
return Iterables.getFirst(arg1, null);
}
}
- @Stellar(name="GET"
- , description="Returns the i'th element of the list "
- , params = { "input - List", "i - The index (0-based)"}
- , returns = "First element of the list"
+ @Stellar(name = "GET",
+ description = "Returns the i'th element of the list ",
+ params = { "input - List", "i - The index (0-based)"},
+ returns = "First element of the list"
)
public static class Get extends BaseStellarFunction {
@Override
+ @SuppressWarnings("unchecked")
public Object apply(List<Object> args) {
List<Object> arg1 = (List<Object>) args.get(0);
int offset = (Integer) args.get(1);
- if(offset < arg1.size()) {
+ if (offset < arg1.size()) {
return Iterables.get(arg1, offset);
}
return null;
diff --git
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/resolver/ClasspathFunctionResolver.java
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/resolver/ClasspathFunctionResolver.java
index 7b7500962c..7a87f4d194 100644
---
a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/resolver/ClasspathFunctionResolver.java
+++
b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/resolver/ClasspathFunctionResolver.java
@@ -173,9 +173,10 @@ public void exclude(String... toExclude) {
}
@Override
+ @SuppressWarnings("unchecked")
public void initialize(Context context) {
super.initialize(context);
- if(context != null) {
+ if (context != null) {
Optional<Object> optional = context.getCapability(STELLAR_CONFIG, false);
if (optional.isPresent()) {
@@ -189,7 +190,7 @@ public void initialize(Context context) {
Optional<ClassLoader> vfsLoader = Optional.empty();
try {
vfsLoader =
VFSClassloaderUtil.configureClassloader(STELLAR_VFS_PATHS.get(stellarConfig,
String.class));
- if(vfsLoader.isPresent()) {
+ if (vfsLoader.isPresent()) {
LOG.debug("CLASSLOADER LOADED WITH: {}",
STELLAR_VFS_PATHS.get(stellarConfig, String.class));
if(LOG.isDebugEnabled()) {
for (FileObject fo : ((VFSClassLoader)
vfsLoader.get()).getFileObjects()) {
@@ -201,10 +202,9 @@ public void initialize(Context context) {
} catch (FileSystemException e) {
LOG.error("Unable to process filesystem: {}", e.getMessage(), e);
}
- }
- else {
+ } else {
LOG.info("No stellar config set; I'm reverting to the context
classpath with no restrictions.");
- if(LOG.isDebugEnabled()) {
+ if (LOG.isDebugEnabled()) {
try {
throw new IllegalStateException("No config set, stacktrace
follows.");
} catch (IllegalStateException ise) {
@@ -212,8 +212,7 @@ public void initialize(Context context) {
}
}
}
- }
- else {
+ } else {
throw new IllegalStateException("CONTEXT IS NULL!");
}
}
@@ -234,6 +233,7 @@ protected boolean includeClass(Class<?> c, FilterBuilder
filterBuilder)
* (aka discovery) of Stellar functions.
*/
@Override
+ @SuppressWarnings("unchecked")
public Set<Class<? extends StellarFunction>> resolvables() {
ClassLoader[] cls = null;
@@ -253,24 +253,24 @@ protected boolean includeClass(Class<?> c, FilterBuilder
filterBuilder)
i, this.classLoaders.size(), this.classLoaders);
}
}
- cls = classLoaderList.toArray(new ClassLoader[classLoaderList.size()]);
+ cls = classLoaderList.toArray(new ClassLoader[0]);
}
FilterBuilder filterBuilder = new FilterBuilder();
excludes.forEach(excl -> {
- if(excl != null) {
+ if (excl != null) {
filterBuilder.exclude(excl);
}
});
includes.forEach(incl -> {
- if(incl != null) {
+ if (incl != null) {
filterBuilder.include(incl);
}
});
Set<String> classes = new HashSet<>();
Set<Class<? extends StellarFunction>> ret = new HashSet<>();
- for(ClassLoader cl : cls) {
- for(Class<?> c : getStellarClasses(cl)) {
+ for (ClassLoader cl : cls) {
+ for (Class<?> c : getStellarClasses(cl)) {
try {
LOG.debug("{}: Found class: {}", cl.getClass().getCanonicalName(),
c.getCanonicalName());
if (includeClass(c, filterBuilder)) {
@@ -281,15 +281,13 @@ protected boolean includeClass(Class<?> c, FilterBuilder
filterBuilder)
classes.add(className);
}
}
- }
- catch(Error le) {
+ } catch (Error le) {
//we have had some error loading a stellar function. This could
mean that
//the classpath is unstable (e.g. old copies of jars are on the
classpath).
try {
LOG.error("Skipping class " + c.getName() + ": " + le.getMessage()
+ ", please check that there are not old versions of
stellar functions on the classpath.", le);
- }
- catch(Error ie) {
+ } catch (Error ie) {
//it's possible that getName() will throw an exception if the
class is VERY malformed.
LOG.error("Skipping class: " + le.getMessage()
+ ", please check that there are not old versions of
stellar functions on the classpath.", le);
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/StellarCompilerTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/StellarCompilerTest.java
index f10ee5c80c..e0230c67ef 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/StellarCompilerTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/StellarCompilerTest.java
@@ -70,6 +70,7 @@ public void setUp() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void exitIntLiteralShouldProperlyParseStringsAsIntegers() throws
Exception {
StellarParser.IntLiteralContext ctx =
mock(StellarParser.IntLiteralContext.class);
Token result = mock(Token.class);
@@ -87,6 +88,7 @@ public void
exitIntLiteralShouldProperlyParseStringsAsIntegers() throws Exceptio
}
@Test
+ @SuppressWarnings("unchecked")
public void exitDoubleLiteralShouldProperlyParseStringsAsDoubles() throws
Exception {
StellarParser.DoubleLiteralContext ctx =
mock(StellarParser.DoubleLiteralContext.class);
Token result = mock(Token.class);
@@ -106,6 +108,7 @@ public void
exitDoubleLiteralShouldProperlyParseStringsAsDoubles() throws Except
}
@Test
+ @SuppressWarnings("unchecked")
public void exitFloatLiteralShouldProperlyParseStringsAsFloats() throws
Exception {
StellarParser.FloatLiteralContext ctx =
mock(StellarParser.FloatLiteralContext.class);
when(ctx.getText()).thenReturn("1000f");
@@ -125,6 +128,7 @@ public void
exitFloatLiteralShouldProperlyParseStringsAsFloats() throws Exceptio
}
@Test
+ @SuppressWarnings("unchecked")
public void exitLongLiteralShouldProperlyParseStringsAsLongs() throws
Exception {
StellarParser.LongLiteralContext ctx =
mock(StellarParser.LongLiteralContext.class);
when(ctx.getText()).thenReturn("1000l");
@@ -144,6 +148,7 @@ public void
exitLongLiteralShouldProperlyParseStringsAsLongs() throws Exception
}
@Test
+ @SuppressWarnings("unchecked")
public void properlyCompareTwoNumbers() throws Exception {
StellarParser.ComparisonExpressionWithOperatorContext ctx =
mock(StellarParser.ComparisonExpressionWithOperatorContext.class);
StellarParser.ComparisonOpContext mockOp =
mock(StellarParser.ComparisonOpContext.class);
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/evaluators/ComparisonOperatorsEvaluatorTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/evaluators/ComparisonOperatorsEvaluatorTest.java
index 8afc234951..29da1ed896 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/evaluators/ComparisonOperatorsEvaluatorTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/evaluators/ComparisonOperatorsEvaluatorTest.java
@@ -46,6 +46,7 @@ public void setUp() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void nonSupportedOperatorThrowsExceptionNonNumbericComparable()
throws Exception {
Token<String> left = mock(Token.class);
when(left.getValue()).thenReturn("b");
@@ -62,6 +63,7 @@ public void
nonSupportedOperatorThrowsExceptionNonNumbericComparable() throws Ex
}
@Test
+ @SuppressWarnings("unchecked")
public void nonSupportedOperatorThrowsExceptionNumbericComparison() throws
Exception {
Token<Long> left = mock(Token.class);
when(left.getValue()).thenReturn(1L);
@@ -78,6 +80,7 @@ public void
nonSupportedOperatorThrowsExceptionNumbericComparison() throws Excep
}
@Test
+ @SuppressWarnings("unchecked")
public void leftIsNullThenThrowException() throws Exception {
Token<Long> left = mock(Token.class);
Token<Long> right = mock(Token.class);
@@ -90,6 +93,7 @@ public void leftIsNullThenThrowException() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void rightIsNullThenReturnFalse() throws Exception {
Token<Long> left = mock(Token.class);
when(left.getValue()).thenReturn(1L);
@@ -102,6 +106,7 @@ public void rightIsNullThenReturnFalse() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void rightAndLeftIsNullThenReturnFalse() throws Exception {
Token<Long> left = mock(Token.class);
Token<Long> right = mock(Token.class);
@@ -113,6 +118,7 @@ public void rightAndLeftIsNullThenReturnFalse() throws
Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void throwParseExceptionWhenTryingToCompareNonComparable() throws
Exception {
exception.expect(ParseException.class);
exception.expectMessage("Unsupported operations. The following expression
is invalid: ");
@@ -130,6 +136,7 @@ public void
throwParseExceptionWhenTryingToCompareNonComparable() throws Excepti
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsProperlyWorkForLongs() throws Exception {
Token<Long> left = mock(Token.class);
when(left.getValue()).thenReturn(0L);
@@ -160,6 +167,7 @@ public void makeSureAllOperatorsProperlyWorkForLongs()
throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsProperlyWorkForDoubles() throws Exception {
Token<Double> left = mock(Token.class);
when(left.getValue()).thenReturn(0D);
@@ -190,6 +198,7 @@ public void makeSureAllOperatorsProperlyWorkForDoubles()
throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsProperlyWorkForFloats() throws Exception {
Token<Float> left = mock(Token.class);
when(left.getValue()).thenReturn(0F);
@@ -220,6 +229,7 @@ public void makeSureAllOperatorsProperlyWorkForFloats()
throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsProperlyWorkForInts() throws Exception {
Token<Integer> left = mock(Token.class);
when(left.getValue()).thenReturn(0);
@@ -250,6 +260,7 @@ public void makeSureAllOperatorsProperlyWorkForInts()
throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsWorkForMixedTypesDoublesLong() throws
Exception {
Token<Long> left = mock(Token.class);
when(left.getValue()).thenReturn(1L);
@@ -280,6 +291,7 @@ public void
makeSureAllOperatorsWorkForMixedTypesDoublesLong() throws Exception
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsWorkForMixedTypesDoublesFloat() throws
Exception {
final double leftValue = 1.0000001D;
final float rightValue = 1.0000001F;
@@ -313,6 +325,7 @@ public void
makeSureAllOperatorsWorkForMixedTypesDoublesFloat() throws Exception
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsWorkForMixedTypesFloatIntegers() throws
Exception {
final int leftValue = 1;
final float rightValue = 1.0000001F;
@@ -346,6 +359,7 @@ public void
makeSureAllOperatorsWorkForMixedTypesFloatIntegers() throws Exceptio
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsWorkForMixedTypesFloatIntegers2() throws
Exception {
final int leftValue = 1;
final float rightValue = 1.00000001F;
@@ -379,6 +393,7 @@ public void
makeSureAllOperatorsWorkForMixedTypesFloatIntegers2() throws Excepti
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsWorkForMixedTypesLongIntegers() throws
Exception {
final int leftValue = 1;
final long rightValue = 3L;
@@ -412,6 +427,7 @@ public void
makeSureAllOperatorsWorkForMixedTypesLongIntegers() throws Exception
}
@Test
+ @SuppressWarnings("unchecked")
public void makeSureAllOperatorsWorkForNonIntegerComparableTypes() throws
Exception {
final String leftValue = "a";
final String rightValue = "b";
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/BloomFilterTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/BloomFilterTest.java
index f8636d769c..2e56510832 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/BloomFilterTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/BloomFilterTest.java
@@ -38,6 +38,7 @@
}};
@Test
+ @SuppressWarnings("unchecked")
public void testMerge() {
BloomFilter bloomString = (BloomFilter)run("BLOOM_ADD(BLOOM_INIT(),
string)", variables);
@@ -58,6 +59,7 @@ public void testMerge() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testAdd() {
BloomFilter result = (BloomFilter)run("BLOOM_ADD(BLOOM_INIT(), string,
double, integer, map)", variables);
for(Object val : variables.values()) {
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/JSONUtilsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/JSONUtilsTest.java
index e28bfb7fce..214d0782e4 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/JSONUtilsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/JSONUtilsTest.java
@@ -58,6 +58,7 @@ public void loads_file_with_typeref() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void loads_file_with_map_class() throws Exception {
Map<String, Object> expected = new HashMap<String, Object>() {{
put("a", "hello");
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/SerDeUtilsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/SerDeUtilsTest.java
index dc5c9ee89b..f3b6eb545c 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/SerDeUtilsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/common/utils/SerDeUtilsTest.java
@@ -122,6 +122,7 @@ public void testList() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testBloomFilter() {
final BloomFilter<Object> expected = new BloomFilter<>(new
BloomFilter.DefaultSerializer<>(), 10000, 0.01);
expected.add("foo");
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/BasicStellarTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/BasicStellarTest.java
index 97cb9709d4..a6a41e5aca 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/BasicStellarTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/BasicStellarTest.java
@@ -229,6 +229,7 @@ public void testVariablesUsed() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testConditionalsAsMapKeys() {
{
String query = "{ ( RET_TRUE() && y < 50 ) : 'info', y >= 50 : 'warn'}";
@@ -556,6 +557,7 @@ public void testIfThenElse() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testInNotIN(){
HashMap variables = new HashMap<>();
boolean thrown = false;
@@ -1036,6 +1038,7 @@ public void non_boolean_predicate_throws_exception() {
}
@Test
+ @SuppressWarnings("unchecked")
public void all_fields_test() {
final Map<String, Object> varMap1 = new HashMap<String, Object>();
varMap1.put("field1", "val1");
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/DataStructureFunctionsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/DataStructureFunctionsTest.java
index 735b8036a5..f9b08291c1 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/DataStructureFunctionsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/DataStructureFunctionsTest.java
@@ -66,6 +66,7 @@ public void is_empty_handles_empty_values() {
}
@Test
+ @SuppressWarnings("unchecked")
public void listAdd_number() {
for(String expr : ImmutableList.of("LIST_ADD(my_list, 1)"
,"LIST_ADD([], 1)"
@@ -82,6 +83,7 @@ public void listAdd_number() {
}
@Test
+ @SuppressWarnings("unchecked")
public void listAdd_mixed() {
for(String expr : ImmutableList.of("LIST_ADD(my_list, 1)"
,"LIST_ADD(['foo'], 1)"
@@ -101,6 +103,7 @@ public void listAdd_mixed() {
}
@Test
+ @SuppressWarnings("unchecked")
public void listAdd_number_nonempty() {
for(String expr : ImmutableList.of("LIST_ADD(my_list, 2)"
,"LIST_ADD([1], 2)"
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/EncodingFunctionsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/EncodingFunctionsTest.java
index 6dc4c3965e..417db4fbed 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/EncodingFunctionsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/EncodingFunctionsTest.java
@@ -53,6 +53,7 @@
}};
@Test
+ @SuppressWarnings("unchecked")
public void testSupportedEncodingsList() throws Exception{
Object ret = run("GET_SUPPORTED_ENCODINGS()", new HashMap());
Assert.assertTrue(ret instanceof List );
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/FunctionalFunctionsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/FunctionalFunctionsTest.java
index c93e4a1122..e32a5cfefd 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/FunctionalFunctionsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/FunctionalFunctionsTest.java
@@ -34,6 +34,7 @@
public class FunctionalFunctionsTest {
@Test
+ @SuppressWarnings("unchecked")
public void testZipLongest_boundary() {
for (String expr : ImmutableList.of( "ZIP_LONGEST()"
, "ZIP_LONGEST( null, null )"
@@ -49,6 +50,7 @@ public void testZipLongest_boundary() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testZip_longest() {
Map<String, Object> variables = ImmutableMap.of(
"list1" , ImmutableList.of(1, 2, 3)
@@ -107,6 +109,7 @@ public void testZip_longest() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testZip_boundary() {
for (String expr : ImmutableList.of( "ZIP()"
, "ZIP( null, null )"
@@ -122,6 +125,7 @@ public void testZip_boundary() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testZip() {
Map<String, Object> variables = ImmutableMap.of(
"list1" , ImmutableList.of(1, 2, 3)
@@ -172,6 +176,7 @@ public void testZip() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testRecursive() {
for (String expr : ImmutableList.of( "MAP(list, inner_list ->
REDUCE(inner_list, (x, y) -> x + y, 0) )"
, "MAP(list, (inner_list) ->
REDUCE(inner_list, (x, y) -> x + y, 0) )"
@@ -188,6 +193,7 @@ public void testRecursive() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testMap_null() {
for (String expr : ImmutableList.of( "MAP([ 1, 2, null], x -> if x == null
then 0 else 2*x )"
, "MAP([ 1, 2, null], x -> x == null ?
0 : 2*x )"
@@ -212,6 +218,7 @@ public void testMap_null() {
@Test
+ @SuppressWarnings("unchecked")
public void testMap() {
for (String expr : ImmutableList.of( "MAP([ 'foo', 'bar'], (x) ->
TO_UPPER(x) )"
, "MAP([ foo, 'bar'], (x) ->
TO_UPPER(x) )"
@@ -233,6 +240,7 @@ public void testMap() {
@Test
+ @SuppressWarnings("unchecked")
public void testMap_conditional() {
for (String expr : ImmutableList.of("MAP([ 'foo', 'bar'], (item) -> item
== 'foo' )"
,"MAP([ foo, bar], (item) -> item ==
'foo' )"
@@ -251,6 +259,7 @@ public void testMap_conditional() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testFilter() {
for (String expr : ImmutableList.of("FILTER([ 'foo', 'bar'], (item) ->
item == 'foo' )"
,"FILTER([ 'foo', bar], (item) -> item
== 'foo' )"
@@ -271,6 +280,7 @@ public void testFilter() {
@Test
+ @SuppressWarnings("unchecked")
public void testFilter_shortcircuit() {
for (String expr : ImmutableList.of("FILTER([ 'foo'], item -> item ==
'foo' or THROW('exception') )"
,"FILTER([ 'foo'], (item) -> item ==
'foo' or THROW('exception') )"
@@ -286,6 +296,7 @@ public void testFilter_shortcircuit() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testFilter_null() {
for (String expr : ImmutableList.of("FILTER([ 'foo', null], item -> item
== null )"
,"FILTER([ 'foo', baz], (item) -> item
== null )"
@@ -306,6 +317,7 @@ public void testFilter_null() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testFilter_notnull() {
for (String expr : ImmutableList.of("FILTER([ 'foo', null], item -> item
!= null )"
,"FILTER([ 'foo', baz], (item) -> item
!= null )"
@@ -327,6 +339,7 @@ public void testFilter_notnull() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testFilter_none() {
for (String expr : ImmutableList.of( "FILTER([ foo, bar], () -> false )"
, "FILTER([ 'foo', 'bar'], (item)->
false )"
@@ -345,6 +358,7 @@ public void testFilter_none() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testFilter_all() {
for (String expr : ImmutableList.of("FILTER([ 'foo', 'bar'], (item) ->
true )"
,"FILTER([ 'foo', bar], (item) -> true
)"
@@ -397,6 +411,7 @@ public void testReduce() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testReduce_on_various_list_sizes() {
{
String expr = "REDUCE([ 1, 2, 3, 4 ], (x, y) -> x + y , 0 )";
@@ -422,6 +437,7 @@ public void testReduce_on_various_list_sizes() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testReduce_NonNumeric() {
for (String expr : ImmutableList.of("REDUCE([ 'foo', 'bar', 'grok'], (x,
y) -> LIST_ADD(x, y), [] )"
)
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/HashFunctionsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/HashFunctionsTest.java
index e0ba2415ba..6cea13c925 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/HashFunctionsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/HashFunctionsTest.java
@@ -220,6 +220,7 @@ public void tlsh_happyPath() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void tlsh_multiBin() throws Exception {
final Map<String, Object> variables = new HashMap<>();
@@ -266,6 +267,7 @@ public void tlsh_multithread() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void tlsh_similarity() throws Exception {
for(Map.Entry<String, String> kv : ImmutableMap.of("been", "ben",
"document", "dokumant", "code", "cad").entrySet()) {
Map<String, Object> variables = ImmutableMap.of("toHash", TLSH_DATA,
"toHashSimilar", TLSH_DATA.replace(kv.getKey(), kv.getValue()));
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/MatchTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/MatchTest.java
index d6986cc481..f6ab20d146 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/MatchTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/MatchTest.java
@@ -325,6 +325,7 @@ public void testVariableIFCheck() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testIfThenElseAction() {
Assert.assertEquals(2,run("match{ foo == true => IF bar THEN 1 ELSE 2,
default => 0}", new HashMap(){{
put("foo",true);
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RestFunctionsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RestFunctionsTest.java
index 4b912efb63..70f7d2f8ee 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RestFunctionsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RestFunctionsTest.java
@@ -122,6 +122,7 @@ public void setup() throws Exception {
* The REST_GET function should perform a get request and parse the results.
*/
@Test
+ @SuppressWarnings("unchecked")
public void restGetShouldSucceed() throws Exception {
Map<String, Object> actual = (Map<String, Object>)
run(String.format("REST_GET('%s')", getUri), context);
@@ -133,6 +134,7 @@ public void restGetShouldSucceed() throws Exception {
* The REST_GET function should perform a get request using a proxy and
parse the results.
*/
@Test
+ @SuppressWarnings("unchecked")
public void restGetShouldSucceedWithProxy() {
mockServerClient.when(
request()
@@ -494,6 +496,7 @@ public void restGetShouldGetHttpClientContext() throws
Exception {
* The REST_GET function should timeout and return null.
*/
@Test
+ @SuppressWarnings("unchecked")
public void restGetShouldTimeout() {
String uri = String.format("http://localhost:%d/get",
mockServerRule.getPort());
@@ -528,6 +531,7 @@ public void restGetShouldTimeout() {
* The REST_GET function should honor the function supplied timeout setting.
*/
@Test
+ @SuppressWarnings("unchecked")
public void restGetShouldTimeoutWithSuppliedTimeout() {
String expression = String.format("REST_GET('%s', %s)", getUri,
timeoutConfig);
Map<String, Object> actual = (Map<String, Object>) run(expression,
context);
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/SetFunctionsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/SetFunctionsTest.java
index 1aa8eb4191..00a045ccb6 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/SetFunctionsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/SetFunctionsTest.java
@@ -30,11 +30,13 @@
public class SetFunctionsTest {
@Test(expected=ParseException.class)
+ @SuppressWarnings("unchecked")
public void multisetInitTest_wrongType() throws Exception {
Map<Object, Integer> s = (Map<Object, Integer>)
StellarProcessorUtils.run("MULTISET_INIT({ 'foo' : 'bar'})", new HashMap<>());
}
@Test
+ @SuppressWarnings("unchecked")
public void multisetInitTest() throws Exception {
{
Map<Object, Integer> s = (Map<Object, Integer>)
StellarProcessorUtils.run("MULTISET_INIT()", new HashMap<>());
@@ -66,6 +68,7 @@ public void multisetInitTest() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void multisetAddTest() throws Exception {
{
Map<Object, Integer> s = (Map<Object, Integer>)
StellarProcessorUtils.run("MULTISET_ADD(MULTISET_INIT(), 1)", new HashMap<>());
@@ -107,6 +110,7 @@ public void multisetAddTest() throws Exception {
}
}
@Test
+@SuppressWarnings("unchecked")
public void multisetRemoveTest() throws Exception {
{
Map<Object, Integer> s = (Map<Object, Integer>)
StellarProcessorUtils.run("MULTISET_REMOVE(MULTISET_INIT([1]), 1)", new
HashMap<>());
@@ -141,12 +145,14 @@ public void multisetRemoveTest() throws Exception {
}
@Test(expected=ParseException.class)
+ @SuppressWarnings("unchecked")
public void multisetMergeTest_wrongType() throws Exception {
Map<Object, Integer> s = (Map<Object, Integer>)
StellarProcessorUtils.run("MULTISET_MERGE({ 'bar' : 'foo' } )", new
HashMap<>());
}
@Test
+ @SuppressWarnings("unchecked")
public void multisetMergeTest() throws Exception {
{
Map<Object, Integer> s = (Map<Object, Integer>)
StellarProcessorUtils.run("MULTISET_MERGE([MULTISET_INIT(),
MULTISET_INIT(null), null])", new HashMap<>());
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/ShellFunctionsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/ShellFunctionsTest.java
index 354e0c3259..126a9742cc 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/ShellFunctionsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/ShellFunctionsTest.java
@@ -135,6 +135,7 @@ public void testMap2TableInsufficientArgs() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testVars2Map() {
Object out = run("SHELL_VARS2MAP('var1', 'var2')", new HashMap<>(),
context);
Assert.assertTrue(out instanceof Map);
@@ -145,6 +146,7 @@ public void testVars2Map() {
}
@Test
+ @SuppressWarnings("unchecked")
public void testVars2MapEmpty() {
Object out = run("SHELL_VARS2MAP()", new HashMap<>(), context);
Map<String, String> mapOut = (Map<String, String>)out;
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/StringFunctionsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/StringFunctionsTest.java
index 9f78fe1afa..75625705ab 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/StringFunctionsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/StringFunctionsTest.java
@@ -70,6 +70,7 @@ public void testStringFunctions_advanced() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void testLeftRightFills() throws Exception {
final Map<String, Object> variableMap = new HashMap<String, Object>() {{
put("foo", null);
@@ -225,6 +226,7 @@ public void testFormatWithMissingArguments() throws
Exception {
* @throws Exception
*/
@Test
+ @SuppressWarnings("unchecked")
public void testChomp() throws Exception {
Assert.assertEquals("abc", run("CHOMP('abc')", new HashedMap()));
Assert.assertEquals("abc", run("CHOMP(msg)", ImmutableMap.of("msg",
"abc\r\n")));
@@ -268,6 +270,7 @@ public void testChomp() throws Exception {
* @throws Exception
*/
@Test
+ @SuppressWarnings("unchecked")
public void testChop() throws Exception {
Assert.assertEquals("ab", run("CHOP('abc')", new HashedMap()));
Assert.assertEquals(null, run("CHOP(null)", new HashedMap()));
@@ -310,6 +313,7 @@ public void testChop() throws Exception {
* PREPEND_IF_MISSING StringFunction
*/
@Test
+ @SuppressWarnings("unchecked")
public void testPrependIfMissing() throws Exception {
Assert.assertEquals("xyzabc", run("PREPEND_IF_MISSING('abc', 'xyz')",
new HashedMap()));
Assert.assertEquals("xyzXYZabc", run("PREPEND_IF_MISSING('XYZabc', 'xyz',
'mno')", new HashedMap()));
@@ -363,6 +367,7 @@ public void testPrependIfMissing() throws Exception {
* APPEND_IF_MISSING StringFunction
*/
@Test
+ @SuppressWarnings("unchecked")
public void testAppendIfMissing() throws Exception {
Assert.assertEquals("apachemetron", run("APPEND_IF_MISSING('apache',
'metron')", new HashedMap()));
Assert.assertEquals("abcXYZxyz", run("APPEND_IF_MISSING('abcXYZ',
'xyz', 'mno')", new HashedMap()));
@@ -450,6 +455,7 @@ public void testSubstring_invalidWrongTypeInput() throws
Exception {
* COUNT_MATCHES StringFunction
*/
@Test
+ @SuppressWarnings("unchecked")
public void testCountMatches() throws Exception {
Assert.assertEquals(0, (int) run("COUNT_MATCHES(null, '*')", new
HashedMap()));
Assert.assertEquals(2, (int) run("COUNT_MATCHES('apachemetron', 'e')", new
HashedMap()));
@@ -536,6 +542,7 @@ public void testCountMatches() throws Exception {
private String string5;
@Test
+ @SuppressWarnings("unchecked")
public void testToJsonObject() throws Exception {
//JSON Object
Object ret1 = run("TO_JSON_OBJECT(msg)", ImmutableMap.of("msg", string1));
@@ -674,6 +681,7 @@ public void testToJsonMap() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
public void testToJsonList() throws Exception {
//Simple Arrays
Object ret3 = run("TO_JSON_LIST(msg)", ImmutableMap.of("msg", string3));
diff --git
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/TextFunctionsTest.java
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/TextFunctionsTest.java
index 07b3619d44..d95cf6693d 100644
---
a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/TextFunctionsTest.java
+++
b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/TextFunctionsTest.java
@@ -38,6 +38,7 @@
}};
@Test
+ @SuppressWarnings("unchecked")
public void testGetAvailableLanguageTags() {
Object ret = run("FUZZY_LANGS()", new HashMap<>());
Assert.assertNotNull(ret);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services