/** * Formats the int array a for printing purposes. * * @param a the int array to be formatted * @param sep the separator between the single values of the array, e.g. ',' * @return a String representing the int array a */ public static String format(int[] a, String sep) { return (a == null) ? "null" : (a.length == 0) ? "" : // formatTo(new StringBuilder(), a, sep).toString(); }
/** * Formats the double array d with ', ' as separator and 2 fraction digits. * * @param d the double array to be formatted * @return a String representing the double array d */ public static String format(double[] d) { return formatTo(new StringBuilder(), d, ", ").toString(); }
/** * Formats the double array d with the specified separator. * * @param d the double array to be formatted * @param sep the separator between the single values of the double array, * e.g. ',' * @return a String representing the double array d */ public static String format(double[] d, String sep) { if(d.length == 0) { return ""; } return formatTo(new StringBuilder(), d, sep).toString(); }
/** * Formats the double array d with the specified number format. * * @param d the double array to be formatted * @param sep the separator between the single values of the double array, * e.g. ',' * @param nf the number format to be used for formatting * @return a String representing the double array d */ public static String format(double[] d, String sep, NumberFormat nf) { if(d.length == 0) { return ""; } return formatTo(new StringBuilder(), d, sep, nf).toString(); }
/** * Formats the array of double arrays d with 'the specified separators and * fraction digits. * * @param d the double array to be formatted * @param sep1 the first separator of the outer array * @param sep2 the second separator of the inner array * @param nf the number format to use * @return a String representing the double array d */ public static String format(double[][] d, String sep1, String sep2, NumberFormat nf) { if(d.length == 0) { return ""; } StringBuilder buffer = new StringBuilder(); formatTo(buffer, d[0], sep2, nf); for(int i = 1; i < d.length; i++) { buffer.append(sep1); formatTo(buffer, d[i], sep2, nf); } return buffer.toString(); }
/** * returns String-representation of Vector. * * @param nf NumberFormat to specify output precision * @return String representation of this Matrix in precision as specified by * given NumberFormat */ public static String format(Vector m, NumberFormat nf) { StringBuilder buf = new StringBuilder(); buf.append('['); formatTo(buf, m.getArrayRef(), ", ", nf); buf.append(']'); return buf.toString(); }
/** * Serialize an object into the inline section. */ @Override public void write(TextWriterStream out, String label, int[] v) { StringBuilder buf = new StringBuilder(); if(label != null) { buf.append(label).append('='); } if(v != null) { FormatUtil.formatTo(buf, v, " "); } out.inlinePrintNoQuotes(buf.toString()); } }
/** * Serialize an object into the inline section. */ @Override public void write(TextWriterStream out, String label, double[] v) { StringBuilder buf = new StringBuilder(); if(label != null) { buf.append(label).append('='); } if(v != null) { FormatUtil.formatTo(buf, v, " "); } out.inlinePrintNoQuotes(buf.toString()); } }