/** * Converts an FpML frequency to a {@code Frequency}. * * @param baseEl the FpML element to parse * @return the frequency * @throws RuntimeException if unable to parse */ public Frequency parseFrequency(XmlElement baseEl) { // FpML content: ('periodMultiplier', 'period') String multiplier = baseEl.getChild("periodMultiplier").getContent(); String unit = baseEl.getChild("period").getContent(); if (unit.equals("T")) { return Frequency.TERM; } return convertFrequency(multiplier, unit); }
public void documentFrequency() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableMap.of("href", "foo"), ImmutableList.of(tradeHeaderEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocument test = new FpmlDocument(rootEl, ImmutableMap.of(), FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), REF_DATA); assertEquals(test.convertFrequency("1", "M"), Frequency.P1M); assertEquals(test.convertFrequency("12", "M"), Frequency.P12M); assertEquals(test.convertFrequency("1", "Y"), Frequency.P12M); assertEquals(test.convertFrequency("13", "Y"), Frequency.of(Period.ofYears(13))); }