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

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


  }

  public void testGetValueFromEmptyAggregation() {
    ValueAggregator aggregator = new ValueAggregator(ValueType.DATE);
    DateValue dateNull = DateValue.getNullValue();
    NumberValue numberNull = NumberValue.getNullValue();

    assertEquals(new NumberValue(0), aggregator.getValue(AggregationType.COUNT));

    assertEquals(dateNull, aggregator.getValue(AggregationType.MIN));
View Full Code Here


    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());
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());
    assertEquals("i3", dataTable.getColumnDescription(2).getId());
View Full Code Here

        dataTable.getRow(1).getCell(5).getValue());
    assertEquals(NumberValue.getNullValue(),
        dataTable.getRow(2).getCell(4).getValue());
    assertEquals("true", dataTable.getRow(2).getCell(5).getValue().toString());
    assertEquals(dataTable.getRow(0).getCell(6).getValue().toString(),
        new DateValue(gc), dataTable.getRow(0).getCell(6).getValue());
    assertEquals(new DateTimeValue(gc),
        dataTable.getRow(0).getCell(7).getValue());
    assertEquals(new TimeOfDayValue(gc),
        dataTable.getRow(0).getCell(8).getValue());
    assertEquals(DateValue.getNullValue(),
View Full Code Here

    TableRow row = new TableRow();
    row.addCell(new TableCell("aaa"));
    row.addCell(new TableCell(222));
    row.addCell(new TableCell(false));
    row.addCell(new TableCell(new DateValue(2001, 10, 14)));
    row.addCell(new TableCell(new TimeOfDayValue(12, 11, 13, 14)));
    row.addCell(new TableCell(new DateTimeValue(2000, 10, 1, 1, 10, 23, 432)));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("ccc"));
    row.addCell(new TableCell(111));
    row.addCell(new TableCell(true));
    row.addCell(new TableCell(new DateValue(2001, 1, 14)));
    row.addCell(new TableCell(new TimeOfDayValue(12, 30, 13, 14)));
    row.addCell(new TableCell(new DateTimeValue(1000, 11, 1, 1, 10, 23, 432)));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("bbb"));
    row.addCell(new TableCell(3));
    row.addCell(new TableCell(true));
    row.addCell(new TableCell(new DateValue(2012, 2, 14)));
    row.addCell(new TableCell(new TimeOfDayValue(12, 11, 3, 14)));
    row.addCell(new TableCell(new DateTimeValue(2000, 1, 1, 1, 10, 31, 4)));
    rows.add(row);

    row = new TableRow();
    row.addCell("ddd");
    row.addCell(222);
    row.addCell(false);
    row.addCell(new DateValue(1997, 5, 5));
    row.addCell(new TimeOfDayValue(12, 15, 15, 14));
    row.addCell(new DateTimeValue(3100, 1, 2, 15, 15, 1, 0));
    rows.add(row);

    testData.addRows(rows);
