Example #1
0
  private void initDecimalRangeCheck(Data checkedData, Data otherData) {
    Double otherValue = otherData.getValue();

    Double minCheckedValue = otherValue.doubleValue();
    Double maxCheckedValue = otherValue.doubleValue();

    if (percent != null) {
      double percentValue = percent / 100.0;

      minCheckedValue = (1.0 - percentValue) * otherValue;
      maxCheckedValue = (1.0 + percentValue) * otherValue;
    }

    if (offset != null) {
      minCheckedValue = minCheckedValue - offset.longValue();
      maxCheckedValue = maxCheckedValue + offset.longValue();
    }

    if (percent == null && offset == null) {
      minCheckedValue = null;
      maxCheckedValue = null;
    }

    rangeCheck.setDecimalMinValueMale(minCheckedValue);
    rangeCheck.setDecimalMaxValueMale(maxCheckedValue);
    rangeCheck.setDecimalMinValueFemale(minCheckedValue);
    rangeCheck.setDecimalMaxValueFemale(maxCheckedValue);
  }
Example #2
0
  private void initIntegerRangeCheck(Data checkedData, Data otherData) {
    Long otherValue = otherData.getValue();

    Long minCheckedValue = otherValue;
    Long maxCheckedValue = otherValue;

    if (percent != null) {
      double percentValue = percent / 100.0;

      minCheckedValue =
          new Double(Math.ceil((1.0 - percentValue) * otherValue.longValue())).longValue();
      maxCheckedValue =
          new Double(Math.floor((1.0 + percentValue) * otherValue.longValue())).longValue();
    }

    if (offset != null) {
      minCheckedValue = minCheckedValue - offset;
      maxCheckedValue = maxCheckedValue + offset;
    }

    if (percent == null && offset == null) {
      minCheckedValue = null;
      maxCheckedValue = null;
    }

    rangeCheck.setIntegerMinValueMale(minCheckedValue);
    rangeCheck.setIntegerMaxValueMale(maxCheckedValue);
    rangeCheck.setIntegerMinValueFemale(minCheckedValue);
    rangeCheck.setIntegerMaxValueFemale(maxCheckedValue);
  }
  public synchronized Data getData(Participant participant) {
    isGetDataCalled = true;

    for (IDataSource dataSource : getDataSources()) {
      Data data = dataSource.getData(participant);
      if (data != null && data.getValue() != null) {
        firstDataSource = dataSource;
        return data;
      }
    }
    return null;
  }
  @Override
  protected Data modify(Data data, Participant participant) {

    if (data == null) return null;
    if (!data.getType().equals(DataType.DATE))
      throw new IllegalArgumentException(
          "DataType " + DataType.DATE + " expected, " + data.getType() + " received.");

    Calendar cal = Calendar.getInstance();
    cal.setTime((Date) data.getValue());

    for (DateModifier dateModifier : getDateModifiers()) {
      dateModifier.modify(cal, participant);
    }

    return DataBuilder.buildDate(cal.getTime());
  }
Example #5
0
  @Override
  public boolean checkParameterValue(
      InstrumentParameter checkedParameter,
      Data paramData,
      InstrumentRunService runService,
      ActiveInstrumentRunService activeRunService) {
    if (parameterCode != null && (percent != null || offset != null)) {
      //
      // Get the other parameter's value.
      //
      InstrumentRunValue otherRunValue = activeRunService.getInstrumentRunValue(parameterCode);

      Data otherData = null;
      if (otherRunValue != null) {
        otherData = otherRunValue.getData(paramData.getType());
      }

      if (otherData != null && otherData.getValue() != null) {
        // Lazily instantiate the rangeCheck.
        if (rangeCheck == null) {
          rangeCheck = new RangeCheck();
        }

        if (checkedParameter.getDataType() == DataType.INTEGER) {
          initIntegerRangeCheck(paramData, otherData);
        } else if (checkedParameter.getDataType() == DataType.DECIMAL) {
          initDecimalRangeCheck(paramData, otherData);
        } else {
          return false;
        }

        return rangeCheck.checkParameterValue(
            checkedParameter, paramData, runService, activeRunService);
      } else { // no need to check the spread if the other parameter does not yet have a value
        return true;
      }
    } else { // nothing to check!
      return true;
    }
  }