Package com.google.visualization.datasource.datatable.value

Examples of com.google.visualization.datasource.datatable.value.TextValue


  /**
   * Test string aggregation.
   */
  public void testStringAggregation() {
    ValueAggregator aggregator = new ValueAggregator(ValueType.TEXT);
    aggregator.aggregate(new TextValue("a"));
    aggregator.aggregate(new TextValue("b"));

    try {
      aggregator.getValue(AggregationType.SUM);
      fail();
    } catch (UnsupportedOperationException e) {
      // Expected behavior.
    }
    try {
      aggregator.getValue(AggregationType.AVG);
      fail();
    } catch (UnsupportedOperationException e) {
      // Expected behavior.
    }

    assertEquals(new NumberValue(2), aggregator.getValue(AggregationType.COUNT));
    assertEquals(new TextValue("a"), aggregator.getValue(AggregationType.MIN));
    assertEquals(new TextValue("b"), aggregator.getValue(AggregationType.MAX));

  }
View Full Code Here


    assertEquals("60.0", tableAggregator.getAggregationValue(
        generatePath(new String[]{"1994"}), "Sales",
        AggregationType.SUM).toString());

    Assert.assertEquals(new TextValue("Youthanasia"), tableAggregator.
        getAggregationValue(generatePath(new String[]{}), "Band",
        AggregationType.MAX));
  }
View Full Code Here

    tree.aggregate(createPath(new String[] {"Bla", "3", "5"}),
        AggregationNodeTest.createValueMap(new String[]{"B", "50"}));
    tree.aggregate(createPath(new String[]{"4"}),
        AggregationNodeTest.createValueMap(new String[]{"C", "10"}));

    Assert.assertEquals(new TextValue("A"),
        tree.getNode(createPath(new String[] {}))
        .getAggregationValue("Band", AggregationType.MIN));

    assertEquals("75.0", tree.getNode(createPath(
        new String[] {"Bla", "3"})).getAggregationValue(
View Full Code Here

   */
  public void testAggregation() {
    AggregationNode node = newAggregationNode();
    node.aggregate(createValueMap(new String[]{"A", "100"}));
    node.aggregate(createValueMap(new String[]{"B", "50"}));
    assertEquals(new TextValue("B"), node.getAggregationValue(
        "Band", AggregationType.MAX));
    assertEquals("75.0", node.getAggregationValue(
        "Sales", AggregationType.AVG).toString());
  }
View Full Code Here

    input.addColumn(new ColumnDescription("isPig", ValueType.BOOLEAN, "label2"));

    TableRow row;

    row = new TableRow();
    row.addCell(new TableCell(new TextValue("aaa")));
    row.addCell(new TableCell(new NumberValue(222)));
    row.addCell(new TableCell(BooleanValue.TRUE, "T"));
    input.addRow(row);

    row = new TableRow();
    row.addCell(new TableCell(new TextValue("ccc")));
    row.addCell(new TableCell(new NumberValue(111)));
    row.addCell(new TableCell(BooleanValue.TRUE, "T"));
    input.addRow(row);

    row = new TableRow();
    row.addCell(new TableCell(new TextValue("bbb")));
    row.addCell(new TableCell(new NumberValue(333)));
    row.addCell(new TableCell(BooleanValue.FALSE, "F"));
    input.addRow(row);
  }
View Full Code Here

            TimeComponentExtractor.TimeComponent.HOUR)));
    q.setSelection(selection);

    //Add filter.
    QueryFilter filter = new ColumnValueFilter(new SimpleColumn("name"),
        new TextValue("name"), ComparisonFilter.Operator.EQ);
    q.setFilter(filter);

    //Add group.
    QueryGroup group = new QueryGroup();
    group.addColumn(new SimpleColumn("hireDate"));
