Пример #1
0
  double getDouble(String cellName) {
    for (DataCell cell : cells) {
      if (cell.getCellName().equals(cellName)) return (double) ((NumberCell) cell).getCellValue();
    }

    return 0.0;
  }
Пример #2
0
  String getString(String cellName) {
    for (DataCell cell : cells) {
      if (cell.getCellName().equals(cellName)) return (String) ((StringCell) cell).getCellValue();
    }

    return new String("");
  }
Пример #3
0
  /** Creates a dataset of type XYSeries */
  public XYDataset convertDataSet() {
    int size = 0; // Initialises a value for size
    int sum = 0; // initialises a value for sum
    int pos = 0; // initialises a value for position
    int j = 0; // initialises a increment for the for loop

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries(super.GetTitle());

    DataCell preVal = super.GetDataSet().GetCell(0, 0);
    // Creates a new list for the found elements
    super.m_foundElements = new ArrayList<String>();

    for (int i = 0; i < super.GetDataSet().GetNumOfRows() - 1; i++) {

      if (!super.isUnique(super.GetDataSet().GetCell(super.GetXColumnPosition(), i).toString())) {
        for (j = pos; j < super.GetDataSet().GetNumOfRows() - 1; j++) {
          if (preVal
              .toString()
              .equals(super.GetDataSet().GetCell(super.GetXColumnPosition(), j).toString())) {

            // Check if datatype is a number
            if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
                == DataType.INTEGER) {
              sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetInteger();
            } else if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
                == DataType.DOUBLE) {
              sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetDouble();
            }
          }
        }
        super.m_foundElements.add(
            super.GetDataSet().GetCell(super.GetXColumnPosition(), i).toString());

        // Add to chart dataSet
        series.add(sum, preVal.GetInteger());

        preVal = super.GetDataSet().GetCell(super.GetXColumnPosition(), i++);
        sum = 0; //
        pos++;
      }
    }

    for (j = pos; j < super.GetDataSet().GetNumOfRows() - 1; j++) {
      if (super.m_foundElements
          .get(super.m_foundElements.size() - 1)
          .equals(super.GetDataSet().GetCell(super.GetXColumnPosition(), j).toString())) {
        if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
            == DataType.INTEGER) {
          sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetInteger();
        } else if (super.GetDataSet().GetCell(super.GetXColumnPosition(), j).GetDataType()
            == DataType.DOUBLE) {
          sum += super.GetDataSet().GetCell(super.GetYColumnPosition(), j).GetDouble();
        }
      }
    }
    series.add(sum, preVal.GetInteger());
    dataset.addSeries(series);
    return dataset;
  }
Пример #4
0
  public void print() {

    for (DataCell cell : cells) {
      System.out.printf("%s [%s] = ", cell.getCellName(), cell.getCellType());
      if (cell.getCellType().equals("number")) {
        System.out.printf("%.2f\n", ((NumberCell) cell).getCellValue());
      } else {
        System.out.printf("%s\n", ((StringCell) cell).getCellValue());
      }
    }

    System.out.println("");
  }
  /**
   * Create a KVPair that can be used to issue a delete on an index record associated with the given
   * main table mutation.
   *
   * @param mutation the incoming modification. Its rowKey is used to get the the row in the base
   *     table that will be updated. Once we have that, we can create a new KVPair of type {@link
   *     KVPair.Type#DELETE DELETE} and call {@link #translate(KVPair)} to translate it to the
   *     index's rowKey.
   * @param ctx the write context of the modification. Used to get transaction and region info.
   * @param indexedColumns the columns which are part of this index. Used to filter the Get.
   * @return An index row KVPair that can be used to delete the associated index row, or null if the
   *     mutated row is not found (may have already been deleted).
   * @throws IOException for encoding/decoding problems.
   */
  public KVPair createIndexDelete(KVPair mutation, WriteContext ctx, BitSet indexedColumns)
      throws IOException {
    // do a Get() on all the indexed columns of the base table
    DataResult result = fetchBaseRow(mutation, ctx, indexedColumns);
    //        EntryPredicateFilter predicateFilter = new EntryPredicateFilter(indexedColumns, new
    // ObjectArrayList<Predicate>(),true);
    //        get.setAttribute(SpliceConstants.ENTRY_PREDICATE_LABEL,predicateFilter.toBytes());
    //        DataResult result = ctx.getRegion().get(get);
    if (result == null || result.size() <= 0) {
      // we can't find the old row, may have been deleted already
      return null;
    }

    DataCell resultValue = result.userData();
    if (resultValue == null) {
      // we can't find the old row, may have been deleted already
      return null;
    }

    // transform the results into an index row (as if we were inserting it) but create a delete for
    // it

    KVPair toTransform =
        new KVPair(
            resultValue.keyArray(),
            resultValue.keyOffset(),
            resultValue.keyLength(),
            resultValue.valueArray(),
            resultValue.valueOffset(),
            resultValue.valueLength(),
            KVPair.Type.DELETE);
    return translate(toTransform);
  }