1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | package Torello.Java; import Torello.Java.Function.IntDoubleFunction; class Double1D { static String toCSV (double[] arr, int sPos, int ePos, IntDoubleFunction<String> toString, Integer maxLength) { LV l = new LV(sPos, ePos, arr); StringBuilder sb = new StringBuilder(); int i = l.start; String s; if (toString == null) { sb.append(arr[i++]); while (i < l.end) sb.append(", " + arr[i++]); } else { for (; i < l.end; i++) if ((s = toString.apply(i, arr[i])).length() > 0) { sb.append(s); break; } for (i++; i < l.end; i++) if ((s = toString.apply(i, arr[i])) == null) StrCSV.throwNPE(i, arr[i]); else sb.append(", " + s); } if ((maxLength != null) && (sb.length() > maxLength.intValue())) { sb.setLength(maxLength - 4); sb.append(" ..."); return sb.toString(); } return sb.toString(); } } |