示例#1
0
 // If the Decision Table model was pre-5.4 Numeric data-types were always stored as
 // BigDecimals. This function attempts to set the correct DTCellValue property based
 // on the *true* data type.
 private void convertDTCellValueFromNumeric(DataType.DataTypes dataType, DTCellValue52 dcv) {
   // Generic type NUMERIC was always stored as a BigDecimal
   final BigDecimal value = (BigDecimal) dcv.getNumericValue();
   switch (dataType) {
     case NUMERIC_BIGDECIMAL:
       dcv.setNumericValue(value == null ? null : value);
       break;
     case NUMERIC_BIGINTEGER:
       dcv.setNumericValue(value == null ? null : value.toBigInteger());
       break;
     case NUMERIC_BYTE:
       dcv.setNumericValue(value == null ? null : value.byteValue());
       break;
     case NUMERIC_DOUBLE:
       dcv.setNumericValue(value == null ? null : value.doubleValue());
       break;
     case NUMERIC_FLOAT:
       dcv.setNumericValue(value == null ? null : value.floatValue());
       break;
     case NUMERIC_INTEGER:
       dcv.setNumericValue(value == null ? null : value.intValue());
       break;
     case NUMERIC_LONG:
       dcv.setNumericValue(value == null ? null : value.longValue());
       break;
     case NUMERIC_SHORT:
       dcv.setNumericValue(value == null ? null : value.shortValue());
       break;
   }
 }
示例#2
0
  @Override
  public void populateDecisionTable(final GuidedDecisionTable52 dtable, final int maxRowCount) {
    if (this.values.size() < maxRowCount) {
      for (int iRow = this.values.size(); iRow < maxRowCount; iRow++) {
        this.values.add(new DTCellValue52(0));
      }
    }

    for (int iRow = 0; iRow < this.values.size(); iRow++) {
      dtable.getData().add(new ArrayList<DTCellValue52>());
      final DTCellValue52 dcv = this.values.get(iRow);
      dcv.setNumericValue(Integer.valueOf(iRow + 1));
      dtable.getData().get(iRow).add(0, dcv);
    }
  }
示例#3
0
 /**
  * Convert a DTCellValue52 to it's String representation
  *
  * @param dcv
  * @return
  */
 public String asString(final DTCellValue52 dcv) {
   switch (dcv.getDataType()) {
     case BOOLEAN:
       return convertBooleanValueToString(dcv);
     case DATE:
       return convertDateValueToString(dcv);
     case NUMERIC:
       return convertNumericValueToString(dcv);
     case NUMERIC_BIGDECIMAL:
       return convertBigDecimalValueToString(dcv);
     case NUMERIC_BIGINTEGER:
       return convertBigIntegerValueToString(dcv);
     case NUMERIC_BYTE:
       return convertByteValueToString(dcv);
     case NUMERIC_DOUBLE:
       return convertDoubleValueToString(dcv);
     case NUMERIC_FLOAT:
       return convertFloatValueToString(dcv);
     case NUMERIC_INTEGER:
       return convertIntegerValueToString(dcv);
     case NUMERIC_LONG:
       return convertLongValueToString(dcv);
     case NUMERIC_SHORT:
       return convertShortValueToString(dcv);
   }
   return convertStringValueToString(dcv);
 }
示例#4
0
 // Convert a Date value to a String
 private String convertDateValueToString(DTCellValue52 dcv) {
   final Date value = dcv.getDateValue();
   String result = "";
   if (value != null) {
     result = DATE_CONVERTOR.format((Date) value);
   }
   return result;
 }