View Full Code Here

    assertEquals("", JsonRenderer.renderDataTable(dataTable, true, false, true));
    assertEquals("", JsonRenderer.renderDataTable(dataTable, true, true, true));
  }

  public void testAppendCellJson() {
    TableCell dateCell = new TableCell(new DateValue(2009, 1, 12));
    TableCell timeofdayCell = new TableCell(new TimeOfDayValue(12, 13, 14, 15));
    TableCell datetimeCell = new TableCell(new DateTimeValue(2009, 1, 12, 12, 13, 14, 15));
    TableCell booleanCell = new TableCell(true);
    TableCell numberCell = new TableCell(12.3);
    TableCell textCell = new TableCell("aba");


    assertEquals("{\"v\":new Date(2009,1,12)}",
        JsonRenderer.appendCellJson(dateCell, new StringBuilder(),
            true, false, true).toString());
    assertEquals("{\"v\":\"Date(2009,1,12)\"}",
        JsonRenderer.appendCellJson(dateCell, new StringBuilder(),
            true, false, false).toString());
    assertEquals("{\"v\":[12,13,14,15]}",
        JsonRenderer.appendCellJson(timeofdayCell, new StringBuilder(),
            true, false, true).toString());
    assertEquals("{\"v\":new Date(2009,1,12,12,13,14)}", //no milliseconds passed
        JsonRenderer.appendCellJson(datetimeCell, new StringBuilder(),
            true, false, true).toString());
    assertEquals("{\"v\":\"Date(2009,1,12,12,13,14)\"}", //no milliseconds passed
        JsonRenderer.appendCellJson(datetimeCell, new StringBuilder(),
            true, false, false).toString());
    assertEquals("{\"v\":true}",
        JsonRenderer.appendCellJson(booleanCell, new StringBuilder(),
            true, false, true).toString());
    assertEquals("{\"v\":12.3}",
        JsonRenderer.appendCellJson(numberCell, new StringBuilder(),
            true, false, true).toString());
    assertEquals("{\"v\":\"aba\"}",
        JsonRenderer.appendCellJson(textCell, new StringBuilder(),
            true, false, true).toString());

    // No formatting still stays the same when there is no formatted value
    assertEquals("{\"v\":12.3}",
        JsonRenderer.appendCellJson(numberCell, new StringBuilder(),
            false, false, true).toString());


   dateCell = new TableCell(new DateValue(2009, 1, 12), "2009-2-12");

    // With formatting
    assertEquals("{\"v\":new Date(2009,1,12),\"f\":\"2009-2-12\"}",
        JsonRenderer.appendCellJson(dateCell, new StringBuilder(),
            true, false, true).toString());
View Full Code Here

    testData.addColumn(c2);

    rows = Lists.newArrayList();

    TableRow row = new TableRow();
    row.addCell(new TableCell(new DateValue(2011, 1, 1), "1/1/2011"));
    row.addCell(new TableCell(new DateTimeValue(2011, 1, 1, 0, 0, 0, 0), "1/1/2011 00:00:00"));
    row.addCell(new TableCell(new NumberValue(222), "222"));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(new DateValue(2011, 1, 2), "1/2/2011"));
    row.addCell(new TableCell(new DateTimeValue(2011, 1, 2, 3, 15, 0, 0)));
    row.addCell(new TableCell(NumberValue.getNullValue()));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(new DateValue(2011, 1, 3), "1/3/2011"));
    row.addCell(new TableCell(new DateTimeValue(2011, 1, 3, 3, 15, 0, 0), "1/1/2011 03:15:00"));
    row.addCell(new TableCell(333));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(new DateValue(2011, 1, 4)));
    row.addCell(new TableCell(new DateTimeValue(2011, 1, 4, 0, 0, 0, 0)));
    row.addCell(new TableCell(222));
    rows.add(row);
   
    testData.addRows(rows);
View Full Code Here

    GregorianCalendar calendar;
    String escapedFormattedString = "";
    boolean isJsonNull = false;

    // Prepare a Json string representing the current value.
    DateValue dateValue;
    TimeOfDayValue timeOfDayValue;
    if ((value == null) || (value.isNull())) {
      valueJson.append("null");
      isJsonNull = true;
    } else {
      switch (type) {
        case BOOLEAN:
          valueJson.append(((BooleanValue) value).getValue());
          break;
        case DATE:
          valueJson.append("Date(");
          dateValue = (DateValue) value;
          valueJson.append(dateValue.getYear()).append(",");
          valueJson.append(dateValue.getMonth()).append(",");
          valueJson.append(dateValue.getDayOfMonth());
          valueJson.append(")");
          if (renderDateAsDateConstructor) {
            // Rendering date as a call to Date constructor, e.g new Date(2011,1,1)
            valueJson.insert(0, "new ");
          } else {
View Full Code Here

          // Set the year, month and date in the gregorian calendar.
          // Use the 'set' method with those parameters, and not the 'setTime'
          // method with the date parameter, since the Date object contains the
          // current time zone and it's impossible to change it to 'GMT'.
          gc.set(date.getYear() + 1900, date.getMonth(), date.getDate());
          value = new DateValue(gc);
        }
        break;
      case DATETIME:
        Timestamp timestamp = rs.getTimestamp(column);
        // If timestamp is null it is handled later.
View Full Code Here

    table.addColumn(new ColumnDescription("numberCol", ValueType.NUMBER, "numberCol"));
    table.addColumn(new ColumnDescription("timeOfDayCol", ValueType.TIMEOFDAY, "timeOfDayCol"));
    table.addColumn(new ColumnDescription("dateTimeCol", ValueType.DATETIME, "dateTimeCol"));

    TableRow row = new TableRow();
    row.addCell(new TableCell(new DateValue(2008, 5, 3)));
    row.addCell(new TableCell(new NumberValue(23)));
    row.addCell(new TableCell(new TimeOfDayValue(13, 12, 11)));
    row.addCell(new TableCell(new DateTimeValue(2007, 3, 4, 2, 6, 23, 120)));

    // Check date value.
View Full Code Here

TOP

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

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.