/** * Converts an FpML 'hourMinuteTime' to a {@code LocalTime}. * * @param baseEl the FpML element to parse * @return the time * @throws RuntimeException if unable to parse */ public LocalTime parseTime(XmlElement baseEl) { return LocalTime.parse(baseEl.getContent()); }
/** * Converts an FpML 'decimal' to a {@code double}. * * @param baseEl the FpML element to parse * @return the double * @throws RuntimeException if unable to parse */ public double parseDecimal(XmlElement baseEl) { return Double.parseDouble(baseEl.getContent()); }
/** * Converts an FpML 'date' to a {@code LocalDate}. * * @param baseEl the FpML element to parse * @return the date * @throws RuntimeException if unable to parse */ public LocalDate parseDate(XmlElement baseEl) { return convertDate(baseEl.getContent()); }
private static List<String> findPartyIds(XmlElement party) { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (XmlElement child : party.getChildren("partyId")) { if (child.hasContent()) { builder.add(child.getContent()); } } return builder.build(); }
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)); } }
private IborRateResetMethod parseAveragingMethod(XmlElement baseEl) { String str = baseEl.getContent(); if (str.equals("Unweighted")) { return IborRateResetMethod.UNWEIGHTED; } else if (str.equals("Weighted")) { return IborRateResetMethod.WEIGHTED; } else { throw new FpmlParseException(Messages.format( "Unknown 'resetMethod' value '{}', expected 'Unweighted' or 'Weighted'", str)); } }
private FixingRelativeTo parseResetRelativeTo(XmlElement baseEl) { String str = baseEl.getContent(); if (str.equals("CalculationPeriodStartDate")) { return FixingRelativeTo.PERIOD_START; } else if (str.equals("CalculationPeriodEndDate")) { return FixingRelativeTo.PERIOD_END; } else { throw new FpmlParseException(Messages.format( "Unknown 'resetRelativeTo' value '{}', expected 'CalculationPeriodStartDate' or 'CalculationPeriodEndDate'", str)); } }
private NegativeRateMethod parseNegativeInterestRateTreatment(XmlElement baseEl) { String str = baseEl.getContent(); if (str.equals("NegativeInterestRateMethod")) { return NegativeRateMethod.ALLOW_NEGATIVE; } else if (str.equals("ZeroInterestRateMethod")) { return NegativeRateMethod.NOT_NEGATIVE; } else { throw new FpmlParseException(Messages.format( "Unknown 'negativeInterestRateTreatment' value '{}', " + "expected 'NegativeInterestRateMethod' or 'ZeroInterestRateMethod'", str)); } }
/** * Converts an FpML 'FloatingRateIndex' tenor to a {@code Tenor}. * * @param baseEl the FpML floating rate index element to parse * @return the period * @throws RuntimeException if unable to parse */ public Tenor parseIndexTenor(XmlElement baseEl) { // FpML content: ('periodMultiplier', 'period') String multiplier = baseEl.getChild("periodMultiplier").getContent(); String unit = baseEl.getChild("period").getContent(); return convertIndexTenor(multiplier, unit); }
/** * Converts an FpML 'Period' to a {@code Period}. * * @param baseEl the FpML element to parse * @return the period * @throws RuntimeException if unable to parse */ public Period parsePeriod(XmlElement baseEl) { // FpML content: ('periodMultiplier', 'period') String multiplier = baseEl.getChild("periodMultiplier").getContent(); String unit = baseEl.getChild("period").getContent(); return Period.parse("P" + multiplier + unit); }
/** * Converts an FpML 'BusinessCenter' to a {@code HolidayCalendar}. * * @param baseEl the FpML calendar element to parse * @return the calendar * @throws RuntimeException if unable to parse */ public HolidayCalendarId parseBusinessCenter(XmlElement baseEl) { validateScheme(baseEl, "businessCenterScheme", "http://www.fpml.org/coding-scheme/business-center"); return convertHolidayCalendar(baseEl.getContent()); }
private ZoneId parseExpiryZone(XmlElement expirationTimeEl, FpmlDocument document) { String businessCenter = expirationTimeEl.getChild("businessCenter").getContent(); Optional<ZoneId> optionalZoneId = document.getZoneId(businessCenter); if (!optionalZoneId.isPresent()) { throw new FpmlParseException("Unknown businessCenter" + " attribute value: " + businessCenter); } return optionalZoneId.get(); }
/** * Converts an FpML 'DayCountFraction' to a {@code DayCount}. * * @param baseEl the FpML day count element to parse * @return the day count * @throws RuntimeException if unable to parse */ public DayCount parseDayCountFraction(XmlElement baseEl) { validateScheme( baseEl, "dayCountFractionScheme", "http://www.fpml.org/coding-scheme/day-count-fraction", // standard form "http://www.fpml.org/spec/2004/day-count-fraction"); // seen in the wild return convertDayCount(baseEl.getContent()); }
/** * Converts an FpML 'FloatingRateIndex.model' to a {@code PriceIndex}. * * @param baseEl the FpML floating rate model element to parse * @return the index * @throws RuntimeException if unable to parse */ public PriceIndex parsePriceIndex(XmlElement baseEl) { XmlElement indexEl = baseEl.getChild("floatingRateIndex"); validateScheme(indexEl, "floatingRateIndexScheme", "http://www.fpml.org/coding-scheme/inflation-index-description"); FloatingRateName floatingName = FloatingRateName.of(indexEl.getContent()); return floatingName.toPriceIndex(); }
public void test_ofChildren_one() { XmlElement test = XmlElement.ofChildren("test", ATTR_MAP, CHILD_LIST_ONE); assertEquals(test.getName(), "test"); assertEquals(test.getAttributes(), ATTR_MAP); assertEquals(test.hasContent(), false); assertEquals(test.getContent(), ""); assertEquals(test.getChildren(), CHILD_LIST_ONE); assertEquals(test.getAttribute("key"), "value"); assertEquals(test.findAttribute("key"), Optional.of("value")); assertEquals(test.findAttribute("none"), Optional.empty()); assertEquals(test.getChild(0), LEAF1); assertEquals(test.getChild("leaf1"), LEAF1); assertEquals(test.findChild("leaf1"), Optional.of(LEAF1)); assertEquals(test.getChildren("leaf1"), ImmutableList.of(LEAF1)); assertEquals(test.toString(), "<test key=\"value\" og=\"strata\">" + System.lineSeparator() + " <leaf1 ... />" + System.lineSeparator() + "</test>"); }
public void test_of_ByteSource() { ByteSource source = ByteSource.wrap(SAMPLE.getBytes(StandardCharsets.UTF_8)); XmlFile test = XmlFile.of(source); XmlElement root = test.getRoot(); assertEquals(root.getName(), "base"); assertEquals(root.getAttributes(), ATTR_MAP_EMPTY); assertEquals(root.getContent(), ""); assertEquals(root.getChildren().size(), 1); XmlElement child = root.getChild(0); assertEquals(child, XmlElement.ofChildren("test", ATTR_MAP, CHILD_LIST_MULTI)); assertEquals(test.getReferences(), ImmutableMap.of()); }
public void test_of_ByteSource_parsedReferences() { ByteSource source = ByteSource.wrap(SAMPLE.getBytes(StandardCharsets.UTF_8)); XmlFile test = XmlFile.of(source, "key"); XmlElement root = test.getRoot(); assertEquals(root.getName(), "base"); assertEquals(root.getAttributes(), ATTR_MAP_EMPTY); assertEquals(root.getContent(), ""); assertEquals(root.getChildren().size(), 1); XmlElement child = root.getChild(0); assertEquals(child, XmlElement.ofChildren("test", ATTR_MAP, CHILD_LIST_MULTI)); assertEquals(test.getReferences(), ImmutableMap.of("value", root.getChild(0))); }
public void test_ofChildren_empty() { XmlElement test = XmlElement.ofChildren("test", CHILD_LIST_EMPTY); assertEquals(test.getName(), "test"); assertEquals(test.getAttributes(), ATTR_MAP_EMPTY); assertEquals(test.hasContent(), false); assertEquals(test.getContent(), ""); assertEquals(test.getChildren(), CHILD_LIST_EMPTY); assertThrowsIllegalArg(() -> test.getAttribute("notFound")); assertThrows(() -> test.getChild(0), IndexOutOfBoundsException.class); assertThrowsIllegalArg(() -> test.getChild("notFound")); assertEquals(test.findChild("notFound"), Optional.empty()); assertEquals(test.getChildren("notFound"), ImmutableList.of()); assertEquals(test.toString(), "<test></test>"); }
public void test_ofContent() { XmlElement test = XmlElement.ofContent("test", ATTR_MAP_EMPTY, "hello"); assertEquals(test.getName(), "test"); assertEquals(test.getAttributes(), ATTR_MAP_EMPTY); assertEquals(test.hasContent(), true); assertEquals(test.getContent(), "hello"); assertEquals(test.getChildren(), CHILD_LIST_EMPTY); assertThrowsIllegalArg(() -> test.getAttribute("notFound")); assertThrows(() -> test.getChild(0), IndexOutOfBoundsException.class); assertThrowsIllegalArg(() -> test.getChild("notFound")); assertEquals(test.findChild("notFound"), Optional.empty()); assertEquals(test.getChildren("notFound"), ImmutableList.of()); assertEquals(test.toString(), "<test>hello</test>"); }
public void test_ofContent_empty() { XmlElement test = XmlElement.ofContent("test", ""); assertEquals(test.getName(), "test"); assertEquals(test.getAttributes(), ATTR_MAP_EMPTY); assertEquals(test.hasContent(), false); assertEquals(test.getContent(), ""); assertEquals(test.getChildren(), CHILD_LIST_EMPTY); assertThrowsIllegalArg(() -> test.getAttribute("notFound")); assertThrows(() -> test.getChild(0), IndexOutOfBoundsException.class); assertThrowsIllegalArg(() -> test.getChild("notFound")); assertEquals(test.findChild("notFound"), Optional.empty()); assertEquals(test.getChildren("notFound"), ImmutableList.of()); assertEquals(test.toString(), "<test></test>"); }