@Override public <T> T getInfo(CurveInfoType<T> type) { // overridden for performance @SuppressWarnings("unchecked") T value = (T) info.get(type); if (value == null) { throw new IllegalArgumentException(Messages.format("Curve info not found for type '{}'", type)); } return value; }
@Override public <T> T getInfo(SurfaceInfoType<T> type) { // overridden for performance @SuppressWarnings("unchecked") T value = (T) info.get(type); if (value == null) { throw new IllegalArgumentException(Messages.format("Surface info not found for type '{}'", type)); } return value; }
/** * Gets a single sensitivity instance by name. * * @param name the curve name to find * @return the matching sensitivity * @throws IllegalArgumentException if the name and currency do not match an entry */ public UnitParameterSensitivity getSensitivity(MarketDataName<?> name) { return findSensitivity(name) .orElseThrow(() -> new IllegalArgumentException(Messages.format( "Unable to find sensitivity: {}", name))); }
static void checkType(MarketDataId<?> id, Object value) { if (!id.getMarketDataType().isInstance(value)) { if (value == null) { throw new IllegalArgumentException(Messages.format( "Value for identifier '{}' must not be null", id)); } throw new ClassCastException(Messages.format( "Value for identifier '{}' does not implement expected type '{}': '{}'", id, id.getMarketDataType().getSimpleName(), value)); } }
@ImmutableValidator private void validate() { if (minGapInDays < 1) { throw new IllegalArgumentException(Messages.format( "Minimum gap must be at least one day, but was {}", minGapInDays)); } }
private static void validateEntry(ReferenceDataId<?> id, Object value) { if (!id.getReferenceDataType().isInstance(value)) { if (value == null) { throw new IllegalArgumentException(Messages.format( "Value for identifier '{}' must not be null", id)); } throw new ClassCastException(Messages.format( "Value for identifier '{}' does not implement expected type '{}': '{}'", id, id.getReferenceDataType().getSimpleName(), value)); } }
@Override public <T> T getAttribute(AttributeType<T> type) { return findAttribute(type).orElseThrow(() -> new IllegalArgumentException( Messages.format("Attribute not found for type '{}'", type))); }
@Override public <T> T getAttribute(AttributeType<T> type) { return findAttribute(type).orElseThrow(() -> new IllegalArgumentException( Messages.format("Attribute not found for type '{}'", type))); }
@Override public <T> T getAttribute(AttributeType<T> type) { return findAttribute(type).orElseThrow(() -> new IllegalArgumentException( Messages.format("Attribute not found for type '{}'", type))); }
private PaymentRelativeTo parsePayRelativeTo(XmlElement baseEl) { String str = baseEl.getContent(); if (str.equals("CalculationPeriodStartDate")) { return PaymentRelativeTo.PERIOD_START; } else if (str.equals("CalculationPeriodEndDate")) { return PaymentRelativeTo.PERIOD_END; } else { throw new FpmlParseException(Messages.format( "Unknown 'payRelativeTo' value '{}', expected 'CalculationPeriodStartDate' or 'CalculationPeriodEndDate'", str)); } }
@ImmutableValidator private void validate() { if (!currencyPair.contains(referenceCurrency)) { throw new IllegalArgumentException(Messages.format( "Reference currency {} must be one of those in the currency pair {}", referenceCurrency, currencyPair)); } }
private static void checkBoxType(MarketDataId<?> id, MarketDataBox<?> box) { if (!id.getMarketDataType().isAssignableFrom(box.getMarketDataType())) { throw new IllegalArgumentException(Messages.format( "Market data type {} of value {} is not compatible with the market data type of the identifier {}", box.getMarketDataType().getName(), box, id.getMarketDataType().getName())); } }
@Test(dataProvider = "formatMessage") public void test_formatMessage_prefixSuffix(String template, Object[] args, String expMain, String expExcess) { assertEquals( Messages.format("::" + Objects.toString(template, "") + "@@", args), "::" + expMain + "@@" + expExcess); }
@ImmutableValidator private void validate() { if (!index.getCurrencyPair().contains(referenceCurrency)) { throw new IllegalArgumentException( Messages.format("Reference currency {} must be one of those in the FxIndex {}", referenceCurrency, index)); } }
private void checkAndUpdateScenarioCount(MarketDataBox<?> value) { if (value.isScenarioValue()) { if (scenarioCount == -1) { scenarioCount = value.getScenarioCount(); } else if (value.getScenarioCount() != scenarioCount) { throw new IllegalArgumentException(Messages.format( "All values must have the same number of scenarios, expecting {} but received {}", scenarioCount, value.getScenarioCount())); } } }
@Override public ScenarioArray<?> convertedTo(Currency resultCurrency, ScenarioFxRateProvider fxRateProvider) { int scenarioCount = getScenarioCount(); if (fxRateProvider.getScenarioCount() != scenarioCount) { throw new IllegalArgumentException(Messages.format( "Expected {} FX rates but received {}", scenarioCount, fxRateProvider.getScenarioCount())); } ImmutableList<Object> converted = zipWithIndex(values.stream()) .map(tp -> convert(resultCurrency, fxRateProvider, tp.getFirst(), tp.getSecond())) .collect(toImmutableList()); return DefaultScenarioArray.of(converted); }
@ImmutableValidator private void validate() { if (value.isScenarioValue() && value.getScenarioCount() != underlying.getScenarioCount()) { throw new IllegalArgumentException(Messages.format( "Scenario count mismatch: value has {} scenarios but this market data has {}", value.getScenarioCount(), underlying.getScenarioCount())); } }
@ImmutableValidator private void validate() { FxIndex index = observation.getIndex(); if (!index.getCurrencyPair().contains(notionalAmount.getCurrency())) { throw new IllegalArgumentException( Messages.format( "Reference currency {} must be one of those in the FxIndex {}", notionalAmount.getCurrency(), index)); } }
@Override protected String formatData(TradeReport report, int rowIdx, int colIdx, ReportOutputFormat format) { TradeReportColumn templateColumn = report.getColumns().get(colIdx); Result<?> result = report.getData().get(rowIdx, colIdx); if (result.isFailure()) { return templateColumn.isIgnoreFailures() ? "" : Messages.format("FAIL: {}", result.getFailure().getMessage()); } Object value = result.getValue(); return formatValue(value, format); }
@ImmutableValidator private void validate() { ArgChecker.isTrue( fixedLeg.getCurrency().equals(floatingLeg.getCurrency()), Messages.format( "Swap leg conventions must have same currency but found {} and {}, conventions {} and {}", fixedLeg.getCurrency(), floatingLeg.getCurrency(), fixedLeg, floatingLeg)); }