示例#5
0
  /**
   * The column-data type is looked up from the SuggestionCompletionEngine and represents the *true*
   * data-type that the column represents. The data-type associated with the Cell Value can be
   * incorrect for legacy models. For pre-5.2 they will always be String and for pre-5.4 numerical
   * fields are always Numeric
   *
   * @param dataType
   * @param dcv
   */
  public void assertDTCellValue(DataType.DataTypes dataType, DTCellValue52 dcv) {
    if (dcv == null) {
      return;
    }

    // If already converted exit
    if (dataType.equals(dcv.getDataType())) {
      return;
    }

    switch (dcv.getDataType()) {
      case NUMERIC:
        convertDTCellValueFromNumeric(dataType, dcv);
        break;
      default:
        convertDTCellValueFromString(dataType, dcv);
    }
  }
  /**
   * Convert a type-safe UI CellValue into a type-safe Model CellValue
   *
   * @param column Model column from which data-type can be derived
   * @param cell UI CellValue to convert into Model CellValue
   * @return
   */
  public DTCellValue52 convertToModelCell(BaseColumn column, CellValue<?> cell) {
    DataType.DataTypes dt = utilities.getDataType(column);
    DTCellValue52 dtCell = null;

    switch (dt) {
      case BOOLEAN:
        dtCell = new DTCellValue52((Boolean) cell.getValue());
        break;
      case DATE:
        dtCell = new DTCellValue52((Date) cell.getValue());
        break;
      case NUMERIC:
        dtCell = new DTCellValue52((BigDecimal) cell.getValue());
        break;
      case NUMERIC_BIGDECIMAL:
        dtCell = new DTCellValue52((BigDecimal) cell.getValue());
        break;
      case NUMERIC_BIGINTEGER:
        dtCell = new DTCellValue52((BigInteger) cell.getValue());
        break;
      case NUMERIC_BYTE:
        dtCell = new DTCellValue52((Byte) cell.getValue());
        break;
      case NUMERIC_DOUBLE:
        dtCell = new DTCellValue52((Double) cell.getValue());
        break;
      case NUMERIC_FLOAT:
        dtCell = new DTCellValue52((Float) cell.getValue());
        break;
      case NUMERIC_INTEGER:
        dtCell = new DTCellValue52((Integer) cell.getValue());
        break;
      case NUMERIC_LONG:
        dtCell = new DTCellValue52((Long) cell.getValue());
        break;
      case NUMERIC_SHORT:
        dtCell = new DTCellValue52((Short) cell.getValue());
        break;
      default:
        dtCell = new DTCellValue52((String) cell.getValue());
    }
    dtCell.setOtherwise(cell.isOtherwise());
    return dtCell;
  }
示例#7
0
  private void initialiseRowData(final int rowIndex) {
    final List<BaseColumn> modelColumns = model.getExpandedColumns();
    final List<DTCellValue52> modelRow = model.getData().get(rowIndex);
    for (int columnIndex = 0; columnIndex < modelColumns.size(); columnIndex++) {
      final BaseColumn modelColumn = modelColumns.get(columnIndex);
      final DTCellValue52 modelCell = makeModelCellValue(modelColumn);
      modelRow.add(modelCell);

      // BaseGridData is sparsely populated; only add values if needed.
      if (modelCell.hasValue()) {
        uiModel.setCellInternal(
            rowIndex,
            columnIndex,
            gridWidgetCellFactory.convertCell(
                modelCell, modelColumn, cellUtilities, columnUtilities));
      }
      uiModel.indexColumn(columnIndex);

      // Set-up SelectionManager for Row Number column, to select entire row.
      if (modelColumn instanceof RowNumberCol52) {
        uiModel.getCell(rowIndex, columnIndex).setSelectionManager(RowSelectionStrategy.INSTANCE);
      }
    }
  }
