/** * Writes the curve groups definition in a CSV format to an appendable. * * @param underlying the underlying appendable destination * @param groups the curve groups */ public static void writeCurveGroupDefinition(Appendable underlying, RatesCurveGroupDefinition... groups) { CsvOutput csv = CsvOutput.standard(underlying); csv.writeLine(HEADERS); for (RatesCurveGroupDefinition group : groups) { writeCurveGroupDefinition(csv, group); } }
/** * Writes the curve group in a CSV format to an appendable. * * @param underlying the underlying appendable destination * @param groups the curve groups */ public static void writeCurveGroup(Appendable underlying, RatesCurveGroup... groups) { CsvOutput csv = CsvOutput.standard(underlying); csv.writeLine(HEADERS); for (RatesCurveGroup group : groups) { writeCurveGroup(csv, group); } }
public void test_standard_writeLines_alwaysQuote() { List<List<String>> rows = Arrays.asList(Arrays.asList("a", "x"), Arrays.asList("b", "y")); StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n").writeLines(rows, true); assertEquals(buf.toString(), "\"a\",\"x\"\n\"b\",\"y\"\n"); }
public void test_standard_writeLines_tab_separated() { StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n", LINE_ITEM_SEP_TAB).writeLine(Arrays.asList("a", "1,000")); assertEquals(buf.toString(), "a\t\"1,000\"\n"); }
public void test_standard_expressionPrefix() { StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n").writeLine(Arrays.asList("=cmd", "+cmd", "-cmd", "@cmd", "")); assertEquals(buf.toString(), "\"=cmd\",+cmd,-cmd,\"@cmd\",\n"); }
public void test_standard_expressionPrefixNumbers() { StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n").writeLine(Arrays.asList("+8", "-7", "+8-7", "-7+8", "NaN", "-Infinity")); assertEquals(buf.toString(), "+8,-7,+8-7,-7+8,NaN,-Infinity\n"); }
public void test_standard_writeLines_selectiveQuote_commaAndQuote() { List<List<String>> rows = Arrays.asList(Arrays.asList("a", "1,000"), Arrays.asList("b\"c", "y")); StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n", LINE_ITEM_SEP_COMMA).writeLines(rows, false); assertEquals(buf.toString(), "a,\"1,000\"\n\"b\"\"c\",y\n"); }
public void test_standard_writeLine_selectiveQuote() { StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n", LINE_ITEM_SEP_COMMA).writeLine(Arrays.asList("a", "1,000")); assertEquals(buf.toString(), "a,\"1,000\"\n"); }
public void test_standard_writeLines_selectiveQuote_trimmable() { List<List<String>> rows = Arrays.asList(Arrays.asList("a", " x"), Arrays.asList("b ", "y")); StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n", LINE_ITEM_SEP_COMMA).writeLines(rows, false); assertEquals(buf.toString(), "a,\" x\"\n\"b \",y\n"); }
public void test_standard_writeLines_systemNewLine() { List<List<String>> rows = Arrays.asList(Arrays.asList("a", "x"), Arrays.asList("b", "y")); StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf).writeLines(rows, false); assertEquals(buf.toString(), "a,x" + LINE_SEP + "b,y" + LINE_SEP); }
/** * Writes the curve nodes in a CSV format to an appendable. * * @param underlying the underlying appendable destination * @param valuationDate the valuation date * @param group the curve group */ public static void writeCurveNodes(Appendable underlying, LocalDate valuationDate, RatesCurveGroup group) { CsvOutput csv = CsvOutput.standard(underlying); // header csv.writeLine(HEADERS_NODES); // rows String valuationDateStr = valuationDate.toString(); Map<Currency, Curve> discountingCurves = group.getDiscountCurves(); Set<CurveName> names = new HashSet<>(); for (Entry<Currency, Curve> entry : discountingCurves.entrySet()) { Curve curve = entry.getValue(); nodeLines(valuationDateStr, curve, csv); names.add(curve.getName()); } Map<Index, Curve> forwardCurves = group.getForwardCurves(); for (Entry<Index, Curve> entry : forwardCurves.entrySet()) { Curve curve = entry.getValue(); if (!names.contains(curve.getName())) { nodeLines(valuationDateStr, curve, csv); names.add(curve.getName()); } } }
/** * Writes the curve settings in a CSV format to an appendable. * * @param underlying the underlying appendable destination * @param group the curve group */ public static void writeCurveSettings(Appendable underlying, RatesCurveGroup group) { CsvOutput csv = CsvOutput.standard(underlying); // header csv.writeLine(HEADERS_SETTINGS); // rows Map<Currency, Curve> discountingCurves = group.getDiscountCurves(); Set<CurveName> names = new HashSet<>(); for (Entry<Currency, Curve> entry : discountingCurves.entrySet()) { Curve curve = entry.getValue(); csv.writeLine(curveSettings(curve)); names.add(curve.getName()); } Map<Index, Curve> forwardCurves = group.getForwardCurves(); for (Entry<Index, Curve> entry : forwardCurves.entrySet()) { Curve curve = entry.getValue(); if (!names.contains(curve.getName())) { csv.writeLine(curveSettings(curve)); names.add(curve.getName()); } } }
public void test_mixed() { List<String> row = Arrays.asList("x", "y"); StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n") .writeCell("a") .writeCell("b") .writeLine(row); assertEquals(buf.toString(), "a,b,x,y\n"); }
public void test_writeCell() { StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n") .writeCell("a") .writeCell("x") .writeNewLine() .writeCell("b", true) .writeCell("y", true) .writeNewLine(); assertEquals(buf.toString(), "a,x\n\"b\",\"y\"\n"); }
CsvOutput csv = CsvOutput.standard(output, "\n"); List<String> additionalHeaders = supplier.headers(curveSens);
public void test_exception() { Appendable throwingAppendable = new Appendable() { @Override public Appendable append(CharSequence csq, int start, int end) throws IOException { throw new IOException(); } @Override public Appendable append(char c) throws IOException { throw new IOException(); } @Override public Appendable append(CharSequence csq) throws IOException { throw new IOException(); } }; CsvOutput output = CsvOutput.standard(throwingAppendable, "\n"); assertThrows(UncheckedIOException.class, () -> output.writeCell("a")); assertThrows(UncheckedIOException.class, () -> output.writeNewLine()); }