lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [15/50] [abbrv] lucene-solr:jira/solr-11072: SOLR-11145, SOLR-11146: Added comprehensive unit tests for Analytics Component 2.0 as well as analytics bug fixes.
Date Thu, 19 Oct 2017 08:31:03 GMT
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java
b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java
new file mode 100644
index 0000000..3286a15
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/CastingStringValueTest.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.solr.analytics.value;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream.ExpressionType;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.constant.ConstantStringValue;
+import org.junit.Test;
+
+public class CastingStringValueTest extends SolrTestCaseJ4 {
+
+  @Test
+  public void objectCastingTest() {
+    TestStringValue val = new TestStringValue();
+    
+    assertTrue(val instanceof AnalyticsValue);
+    AnalyticsValue casted = (AnalyticsValue)val;
+
+    val.setValue("string 1").setExists(true);
+    assertEquals("string 1", casted.getObject());
+    assertTrue(casted.exists());
+
+    val.setValue("abc").setExists(true);
+    assertEquals("abc", casted.getObject());
+    assertTrue(casted.exists());
+  }
+
+  @Test
+  public void stringStreamCastingTest() {
+    TestStringValue val = new TestStringValue();
+    
+    assertTrue(val instanceof StringValueStream);
+    StringValueStream casted = (StringValueStream)val;
+    
+    // No values
+    val.setExists(false);
+    casted.streamStrings( value -> {
+      assertTrue("There should be no values to stream", false);
+    });
+
+    // Multiple Values
+    val.setValue("abcd").setExists(true);
+    Iterator<String> values = Arrays.asList("abcd").iterator();
+    casted.streamStrings( value -> {
+      assertTrue(values.hasNext());
+      assertEquals(values.next(), value);
+    });
+    assertFalse(values.hasNext());
+  }
+
+  @Test
+  public void objectStreamCastingTest() {
+    TestStringValue val = new TestStringValue();
+    
+    assertTrue(val instanceof AnalyticsValueStream);
+    AnalyticsValueStream casted = (AnalyticsValueStream)val;
+    
+    // No values
+    val.setExists(false);
+    casted.streamObjects( value -> {
+      assertTrue("There should be no values to stream", false);
+    });
+
+    // Multiple Values
+    val.setValue("abcd").setExists(true);
+    Iterator<Object> values = Arrays.<Object>asList("abcd").iterator();
+    casted.streamObjects( value -> {
+      assertTrue(values.hasNext());
+      assertEquals(values.next(), value);
+    });
+    assertFalse(values.hasNext());
+  }
+  
+  @Test
+  public void constantConversionTest() {
+    TestStringValue val = new TestStringValue(ExpressionType.CONST);
+    val.setValue("asd23n23").setExists(true);
+    AnalyticsValueStream conv = val.convertToConstant();
+    assertTrue(conv instanceof ConstantStringValue);
+    assertEquals("asd23n23", ((ConstantStringValue)conv).getString());
+
+    val = new TestStringValue(ExpressionType.FIELD);
+    val.setValue("asd23n23").setExists(true);
+    conv = val.convertToConstant();
+    assertSame(val, conv);
+
+    val = new TestStringValue(ExpressionType.UNREDUCED_MAPPING);
+    val.setValue("asd23n23").setExists(true);
+    conv = val.convertToConstant();
+    assertSame(val, conv);
+
+    val = new TestStringValue(ExpressionType.REDUCTION);
+    val.setValue("asd23n23").setExists(true);
+    conv = val.convertToConstant();
+    assertSame(val, conv);
+
+    val = new TestStringValue(ExpressionType.REDUCED_MAPPING);
+    val.setValue("asd23n23").setExists(true);
+    conv = val.convertToConstant();
+    assertSame(val, conv);
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java
b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java
new file mode 100644
index 0000000..bcdf7da
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/ConstantValueTest.java
@@ -0,0 +1,368 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.solr.analytics.value;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Date;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.constant.ConstantBooleanValue;
+import org.apache.solr.analytics.value.constant.ConstantDateValue;
+import org.apache.solr.analytics.value.constant.ConstantDoubleValue;
+import org.apache.solr.analytics.value.constant.ConstantFloatValue;
+import org.apache.solr.analytics.value.constant.ConstantIntValue;
+import org.apache.solr.analytics.value.constant.ConstantLongValue;
+import org.apache.solr.analytics.value.constant.ConstantStringValue;
+import org.apache.solr.analytics.value.constant.ConstantValue;
+import org.junit.Test;
+
+public class ConstantValueTest extends SolrTestCaseJ4 {
+  
+
+  @Test
+  public void constantParsingTest() throws DateTimeParseException {
+    // Int
+    AnalyticsValueStream uncasted = ConstantValue.creatorFunction.apply("1234");
+    assertTrue(uncasted instanceof ConstantIntValue);
+    assertEquals(1234, ((ConstantIntValue)uncasted).getInt());
+
+    // Long
+    uncasted = ConstantValue.creatorFunction.apply("1234123412341234");
+    assertTrue(uncasted instanceof ConstantLongValue);
+    assertEquals(1234123412341234L, ((ConstantLongValue)uncasted).getLong());
+
+    // Floats cannot currently be implicitly created
+
+    // Double
+    uncasted = ConstantValue.creatorFunction.apply("12341234.12341234");
+    assertTrue(uncasted instanceof ConstantDoubleValue);
+    assertEquals(12341234.12341234, ((ConstantDoubleValue)uncasted).getDouble(), .000000001);
+
+    // String
+    uncasted = ConstantValue.creatorFunction.apply("'abcdef'");
+    assertTrue(uncasted instanceof ConstantStringValue);
+    assertEquals("abcdef", ((ConstantStringValue)uncasted).getString());
+    
+    uncasted = ConstantValue.creatorFunction.apply("\"abcdef\"");
+    assertTrue(uncasted instanceof ConstantStringValue);
+    assertEquals("abcdef", ((ConstantStringValue)uncasted).getString());
+
+    // Date
+    uncasted = ConstantValue.creatorFunction.apply("1800-01-01T10:30:15.33Z");
+    assertTrue(uncasted instanceof ConstantDateValue);
+    assertEquals(Date.from(Instant.parse("1800-01-01T10:30:15.33Z")), ((ConstantDateValue)uncasted).getDate());
+  }
+  
+  @Test
+  public void constantConversionTest() {
+    AnalyticsValueStream val = new ConstantBooleanValue(true);
+    assertSame(val, val.convertToConstant());
+
+    val = new ConstantIntValue(123);
+    assertSame(val, val.convertToConstant());
+
+    val = new ConstantLongValue(123L);
+    assertSame(val, val.convertToConstant());
+
+    val = new ConstantFloatValue(123F);
+    assertSame(val, val.convertToConstant());
+
+    val = new ConstantDoubleValue(123.0);
+    assertSame(val, val.convertToConstant());
+
+    val = new ConstantDateValue(123L);
+    assertSame(val, val.convertToConstant());
+
+    val = new ConstantStringValue("123");
+    assertSame(val, val.convertToConstant());
+  }
+
+  @Test
+  public void constantBooleanTest() {
+    ConstantBooleanValue val = new ConstantBooleanValue(true);
+    
+    assertTrue(val.exists());
+    assertEquals(true, val.getBoolean());
+    assertEquals("true", val.getString());
+    assertEquals(new Boolean(true), val.getObject());
+    
+    TestIntValue counter = new TestIntValue();
+    counter.setValue(0);
+    val.streamBooleans( value -> {
+      assertEquals(true, value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamStrings( value -> {
+      assertEquals("true", value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamObjects( value -> {
+      assertEquals(new Boolean(true), value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    
+
+    val = new ConstantBooleanValue(false);
+    
+    assertTrue(val.exists());
+    assertEquals(false, val.getBoolean());
+    assertEquals("false", val.getString());
+    assertEquals(new Boolean(false), val.getObject());
+    
+    counter.setValue(0);
+    val.streamBooleans( value -> {
+      assertEquals(false, value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamStrings( value -> {
+      assertEquals("false", value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamObjects( value -> {
+      assertEquals(new Boolean(false), value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+  }
+
+  @Test
+  public void constantIntTest() {
+    ConstantIntValue val = new ConstantIntValue(24);
+    
+    assertTrue(val.exists());
+    assertEquals(24, val.getInt());
+    assertEquals(24L, val.getLong());
+    assertEquals(24F, val.getFloat(), .00001);
+    assertEquals(24.0, val.getDouble(), .00001);
+    assertEquals("24", val.getString());
+    assertEquals(new Integer(24), val.getObject());
+    
+    TestIntValue counter = new TestIntValue();
+    counter.setValue(0);
+    val.streamInts( value -> {
+      assertEquals(24, value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamLongs( value -> {
+      assertEquals(24L, value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamFloats( value -> {
+      assertEquals(24F, value, .00001);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamDoubles( value -> {
+      assertEquals(24.0, value, .00001);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamStrings( value -> {
+      assertEquals("24", value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamObjects( value -> {
+      assertEquals(new Integer(24), value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+  }
+
+  @Test
+  public void constantLongTest() {
+    ConstantLongValue val = new ConstantLongValue(24L);
+    
+    assertTrue(val.exists());
+    assertEquals(24L, val.getLong());
+    assertEquals(24.0, val.getDouble(), .00001);
+    assertEquals("24", val.getString());
+    assertEquals(new Long(24L), val.getObject());
+    
+    TestIntValue counter = new TestIntValue();
+    counter.setValue(0);
+    val.streamLongs( value -> {
+      assertEquals(24L, value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamDoubles( value -> {
+      assertEquals(24.0, value, .00001);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamStrings( value -> {
+      assertEquals("24", value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamObjects( value -> {
+      assertEquals(new Long(24L), value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+  }
+
+  @Test
+  public void constantFloatTest() {
+    ConstantFloatValue val = new ConstantFloatValue(24F);
+    
+    assertTrue(val.exists());
+    assertEquals(24F, val.getFloat(), .00001);
+    assertEquals(24.0, val.getDouble(), .00001);
+    assertEquals("24.0", val.getString());
+    assertEquals(new Float(24F), val.getObject());
+    
+    TestIntValue counter = new TestIntValue();
+    counter.setValue(0);
+    val.streamFloats( value -> {
+      assertEquals(24F, value, .00001);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamDoubles( value -> {
+      assertEquals(24.0, value, .00001);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamStrings( value -> {
+      assertEquals("24.0", value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamObjects( value -> {
+      assertEquals(new Float(24F), value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+  }
+
+  @Test
+  public void constantDoubleTest() {
+    ConstantDoubleValue val = new ConstantDoubleValue(24.0);
+    
+    assertTrue(val.exists());
+    assertEquals(24.0, val.getDouble(), .00001);
+    assertEquals("24.0", val.getString());
+    assertEquals(new Double(24.0), val.getObject());
+    
+    TestIntValue counter = new TestIntValue();
+    counter.setValue(0);
+    val.streamDoubles( value -> {
+      assertEquals(24.0, value, .00001);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamStrings( value -> {
+      assertEquals("24.0", value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamObjects( value -> {
+      assertEquals(new Double(24.0), value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+  }
+
+  @Test
+  public void constantDateTest() throws DateTimeParseException {
+    Date date = Date.from(Instant.parse("1800-01-01T10:30:15Z"));
+    ConstantDateValue val = new ConstantDateValue(date.getTime());
+    
+    assertTrue(val.exists());
+    assertEquals(date.getTime(), val.getLong());
+    assertEquals(date, val.getDate());
+    assertEquals("1800-01-01T10:30:15Z", val.getString());
+    assertEquals(date, val.getObject());
+    
+    TestIntValue counter = new TestIntValue();
+    counter.setValue(0);
+    val.streamLongs( value -> {
+      assertEquals(date.getTime(), value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamDates( value -> {
+      assertEquals(date, value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamStrings( value -> {
+      assertEquals("1800-01-01T10:30:15Z", value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamObjects( value -> {
+      assertEquals(date, value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+  }
+
+  @Test
+  public void constantStringTest() {
+    ConstantStringValue val = new ConstantStringValue("abcdef");
+    
+    assertTrue(val.exists());
+    assertEquals("abcdef", val.getString());
+    assertEquals("abcdef", val.getObject());
+    
+    TestIntValue counter = new TestIntValue();
+    counter.setValue(0);
+    val.streamStrings( value -> {
+      assertEquals("abcdef", value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+    counter.setValue(0);
+    val.streamObjects( value -> {
+      assertEquals("abcdef", value);
+      assertEquals(0, counter.getInt());
+      counter.setValue(1);
+    });
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java
b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java
new file mode 100644
index 0000000..7facef9
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/value/FillableTestValue.java
@@ -0,0 +1,641 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.solr.analytics.value;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
+import java.util.function.IntConsumer;
+import java.util.function.LongConsumer;
+
+import org.apache.solr.analytics.util.function.BooleanConsumer;
+import org.apache.solr.analytics.util.function.FloatConsumer;
+import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
+import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;
+import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
+import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
+import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
+import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
+import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream.AbstractDoubleValueStream;
+import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;
+import org.apache.solr.analytics.value.FloatValueStream.AbstractFloatValueStream;
+import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
+import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
+import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
+import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
+import org.apache.solr.analytics.value.StringValue.AbstractStringValue;
+import org.apache.solr.analytics.value.StringValueStream.AbstractStringValueStream;
+
+public class FillableTestValue {
+  public static class TestAnalyticsValue extends AbstractAnalyticsValue {
+    private final ExpressionType expressionType;
+    
+    private Object value;
+    private boolean exists;
+    
+    public TestAnalyticsValue() {
+      this(ExpressionType.CONST);
+    }
+    
+    public TestAnalyticsValue(ExpressionType expressionType) {
+      this.expressionType = expressionType;
+    }
+
+    public TestAnalyticsValue setValue(Object value) {
+      this.value = value;
+      return this;
+    }
+    
+    public TestAnalyticsValue setExists(boolean exists) {
+      this.exists = exists;
+      return this;
+    }
+
+    @Override
+    public Object getObject() {
+      return value;
+    }
+
+    @Override
+    public boolean exists() {
+      return exists;
+    }
+
+    @Override
+    public String getName() { return "test_analytics_value"; }
+
+    @Override
+    public String getExpressionStr() { return "test_analytics_value"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return expressionType; }
+  }
+  
+  public static class TestAnalyticsValueStream extends AbstractAnalyticsValueStream {
+    private final ExpressionType expressionType;
+    
+    private Object[] values;
+    
+    public TestAnalyticsValueStream() {
+      this(ExpressionType.CONST);
+    }
+    
+    public TestAnalyticsValueStream(ExpressionType expressionType) {
+      this.expressionType = expressionType;
+    }
+
+    public TestAnalyticsValueStream setValues(Object... values) {
+      this.values = values;
+      return this;
+    }
+
+    @Override
+    public void streamObjects(Consumer<Object> cons) {
+      for (int i = 0; i < values.length; ++i) {
+        cons.accept(values[i]);
+      }
+    }
+
+    @Override
+    public String getName() { return "test_analytics_value_stream"; }
+
+    @Override
+    public String getExpressionStr() { return "test_analytics_value_stream"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return expressionType; }
+  }
+  
+  public static class TestIntValue extends AbstractIntValue {
+    private final ExpressionType expressionType;
+    
+    private int value;
+    private boolean exists;
+    
+    public TestIntValue() {
+      this(ExpressionType.CONST);
+    }
+    
+    public TestIntValue(ExpressionType expressionType) {
+      this.expressionType = expressionType;
+    }
+
+    public TestIntValue setValue(int value) {
+      this.value = value;
+      return this;
+    }
+    
+    public TestIntValue setExists(boolean exists) {
+      this.exists = exists;
+      return this;
+    }
+
+    @Override
+    public int getInt() {
+      return value;
+    }
+
+    @Override
+    public boolean exists() {
+      return exists;
+    }
+
+    @Override
+    public String getName() { return "test_int_value"; }
+
+    @Override
+    public String getExpressionStr() { return "test_int_value"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return expressionType; }
+  }
+  
+  public static class TestIntValueStream extends AbstractIntValueStream {
+    private int[] values;
+    
+    public TestIntValueStream() {
+      this.values = new int[0];
+    }
+
+    public TestIntValueStream setValues(int... values) {
+      this.values = values;
+      return this;
+    }
+
+    @Override
+    public void streamInts(IntConsumer cons) {
+      for (int i = 0; i < values.length; ++i) {
+        cons.accept(values[i]);
+      }
+    }
+
+    @Override
+    public String getName() { return "test_int_value_stream"; }
+
+    @Override
+    public String getExpressionStr() { return "test_int_value_stream"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING;
}
+  }
+
+  public static class TestLongValue extends AbstractLongValue {
+    private final ExpressionType expressionType;
+    
+    private long value;
+    private boolean exists;
+    
+    public TestLongValue() {
+      this(ExpressionType.CONST);
+    }
+    
+    public TestLongValue(ExpressionType expressionType) {
+      this.expressionType = expressionType;
+    }
+
+    public TestLongValue setValue(long value) {
+      this.value = value;
+      return this;
+    }
+    
+    public TestLongValue setExists(boolean exists) {
+      this.exists = exists;
+      return this;
+    }
+
+    @Override
+    public long getLong() {
+      return value;
+    }
+
+    @Override
+    public boolean exists() {
+      return exists;
+    }
+
+    @Override
+    public String getName() { return "test_long_value"; }
+
+    @Override
+    public String getExpressionStr() { return "test_long_value"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return expressionType; }
+  }
+
+  public static class TestLongValueStream extends AbstractLongValueStream {
+    private long[] values;
+    
+    public TestLongValueStream() {
+      this.values = new long[0];
+    }
+
+    public TestLongValueStream setValues(long... values) {
+      this.values = values;
+      return this;
+    }
+
+    @Override
+    public void streamLongs(LongConsumer cons) {
+      for (int i = 0; i < values.length; ++i) {
+        cons.accept(values[i]);
+      }
+    }
+
+    @Override
+    public String getName() { return "test_long_value_stream"; }
+
+    @Override
+    public String getExpressionStr() { return "test_long_value_stream"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING;
}
+  }
+
+  public static class TestFloatValue extends AbstractFloatValue {
+    private final ExpressionType expressionType;
+    
+    private float value;
+    private boolean exists;
+    
+    public TestFloatValue() {
+      this(ExpressionType.CONST);
+    }
+    
+    public TestFloatValue(ExpressionType expressionType) {
+      this.expressionType = expressionType;
+    }
+
+    public TestFloatValue setValue(float value) {
+      this.value = value;
+      return this;
+    }
+    
+    public TestFloatValue setExists(boolean exists) {
+      this.exists = exists;
+      return this;
+    }
+
+    @Override
+    public float getFloat() {
+      return value;
+    }
+
+    @Override
+    public boolean exists() {
+      return exists;
+    }
+
+    @Override
+    public String getName() { return "test_float_value"; }
+
+    @Override
+    public String getExpressionStr() { return "test_float_value"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return expressionType; }
+  }
+  
+  public static class TestFloatValueStream extends AbstractFloatValueStream {
+    private float[] values;
+    
+    public TestFloatValueStream() {
+      this.values = new float[0];
+    }
+
+    public TestFloatValueStream setValues(float... values) {
+      this.values = values;
+      return this;
+    }
+
+    @Override
+    public void streamFloats(FloatConsumer cons) {
+      for (int i = 0; i < values.length; ++i) {
+        cons.accept(values[i]);
+      }
+    }
+
+    @Override
+    public String getName() { return "test_float_value_stream"; }
+
+    @Override
+    public String getExpressionStr() { return "test_float_value_stream"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING;
}
+  }
+
+  public static class TestDoubleValue extends AbstractDoubleValue {
+    private final ExpressionType expressionType;
+    
+    private double value;
+    private boolean exists;
+    
+    public TestDoubleValue() {
+      this(ExpressionType.CONST);
+    }
+    
+    public TestDoubleValue(ExpressionType expressionType) {
+      this.expressionType = expressionType;
+    }
+
+    public TestDoubleValue setValue(double value) {
+      this.value = value;
+      return this;
+    }
+    
+    public TestDoubleValue setExists(boolean exists) {
+      this.exists = exists;
+      return this;
+    }
+
+    @Override
+    public double getDouble() {
+      return value;
+    }
+
+    @Override
+    public boolean exists() {
+      return exists;
+    }
+
+    @Override
+    public String getName() { return "test_double_value"; }
+
+    @Override
+    public String getExpressionStr() { return "test_double_value"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return expressionType; }
+  }
+  
+  public static class TestDoubleValueStream extends AbstractDoubleValueStream {
+    private double[] values;
+    
+    public TestDoubleValueStream() {
+      this.values = new double[0];
+    }
+
+    public TestDoubleValueStream setValues(double... values) {
+      this.values = values;
+      return this;
+    }
+
+    @Override
+    public void streamDoubles(DoubleConsumer cons) {
+      for (int i = 0; i < values.length; ++i) {
+        cons.accept(values[i]);
+      }
+    }
+
+    @Override
+    public String getName() { return "test_double_value_stream"; }
+
+    @Override
+    public String getExpressionStr() { return "test_double_value_stream"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING;
}
+  }
+
+  public static class TestBooleanValue extends AbstractBooleanValue {
+    private final ExpressionType expressionType;
+    
+    private boolean value;
+    private boolean exists;
+    
+    public TestBooleanValue() {
+      this(ExpressionType.CONST);
+    }
+    
+    public TestBooleanValue(ExpressionType expressionType) {
+      this.expressionType = expressionType;
+    }
+
+    public TestBooleanValue setValue(boolean value) {
+      this.value = value;
+      return this;
+    }
+    
+    public TestBooleanValue setExists(boolean exists) {
+      this.exists = exists;
+      return this;
+    }
+
+    @Override
+    public boolean getBoolean() {
+      return value;
+    }
+
+    @Override
+    public boolean exists() {
+      return exists;
+    }
+
+    @Override
+    public String getName() { return "test_boolean_value"; }
+
+    @Override
+    public String getExpressionStr() { return "test_boolean_value"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return expressionType; }
+  }
+
+  public static class TestBooleanValueStream extends AbstractBooleanValueStream {
+    private boolean[] values;
+    
+    public TestBooleanValueStream() {
+      this.values = new boolean[0];
+    }
+
+    public TestBooleanValueStream setValues(boolean... values) {
+      this.values = values;
+      return this;
+    }
+
+    @Override
+    public void streamBooleans(BooleanConsumer cons) {
+      for (int i = 0; i < values.length; ++i) {
+        cons.accept(values[i]);
+      }
+    }
+
+    @Override
+    public String getName() { return "test_boolean_value_stream"; }
+
+    @Override
+    public String getExpressionStr() { return "test_boolean_value_stream"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING;
}
+  }
+
+  public static class TestDateValue extends AbstractDateValue {
+    private final ExpressionType expressionType;
+    
+    private long value;
+    private boolean exists;
+    
+    public TestDateValue() {
+      this(ExpressionType.CONST);
+    }
+    
+    public TestDateValue(ExpressionType expressionType) {
+      this.expressionType = expressionType;
+    }
+
+    public TestDateValue setValue(String value) {
+      try {
+        this.value = Instant.parse(value).toEpochMilli();
+      } catch (DateTimeParseException e) {
+        this.value = 0;
+      }
+      return this;
+    }
+    
+    public TestDateValue setExists(boolean exists) {
+      this.exists = exists;
+      return this;
+    }
+
+    @Override
+    public long getLong() {
+      return value;
+    }
+
+    @Override
+    public boolean exists() {
+      return exists;
+    }
+
+    @Override
+    public String getName() { return "test_date_value"; }
+
+    @Override
+    public String getExpressionStr() { return "test_date_value"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return expressionType; }
+  }
+
+  public static class TestDateValueStream extends AbstractDateValueStream {
+    private String[] values;
+    
+    public TestDateValueStream() {
+      this.values = new String[0];
+    }
+
+    public TestDateValueStream setValues(String... values) {
+      this.values = values;
+      return this;
+    }
+
+    @Override
+    public void streamLongs(LongConsumer cons) {
+      for (int i = 0; i < values.length; ++i) {
+        try {
+          cons.accept(Instant.parse(values[i]).toEpochMilli());
+        } catch (DateTimeParseException e) { }
+      }
+    }
+
+    @Override
+    public String getName() { return "test_date_value_stream"; }
+
+    @Override
+    public String getExpressionStr() { return "test_date_value_stream"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING;
}
+  }
+
+  public static class TestStringValue extends AbstractStringValue {
+    private final ExpressionType expressionType;
+    
+    private String value;
+    private boolean exists;
+    
+    public TestStringValue() {
+      this(ExpressionType.CONST);
+    }
+    
+    public TestStringValue(ExpressionType expressionType) {
+      this.expressionType = expressionType;
+    }
+
+    public TestStringValue setValue(String value) {
+      this.value = value;
+      return this;
+    }
+    
+    public TestStringValue setExists(boolean exists) {
+      this.exists = exists;
+      return this;
+    }
+
+    @Override
+    public String getString() {
+      return value;
+    }
+
+    @Override
+    public boolean exists() {
+      return exists;
+    }
+
+    @Override
+    public String getName() { return "test_string_value"; }
+
+    @Override
+    public String getExpressionStr() { return "test_string_value"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return expressionType; }
+  }
+
+  public static class TestStringValueStream extends AbstractStringValueStream {
+    private String[] values;
+    
+    public TestStringValueStream() {
+      this.values = new String[0];
+    }
+
+    public TestStringValueStream setValues(String... values) {
+      this.values = values;
+      return this;
+    }
+
+    @Override
+    public void streamStrings(Consumer<String> cons) {
+      for (int i = 0; i < values.length; ++i) {
+        cons.accept(values[i]);
+      }
+    }
+
+    @Override
+    public String getName() { return "test_string_value_stream"; }
+
+    @Override
+    public String getExpressionStr() { return "test_string_value_stream"; }
+
+    @Override
+    public ExpressionType getExpressionType() { return ExpressionType.UNREDUCED_MAPPING;
}
+  }
+}


Mime
View raw message