示例#8
0
 // If the Decision Table model has been converted from the legacy text based
 // class then all values are held in the DTCellValue's StringValue. This
 // function attempts to set the correct DTCellValue property based on
 // the DTCellValue's data type.
 private void convertDTCellValueFromString(DataType.DataTypes dataType, DTCellValue52 dcv) {
   String text = dcv.getStringValue();
   switch (dataType) {
     case BOOLEAN:
       dcv.setBooleanValue((text == null ? false : Boolean.valueOf(text)));
       break;
     case DATE:
       Date d = null;
       try {
         if (text != null) {
           if (DATE_CONVERTOR == null) {
             throw new IllegalArgumentException("DATE_CONVERTOR has not been initialised.");
           }
           d = DATE_CONVERTOR.parse(text);
         }
       } catch (IllegalArgumentException e) {
       }
       dcv.setDateValue(d);
       break;
     case NUMERIC:
       BigDecimal numericValue = null;
       try {
         if (text != null) {
           numericValue = new BigDecimal(text);
         }
       } catch (Exception e) {
       }
       dcv.setNumericValue(numericValue);
       break;
     case NUMERIC_BIGDECIMAL:
       BigDecimal bigDecimalValue = null;
       try {
         if (text != null) {
           bigDecimalValue = new BigDecimal(text);
         }
       } catch (Exception e) {
       }
       dcv.setNumericValue(bigDecimalValue);
       break;
     case NUMERIC_BIGINTEGER:
       BigInteger bigIntegerValue = null;
       try {
         if (text != null) {
           bigIntegerValue = new BigInteger(text);
         }
       } catch (Exception e) {
       }
       dcv.setNumericValue(bigIntegerValue);
       break;
     case NUMERIC_BYTE:
       Byte byteValue = null;
       try {
         if (text != null) {
           byteValue = new Byte(text);
         }
       } catch (Exception e) {
       }
       dcv.setNumericValue(byteValue);
       break;
     case NUMERIC_DOUBLE:
       Double doubleValue = null;
       try {
         if (text != null) {
           doubleValue = new Double(text);
         }
       } catch (Exception e) {
       }
       dcv.setNumericValue(doubleValue);
       break;
     case NUMERIC_FLOAT:
       Float floatValue = null;
       try {
         if (text != null) {
           floatValue = new Float(text);
         }
       } catch (Exception e) {
       }
       dcv.setNumericValue(floatValue);
       break;
     case NUMERIC_INTEGER:
       Integer integerValue = null;
       try {
         if (text != null) {
           integerValue = new Integer(text);
         }
       } catch (Exception e) {
       }
       dcv.setNumericValue(integerValue);
       break;
     case NUMERIC_LONG:
       Long longValue = null;
       try {
         if (text != null) {
           longValue = new Long(text);
         }
       } catch (Exception e) {
       }
       dcv.setNumericValue(longValue);
       break;
     case NUMERIC_SHORT:
       Short shortValue = null;
       try {
         if (text != null) {
           shortValue = new Short(text);
         }
       } catch (Exception e) {
       }
       dcv.setNumericValue(shortValue);
       break;
   }
 }
示例#9
0
 // Convert a String value to a String
 private String convertStringValueToString(DTCellValue52 dcv) {
   final String value = dcv.getStringValue();
   return (value == null ? "" : value);
 }
示例#10
0
 // Convert a Short value to a String
 private String convertShortValueToString(DTCellValue52 dcv) {
   final Short value = (Short) dcv.getNumericValue();
   return (value == null ? "" : value.toString());
 }
示例#11
0
 // Convert a Long value to a String
 private String convertLongValueToString(DTCellValue52 dcv) {
   final Long value = (Long) dcv.getNumericValue();
   return (value == null ? "" : value.toString());
 }
示例#12
0
 // Convert a Integer value to a String
 private String convertIntegerValueToString(DTCellValue52 dcv) {
   final Integer value = (Integer) dcv.getNumericValue();
   return (value == null ? "" : value.toString());
 }
示例#13
0
 // Convert a BigDecimal value to a String
 private String convertBigDecimalValueToString(DTCellValue52 dcv) {
   final BigDecimal value = (BigDecimal) dcv.getNumericValue();
   return (value == null ? "" : value.toPlainString());
 }
示例#14
0
 // Convert a Boolean value to a String
 private String convertBooleanValueToString(DTCellValue52 dcv) {
   final Boolean value = dcv.getBooleanValue();
   return (value == null ? "" : value.toString());
 }
  @Override
  public GuidedDecisionTableUiCell convertCell(
      final DTCellValue52 cell,
      final BaseColumn column,
      final CellUtilities cellUtilities,
      final ColumnUtilities columnUtilities) {
    // If the underlying modelCell does not have a value don't create a UiModelCell. The
    // underlying model data is fully populated whereas the uiModel is sparsely populated.
    if (!cell.hasValue()) {
      return null;
    }

    final DataType.DataTypes dataType = columnUtilities.getDataType(column);
    cellUtilities.convertDTCellValueType(dataType, cell);

    switch (dataType) {
      case NUMERIC:
        return new GuidedDecisionTableUiCell<Number>(cell.getNumericValue(), cell.isOtherwise());
      case NUMERIC_BIGDECIMAL:
        return new GuidedDecisionTableUiCell<BigDecimal>(
            (BigDecimal) cell.getNumericValue(), cell.isOtherwise());
      case NUMERIC_BIGINTEGER:
        return new GuidedDecisionTableUiCell<BigInteger>(
            (BigInteger) cell.getNumericValue(), cell.isOtherwise());
      case NUMERIC_BYTE:
        return new GuidedDecisionTableUiCell<Byte>(
            (Byte) cell.getNumericValue(), cell.isOtherwise());
      case NUMERIC_DOUBLE:
        return new GuidedDecisionTableUiCell<Double>(
            (Double) cell.getNumericValue(), cell.isOtherwise());
      case NUMERIC_FLOAT:
        return new GuidedDecisionTableUiCell<Float>(
            (Float) cell.getNumericValue(), cell.isOtherwise());
      case NUMERIC_INTEGER:
        return new GuidedDecisionTableUiCell<Integer>(
            (Integer) cell.getNumericValue(), cell.isOtherwise());
      case NUMERIC_LONG:
        return new GuidedDecisionTableUiCell<Long>(
            (Long) cell.getNumericValue(), cell.isOtherwise());
      case NUMERIC_SHORT:
        return new GuidedDecisionTableUiCell<Short>(
            (Short) cell.getNumericValue(), cell.isOtherwise());
      case DATE:
        return new GuidedDecisionTableUiCell<Date>(cell.getDateValue(), cell.isOtherwise());
      case BOOLEAN:
        return new GuidedDecisionTableUiCell<Boolean>(cell.getBooleanValue(), cell.isOtherwise());
      default:
        return new GuidedDecisionTableUiCell<String>(cell.getStringValue(), cell.isOtherwise());
    }
  }
