Java Code Examples for com.google.common.io.CharSource#wrap()
The following examples show how to use
com.google.common.io.CharSource#wrap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 6 votes |
@Test public void test_parse_multipleSources() { CharSource source1 = CharSource.wrap( "Reference,Sensitivity Tenor,Zero Rate Delta\n" + "GBP-LIBOR,P1M,1.1\n" + "GBP-LIBOR,P2M,1.2\n"); CharSource source2 = CharSource.wrap( "Reference,Sensitivity Tenor,Zero Rate Delta\n" + "GBP-LIBOR,P3M,1.3\n" + "GBP-LIBOR,P6M,1.4\n"); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source1, source2)); assertThat(test.getFailures().size()).as(test.getFailures().toString()).isEqualTo(0); assertThat(test.getValue().keySet()).hasSize(1); List<CurveSensitivities> list = test.getValue().get(""); assertThat(list).hasSize(2); CurveSensitivities csens0 = list.get(0); assertThat(csens0.getTypedSensitivities()).hasSize(1); assertSens(csens0, ZERO_RATE_DELTA, "GBP-LIBOR", GBP, "1M, 2M", 1.1, 1.2); CurveSensitivities csens1 = list.get(1); assertThat(csens1.getTypedSensitivities()).hasSize(1); assertSens(csens1, ZERO_RATE_DELTA, "GBP-LIBOR", GBP, "3M, 6M", 1.3, 1.4); }
Example 2
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 6 votes |
@Test public void test_parse_list_duplicateTenor() { CharSource source = CharSource.wrap( "Reference,Sensitivity Tenor,Zero Rate Delta\n" + "GBP,P1D,1\n" + "GBP,P1M,2\n" + "GBP,P1M,3\n"); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source)); assertThat(test.getFailures().size()).as(test.getFailures().toString()).isEqualTo(0); assertThat(test.getValue().size()).isEqualTo(1); List<CurveSensitivities> list = test.getValue().get(""); assertThat(list).hasSize(1); CurveSensitivities csens0 = list.get(0); assertThat(csens0.getTypedSensitivities()).hasSize(1); assertSens(csens0, ZERO_RATE_DELTA, "GBP", GBP, "1D, 1M", 1, 5); }
Example 3
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 6 votes |
@Test public void test_parse_grid_dateInTenorColumn() { CharSource source = CharSource.wrap( "Sensitivity Type,Sensitivity Tenor,GBP\n" + "ZeroRateGamma,2018-06-30,1\n"); assertThat(LOADER_DATE.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER_DATE.parse(ImmutableList.of(source)); assertThat(test.getFailures().size()).as(test.getFailures().toString()).isEqualTo(0); assertThat(test.getValue().size()).isEqualTo(1); List<CurveSensitivities> list = test.getValue().get(""); assertThat(list).hasSize(1); CurveSensitivities csens0 = list.get(0); assertThat(csens0.getTypedSensitivities()).hasSize(1); CurrencyParameterSensitivities cpss = csens0.getTypedSensitivity(ZERO_RATE_GAMMA); assertThat(cpss.getSensitivities()).hasSize(1); CurrencyParameterSensitivity cps = cpss.getSensitivities().get(0); assertThat(cps.getParameterMetadata()).hasSize(1); assertThat(cps.getParameterMetadata().get(0)).isEqualTo(LabelDateParameterMetadata.of(date(2018, 6, 30), "2018-06-30")); }
Example 4
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 6 votes |
@Test public void test_parse_grid_dateColumn() { CharSource source = CharSource.wrap( "Sensitivity Type,Sensitivity Date,GBP\n" + "ZeroRateGamma,2018-06-30,1\n"); assertThat(LOADER_DATE.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER_DATE.parse(ImmutableList.of(source)); assertThat(test.getFailures().size()).as(test.getFailures().toString()).isEqualTo(0); assertThat(test.getValue().size()).isEqualTo(1); List<CurveSensitivities> list = test.getValue().get(""); assertThat(list).hasSize(1); CurveSensitivities csens0 = list.get(0); assertThat(csens0.getTypedSensitivities()).hasSize(1); CurrencyParameterSensitivities cpss = csens0.getTypedSensitivity(ZERO_RATE_GAMMA); assertThat(cpss.getSensitivities()).hasSize(1); CurrencyParameterSensitivity cps = cpss.getSensitivities().get(0); assertThat(cps.getParameterMetadata()).hasSize(1); assertThat(cps.getParameterMetadata().get(0)).isEqualTo(LabelDateParameterMetadata.of(date(2018, 6, 30), "2018-06-30")); }
Example 5
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 6 votes |
@Test public void test_parse_grid_duplicateTenor() { CharSource source = CharSource.wrap( "Sensitivity Type,Sensitivity Tenor,GBP\n" + "ZeroRateGamma,P6M,1\n" + "ZeroRateGamma,12M,2\n" + "ZeroRateGamma,12M,3\n"); assertThat(LOADER_DATE.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER_DATE.parse(ImmutableList.of(source)); assertThat(test.getFailures().size()).as(test.getFailures().toString()).isEqualTo(0); assertThat(test.getValue().size()).isEqualTo(1); List<CurveSensitivities> list = test.getValue().get(""); assertThat(list).hasSize(1); CurveSensitivities csens0 = list.get(0); assertThat(csens0.getTypedSensitivities()).hasSize(1); assertSens(csens0, ZERO_RATE_GAMMA, "GBP", GBP, "6M, 1Y", 1, 5); // 12M -> 1Y }
Example 6
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 6 votes |
@Test public void test_parse_grid_tenorAndDateColumns() { CharSource source = CharSource.wrap( "Sensitivity Type,Sensitivity Tenor,Sensitivity Date,GBP\n" + "ZeroRateGamma,1M,2018-06-30,1\n"); assertThat(LOADER.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source)); assertThat(test.getFailures().size()).as(test.getFailures().toString()).isEqualTo(0); assertThat(test.getValue().size()).isEqualTo(1); List<CurveSensitivities> list = test.getValue().get(""); assertThat(list).hasSize(1); CurveSensitivities csens0 = list.get(0); assertThat(csens0.getTypedSensitivities()).hasSize(1); CurrencyParameterSensitivities cpss = csens0.getTypedSensitivity(ZERO_RATE_GAMMA); assertThat(cpss.getSensitivities()).hasSize(1); CurrencyParameterSensitivity cps = cpss.getSensitivities().get(0); assertThat(cps.getParameterMetadata()).hasSize(1); assertThat(cps.getParameterMetadata().get(0)).isEqualTo(TenorDateParameterMetadata.of(date(2018, 6, 30), TENOR_1M)); }
Example 7
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_parse_list_badDayMonthTenor() { CharSource source = CharSource.wrap( "Reference,Sensitivity Tenor,Zero Rate Delta\n" + "GBP-LIBOR,P2M1D,1.0"); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source)); assertThat(test.getFailures()).hasSize(1); assertThat(test.getFailures().get(0).getReason()).isEqualTo(FailureReason.PARSING); assertThat(test.getFailures().get(0).getMessage()) .isEqualTo("CSV file could not be parsed at line 2: Invalid tenor, cannot mix years/months and days: 2M1D"); }
Example 8
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_parse_grid_neitherTenorNorDate() { CharSource source = CharSource.wrap( "Sensitivity Type,Sensitivity Tenor,Sensitivity Date,GBP\n" + "ZeroRateGamma,,,1\n"); assertThat(LOADER_DATE.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER_DATE.parse(ImmutableList.of(source)); assertThat(test.getFailures()).hasSize(1); assertThat(test.getValue().size()).isEqualTo(0); FailureItem failure0 = test.getFailures().get(0); assertThat(failure0.getReason()).isEqualTo(FailureReason.PARSING); assertThat(failure0.getMessage()).isEqualTo("CSV file could not be parsed at line 2: Unable to parse tenor or date, " + "check 'Sensitivity Tenor' and 'Sensitivity Date' columns"); }
Example 9
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_parse_grid_missingColumns() { CharSource source = CharSource.wrap( "GBP\n" + "1"); assertThat(LOADER.isKnownFormat(source)).isFalse(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source)); assertThat(test.getFailures()).hasSize(1); assertThat(test.getValue().size()).isEqualTo(0); FailureItem failure0 = test.getFailures().get(0); assertThat(failure0.getReason()).isEqualTo(FailureReason.PARSING); assertThat(failure0.getMessage()).isEqualTo("CSV file could not be parsed as sensitivities, invalid format"); }
Example 10
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_parse_grid_badTenorWithValidDateColumn() { CharSource source = CharSource.wrap( "Sensitivity Type,Sensitivity Tenor,Sensitivity Date,GBP\n" + "ZeroRateGamma,XXX,2018-06-30,1\n"); assertThat(LOADER.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source)); assertThat(test.getFailures()).hasSize(1); assertThat(test.getValue().size()).isEqualTo(0); FailureItem failure0 = test.getFailures().get(0); assertThat(failure0.getReason()).isEqualTo(FailureReason.PARSING); assertThat(failure0.getMessage()) .isEqualTo("CSV file could not be parsed at line 2: Invalid tenor 'XXX', must be expressed as nD, nW, nM or nY"); }
Example 11
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_parse_grid_allRowsBadNoEmptySensitvityCreated() { CharSource source = CharSource.wrap( "Sensitivity Type,Sensitivity Tenor,GBP\n" + "ZeroRateGamma,XX,1\n"); assertThat(LOADER.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source)); assertThat(test.getFailures()).hasSize(1); assertThat(test.getValue().size()).isEqualTo(0); FailureItem failure0 = test.getFailures().get(0); assertThat(failure0.getReason()).isEqualTo(FailureReason.PARSING); assertThat(failure0.getMessage()) .isEqualTo("CSV file could not be parsed at line 2: Invalid tenor 'XX', must be expressed as nD, nW, nM or nY"); }
Example 12
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_parse_list_unableToGetCurrency() { CharSource source = CharSource.wrap( "Reference,Sensitivity Tenor,Zero Rate Delta\n" + "X,1D,1.0"); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source)); assertThat(test.getFailures()).hasSize(1); FailureItem failure0 = test.getFailures().get(0); assertThat(failure0.getReason()).isEqualTo(FailureReason.PARSING); assertThat(failure0.getMessage()) .isEqualTo("CSV file could not be parsed at line 2: Unable to parse currency from reference, " + "consider adding a 'Currency' column"); }
Example 13
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_parse_list_allRowsBadNoEmptySensitvityCreated() { CharSource source = CharSource.wrap( "Reference,Sensitivity Tenor,ZeroRateDelta\n" + "GBP,XX,1\n"); assertThat(LOADER_DATE.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER_DATE.parse(ImmutableList.of(source)); assertThat(test.getFailures()).hasSize(1); assertThat(test.getValue().size()).isEqualTo(0); FailureItem failure0 = test.getFailures().get(0); assertThat(failure0.getReason()).isEqualTo(FailureReason.PARSING); assertThat(failure0.getMessage()) .isEqualTo("CSV file could not be parsed at line 2: Invalid tenor 'XX', must be expressed as nD, nW, nM or nY"); }
Example 14
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_parse_standard_dateInTenorColumn() { CharSource source = CharSource.wrap( "Reference,Sensitivity Type,Sensitivity Tenor,Value\n" + "GBP,ZeroRateGamma,2018-06-30,1\n"); assertThat(LOADER_DATE.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER_DATE.parse(ImmutableList.of(source)); assertThat(test.getFailures()).hasSize(1); assertThat(test.getValue().size()).isEqualTo(0); FailureItem failure0 = test.getFailures().get(0); assertThat(failure0.getReason()).isEqualTo(FailureReason.PARSING); assertThat(failure0.getMessage()) .isEqualTo("CSV file could not be parsed at line 2: Invalid tenor '2018-06-30', must be expressed as nD, nW, nM or nY"); }
Example 15
Source File: SensitivityCsvLoaderTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_parse_grid_dateButTenorRequired() { CharSource source = CharSource.wrap( "Sensitivity Type,Sensitivity Tenor,Sensitivity Date,GBP\n" + "ZeroRateGamma,,2018-06-30,1\n"); assertThat(LOADER.isKnownFormat(source)).isTrue(); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source)); assertThat(test.getFailures()).hasSize(1); assertThat(test.getValue().size()).isEqualTo(0); FailureItem failure0 = test.getFailures().get(0); assertThat(failure0.getReason()).isEqualTo(FailureReason.PARSING); assertThat(failure0.getMessage()) .isEqualTo("CSV file could not be parsed at line 2: Missing value for 'Sensitivity Tenor' column"); }
Example 16
Source File: TacKbp2017KBLoaderTest.java From tac-kbp-eal with MIT License | 4 votes |
private static TacKbp2017KBLoader.TacKbp2017KBLoading getDummyLoading() { return new TacKbp2017KBLoader.TacKbp2017KBLoading(CharSource.wrap("")); }
Example 17
Source File: XmlString.java From onos with Apache License 2.0 | 2 votes |
/** * Prettifies given XML String. * * @param xml input XML * @return prettified input or input itself is input is not well-formed */ public static CharSequence prettifyXml(CharSequence xml) { return new XmlString(CharSource.wrap(xml)); }
Example 18
Source File: CharSources.java From Strata with Apache License 2.0 | 2 votes |
/** * Obtains an instance of {@link CharSource} from a text variable, specified as a byte array. * This also takes in a specific character set, as a {@link Charset}. * * @param content the text to create a {@link CharSource} for * @param charset the charset to build the new CharSource based on * @return a new instance of {@link CharSource} */ public static CharSource ofContent(byte[] content, Charset charset) { return CharSource.wrap(new String(content, charset)); }
Example 19
Source File: CharSources.java From Strata with Apache License 2.0 | 2 votes |
/** * Obtains an instance of {@link CharSource} from a text variable, specified as a byte array. * * @param content the text to create a {@link CharSource} for * @return a new instance of {@link CharSource} with UTF-8 for charset */ public static CharSource ofContent(byte[] content) { return CharSource.wrap(new String(content, Charsets.UTF_8)); }
Example 20
Source File: CharSources.java From Strata with Apache License 2.0 | 2 votes |
/** * Obtains an instance of {@link CharSource} from a text variable, specified as a {@link String} object. * * @param content the text to create a {@link CharSource} for * @return a new instance of {@link CharSource} with UTF-8 for charset */ public static CharSource ofContent(String content) { return CharSource.wrap(content); }