View Full Code Here

    // Null TableDescription.
    reader = new StringReader("\n\n\n1,2,3\n\n4,5,6\n\n\n\n\n");
    dataTable = CsvDataSourceHelper.read(reader, null, false);
    assertEquals(2, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new TextValue("1"), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("2"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new TextValue("3"), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("5"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new TextValue("6"), dataTable.getRow(1).getCell(2).getValue());

    // Different column numbers.
    boolean catched = false;
    try {
      reader = new StringReader("1,2\na, b, c");
      dataTable = CsvDataSourceHelper.read(reader, null, false);
    } catch (CsvDataSourceException e) {
      catched = true;
      assertEquals(ReasonType.INTERNAL_ERROR, e.getReasonType());
      assertEquals(
          "Wrong number of columns in the data.",
          e.getMessageToUser());
    }
    assertTrue(catched);

    // Working example with a table description filled only with types.
    reader = new StringReader("1,a,true\n4,x13a,false\n1400,4,true");
    List<ColumnDescription> columnDescriptions = Lists.newArrayList();
    columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));
    columnDescriptions.add(new ColumnDescription("i3", ValueType.DATE, null));
    dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
    assertEquals(3, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(1), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("a"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(DateValue.getNullValue(), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new NumberValue(4), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("x13a"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(DateValue.getNullValue(), dataTable.getRow(1).getCell(2).getValue());
    assertEquals(new NumberValue(1400), dataTable.getRow(2).getCell(0).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(2).getCell(1).getValue());
    assertEquals(DateValue.getNullValue(), dataTable.getRow(2).getCell(2).getValue());

    // Working example with a table description filled only with types.
    reader = new StringReader("1,a,2004-03-01\n4,x13a,2005-04-02\n1400,4,2006-05-03");
    columnDescriptions = Lists.newArrayList();
    columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));
    columnDescriptions.add(new ColumnDescription("i3", ValueType.DATE, null));
    dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
    assertEquals(3, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(1), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("a"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new DateValue(2004, 2, 1), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new NumberValue(4), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("x13a"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new DateValue(2005, 3, 2), dataTable.getRow(1).getCell(2).getValue());
    assertEquals(new NumberValue(1400), dataTable.getRow(2).getCell(0).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(2).getCell(1).getValue());
    assertEquals(new DateValue(2006, 4, 3), dataTable.getRow(2).getCell(2).getValue());
    assertEquals("i1", dataTable.getColumnDescription(0).getId());
    assertEquals("Column0", dataTable.getColumnDescription(0).getLabel());
    assertEquals("i2", dataTable.getColumnDescription(1).getId());
    assertEquals("Column1", dataTable.getColumnDescription(1).getLabel());
    assertEquals("i3", dataTable.getColumnDescription(2).getId());
    assertEquals("Column2", dataTable.getColumnDescription(2).getLabel());

    // Working example with header rows.
    reader = new StringReader("1,a,2004-03-01\n4,x13a,2005-04-02\n1400,4,2006-05-03");
    columnDescriptions = Lists.newArrayList();
    columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));
    columnDescriptions.add(new ColumnDescription("i3", ValueType.DATE, null));
    dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
    assertEquals(2, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(4), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("x13a"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new DateValue(2005, 3, 2), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new NumberValue(1400), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new DateValue(2006, 4, 3), dataTable.getRow(1).getCell(2).getValue());
    assertEquals("i1", dataTable.getColumnDescription(0).getId());
    assertEquals("1",  dataTable.getColumnDescription(0).getLabel());
    assertEquals("i2", dataTable.getColumnDescription(1).getId());
    assertEquals("a", dataTable.getColumnDescription(1).getLabel());
    assertEquals("i3", dataTable.getColumnDescription(2).getId());
    assertEquals("2004-03-01", dataTable.getColumnDescription(2).getLabel());

    // Bad table description for that data.
    catched = false;
    try {
      reader = new StringReader("true\nfalse\nfalse");
      columnDescriptions = Lists.newArrayList();
      dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
    } catch (CsvDataSourceException e) {
      catched = true;
      assertEquals(ReasonType.INTERNAL_ERROR, e.getReasonType());
      assertEquals(
          "Wrong number of columns in the data.",
          e.getMessageToUser());
    }
    assertTrue(catched);

    // Working example with a null table description.
    reader = new StringReader("true,false\ntrue,false\ntrue,false\nfalse,false");
    columnDescriptions = null;
    dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
    assertEquals(4, dataTable.getNumberOfRows());
    assertEquals(2, dataTable.getNumberOfColumns());
    assertEquals(new TextValue("true"), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new TextValue("true"), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new TextValue("true"), dataTable.getRow(2).getCell(0).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(2).getCell(1).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(3).getCell(0).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(3).getCell(1).getValue());

    // Working example with a table description filled with types.
    reader = new StringReader("true,false\ntrue,false\ntrue,false\nfalse,false");
    columnDescriptions = Lists.newArrayList();
    columnDescriptions.add(new ColumnDescription("1", ValueType.BOOLEAN, "123"));
View Full Code Here

   
    DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
    assertEquals(2, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(4), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("x13a"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new DateValue(2005, 3, 2), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new NumberValue(1400), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new DateValue(2006, 4, 3), dataTable.getRow(1).getCell(2).getValue());
    assertEquals("i1", dataTable.getColumnDescription(0).getId());
    assertEquals("1",  dataTable.getColumnDescription(0).getLabel());
    assertEquals("i2", dataTable.getColumnDescription(1).getId());
    assertEquals("a", dataTable.getColumnDescription(1).getLabel());
View Full Code Here

    QueryFilter queryFilter1 = new ColumnColumnFilter(new SimpleColumn("ID"),
        new SimpleColumn("Salary"), ComparisonFilter.Operator.EQ);
    QueryFilter queryFilter2 = new ColumnValueFilter(new SimpleColumn("ID"),
        new NumberValue(1), ComparisonFilter.Operator.GE);
    QueryFilter queryFilter3 = new ColumnValueFilter(new SimpleColumn("Fname"),
        new TextValue("Mi"), ComparisonFilter.Operator.STARTS_WITH);
    QueryFilter queryFilter4 = new ColumnValueFilter(new SimpleColumn("Lname"),
        new TextValue("SH"), ComparisonFilter.Operator.CONTAINS);
     QueryFilter queryFilter5 = new ColumnValueFilter(new SimpleColumn("Lname"),
        new TextValue("tz"), ComparisonFilter.Operator.ENDS_WITH);
    List<QueryFilter> subFiltersList1 = Lists.newArrayList();
    subFiltersList1.add(queryFilter1);
    subFiltersList1.add(queryFilter2);
    QueryFilter queryCompoundFilter1 =
        new CompoundFilter(CompoundFilter.LogicalOperator.AND, subFiltersList1);
View Full Code Here

    // null value, check that the value equals to the null value format of the
    // specific type value.
    assertEquals(new NumberValue(100.0),
        dataTable.getRow(0).getCell(0).getValue());
    assertEquals("Yaron", dataTable.getRow(0).getCell(1).getValue().toString());
    assertEquals(new TextValue(""), dataTable.getRow(0).getCell(2).getValue());
    assertEquals("Bar", dataTable.getRow(1).getCell(2).getValue().toString());
    assertEquals("F", dataTable.getRow(1).getCell(3).getValue().toString());
    assertEquals(BooleanValue.getNullValue(),
        dataTable.getRow(1).getCell(5).getValue());
    assertEquals(NumberValue.getNullValue(),
View Full Code Here

TOP

Related Classes of com.google.visualization.datasource.datatable.value.TextValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.