示例#16
0
 // Convert a Double value to a String
 private String convertDoubleValueToString(DTCellValue52 dcv) {
   final Double value = (Double) dcv.getNumericValue();
   return (value == null ? "" : value.toString());
 }
  /**
   * Convert a Model cell to one that can be used in the UI
   *
   * @param dcv
   * @return
   */
  @Override
  public CellValue<? extends Comparable<?>> convertModelCellValue(
      BaseColumn column, DTCellValue52 dcv) {

    // Analysis cells do not use data-type
    if (column instanceof AnalysisCol52) {
      return makeNewAnalysisCellValue();
    }

    // Other cells do use data-type
    DataType.DataTypes dataType = utilities.getDataType(column);
    utilities.assertDTCellValue(dataType, dcv);

    CellValue<? extends Comparable<?>> cell = null;
    switch (dataType) {
      case BOOLEAN:
        cell = makeNewBooleanCellValue(dcv.getBooleanValue());
        break;
      case DATE:
        cell = makeNewDateCellValue(dcv.getDateValue());
        break;
      case NUMERIC:
        cell = makeNewNumericCellValue((BigDecimal) dcv.getNumericValue());
        break;
      case NUMERIC_BIGDECIMAL:
        cell = makeNewBigDecimalCellValue((BigDecimal) dcv.getNumericValue());
        break;
      case NUMERIC_BIGINTEGER:
        cell = makeNewBigIntegerCellValue((BigInteger) dcv.getNumericValue());
        break;
      case NUMERIC_BYTE:
        cell = makeNewByteCellValue((Byte) dcv.getNumericValue());
        break;
      case NUMERIC_DOUBLE:
        cell = makeNewDoubleCellValue((Double) dcv.getNumericValue());
        break;
      case NUMERIC_FLOAT:
        cell = makeNewFloatCellValue((Float) dcv.getNumericValue());
        break;
      case NUMERIC_INTEGER:
        cell = makeNewIntegerCellValue((Integer) dcv.getNumericValue());
        break;
      case NUMERIC_LONG:
        if (column instanceof RowNumberCol52) {
          cell = makeNewRowNumberCellValue((Long) dcv.getNumericValue());
        } else {
          cell = makeNewLongCellValue((Long) dcv.getNumericValue());
          if (column instanceof AttributeCol52) {
            AttributeCol52 at = (AttributeCol52) column;
            if (at.getAttribute().equals(RuleAttributeWidget.SALIENCE_ATTR)) {
              if (at.isUseRowNumber()) {
                cell = makeNewRowNumberCellValue((Long) dcv.getNumericValue());
              }
            }
          }
        }
        break;
      case NUMERIC_SHORT:
        cell = makeNewShortCellValue((Short) dcv.getNumericValue());
        break;
      default:
        cell = makeNewStringCellValue(dcv.getStringValue());
        if (column instanceof AttributeCol52) {
          AttributeCol52 ac = (AttributeCol52) column;
          if (ac.getAttribute().equals(RuleAttributeWidget.DIALECT_ATTR)) {
            cell = makeNewDialectCellValue(dcv.getStringValue());
          }
        }
    }

    if (dcv.isOtherwise()) {
      cell.addState(CellState.OTHERWISE);
    }

    return cell;
  }