/** * Create a String out of this rank one ArrayChar object. * If there is a null (0) value in the ArrayChar array, the String will end there. * The null is not returned as part of the String. * * @return String value of CharArray * @throws IllegalArgumentException if rank != 1 */ public String getString() { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.getString rank must be 1"); int strLen = indexCalc.getShape(0); int count = 0; for (int k = 0; k < strLen; k++) { if (0 == storage[k]) break; count++; } return new String(storage, 0, count); }
/** * Set the ArrayChar values from the characters in the String. Rank must be 1. * If String longer than ArrayChar, ignore extra chars; if shorter, fill with 0. * * @param val set characters from this String * @throws IllegalArgumentException if rank != 2 */ public void setString(String val) { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.setString rank must be 1"); int arrayLen = indexCalc.getShape(0); int strLen = Math.min(val.length(), arrayLen); for (int k = 0; k < strLen; k++) storage[k] = val.charAt(k); char c = 0; for (int k = strLen; k < arrayLen; k++) storage[k] = c; }
/** * Set the ArrayChar values from the characters in the String. Rank must be 1. * If String longer than ArrayChar, ignore extra chars; if shorter, fill with 0. * * @param val set characters from this String * @throws IllegalArgumentException if rank != 2 */ public void setString(String val) { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.setString rank must be 1"); int arrayLen = indexCalc.getShape(0); int strLen = Math.min(val.length(), arrayLen); for (int k = 0; k < strLen; k++) storage[k] = val.charAt(k); char c = 0; for (int k = strLen; k < arrayLen; k++) storage[k] = c; }
/** * Set the ArrayChar values from the characters in the String. Rank must be 1. * If String longer than ArrayChar, ignore extra chars; if shorter, fill with 0. * * @param val set characters from this String * @throws IllegalArgumentException if rank != 2 */ public void setString(String val) { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.setString rank must be 1"); int arrayLen = indexCalc.getShape(0); int strLen = Math.min(val.length(), arrayLen); for (int k = 0; k < strLen; k++) storage[k] = val.charAt(k); char c = 0; for (int k = strLen; k < arrayLen; k++) storage[k] = c; }
/** * Create a String out of this rank one ArrayChar object. * If there is a null (0) value in the ArrayChar array, the String will end there. * The null is not returned as part of the String. * * @return String value of CharArray * @throws IllegalArgumentException if rank != 1 */ public String getString() { int rank = getRank(); if (rank == 0) { return new String(storage); } if (rank != 1) throw new IllegalArgumentException("ArayChar.getString rank must be 1"); int strLen = indexCalc.getShape(0); int count = 0; for (int k = 0; k < strLen; k++) { if (0 == storage[k]) break; count++; } return new String(storage, 0, count); }
/** * Create a String out of this rank one ArrayChar object. * If there is a null (0) value in the ArrayChar array, the String will end there. * The null is not returned as part of the String. * * @return String value of CharArray * @throws IllegalArgumentException if rank != 1 */ public String getString() { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.getString rank must be 1"); int strLen = indexCalc.getShape(0); int count = 0; for (int k = 0; k < strLen; k++) { if (0 == storage[k]) break; count++; } return new String(storage, 0, count); }
/** * Set the ArrayChar values from the characters in the String. Rank must be 2. * This treats the ArrayChar as a 1D array of Strings. * If String val longer than ArrayChar, ignore extra chars; if shorter, fill with 0. * <p/> * <p><code> * String[] val = new String[n]; * ArrayChar ca; * Index ima = ca.getIndex(); * for (int i=0; i<n; i++) * ca.setString(i, val[i]); * </code> * * @param index index into 1D String array, must be < getShape(0). * @param val set chars from this sString */ public void setString(int index, String val) { int rank = getRank(); if (rank != 2) throw new IllegalArgumentException("ArrayChar.setString rank must be 2"); Index ima = getIndex(); setString(ima.set(index), val); }
/** * Set the ArrayChar values from the characters in the String. Rank must be 2. * This treats the ArrayChar as a 1D array of Strings. * If String val longer than ArrayChar, ignore extra chars; if shorter, fill with 0. * <p/> * <p><code> * String[] val = new String[n]; * ArrayChar ca; * Index ima = ca.getIndex(); * for (int i=0; i<n; i++) * ca.setString(i, val[i]); * </code> * * @param index index into 1D String array, must be < getShape(0). * @param val set chars from this sString */ public void setString(int index, String val) { int rank = getRank(); if (rank != 2) throw new IllegalArgumentException("ArrayChar.setString rank must be 2"); Index ima = getIndex(); setString(ima.set(index), val); }
/** * Set the ArrayChar values from the characters in the String. Rank must be 2. * This treats the ArrayChar as a 1D array of Strings. * If String val longer than ArrayChar, ignore extra chars; if shorter, fill with 0. * <p/> * <p><code> * String[] val = new String[n]; * ArrayChar ca; * Index ima = ca.getIndex(); * for (int i=0; i<n; i++) * ca.setString(i, val[i]); * </code> * * @param index index into 1D String array, must be < getShape(0). * @param val set chars from this sString */ public void setString(int index, String val) { int rank = getRank(); if (rank != 2) throw new IllegalArgumentException("ArrayChar.setString rank must be 2"); Index ima = getIndex(); setString(ima.set(index), val); }
int rank = getRank(); if (rank == 0) throw new IllegalArgumentException("ArrayChar.setString rank must not be 0");
int rank = getRank(); if (rank == 0) throw new IllegalArgumentException("ArayChar.getString rank must not be 0");
int rank = getRank(); if (rank == 0) throw new IllegalArgumentException("ArayChar.getString rank must not be 0");
/** * Make this into the equivilent 1D ArrayObject of Strings. * * @return 1D ArrayObject of Strings */ public ArrayObject make1DStringArray() { int nelems = (getRank() == 0) ? 1 : (int) getSize() / indexCalc.getShape(getRank()-1); Array sarr = Array.factory(DataType.STRING, new int[]{nelems}); IndexIterator newsiter = sarr.getIndexIterator(); ArrayChar.StringIterator siter = getStringIterator(); while (siter.hasNext()) { newsiter.setObjectNext(siter.next()); } return (ArrayObject) sarr; }
/** * Make this into the equivilent 1D ArrayObject of Strings. * * @return 1D ArrayObject of Strings */ public ArrayObject make1DStringArray() { int nelems = (getRank() == 0) ? 1 : (int) getSize() / indexCalc.getShape(getRank()-1); Array sarr = Array.factory(String.class, new int[]{nelems}); IndexIterator newsiter = sarr.getIndexIterator(); ArrayChar.StringIterator siter = getStringIterator(); while (siter.hasNext()) { newsiter.setObjectNext(siter.next()); } return (ArrayObject) sarr; }
/** * Make this into the equivilent 1D ArrayObject of Strings. * * @return 1D ArrayObject of Strings */ public ArrayObject make1DStringArray() { int nelems = (getRank() == 0) ? 1 : (int) getSize() / indexCalc.getShape(getRank()-1); Array sarr = Array.factory(String.class, new int[]{nelems}); IndexIterator newsiter = sarr.getIndexIterator(); ArrayChar.StringIterator siter = getStringIterator(); while (siter.hasNext()) { newsiter.setObjectNext(siter.next()); } return (ArrayObject) sarr; }
static void printStringArray(PrintStream out, ArrayChar ma, Indent indent, ucar.nc2.util.CancelTask ct) { if (ct != null && ct.isCancel()) return; int rank = ma.getRank(); if (rank == 1) { out.print( " \""+ma.getString()+"\""); return; } if (rank == 2) { boolean first = true; for (ArrayChar.StringIterator iter = ma.getStringIterator(); iter.hasNext(); ) { if (!first) out.print(", "); out.print( "\""+iter.next()+"\""); first = false; if (ct != null && ct.isCancel()) return; } return; } int [] dims = ma.getShape(); int last = dims[0]; out.print("\n" + indent + "{"); indent.incr(); for(int ii = 0; ii < last; ii++) { ArrayChar slice = (ArrayChar) ma.slice(0, ii); printStringArray(out, slice, indent, ct); if(ii != last-1) out.print(","); if (ct != null && ct.isCancel()) return; } indent.decr(); out.print("\n"+indent + "}"); }
static void printStringArray(PrintWriter out, ArrayChar ma, Indent indent, ucar.nc2.util.CancelTask ct) { if (ct != null && ct.isCancel()) return; int rank = ma.getRank();
static void printStringArray(PrintStream out, ArrayChar ma, Indent indent, ucar.nc2.util.CancelTask ct) { if (ct != null && ct.isCancel()) return; int rank = ma.getRank(); if (rank == 1) { out.print( " \""+ma.getString()+"\""); return; } if (rank == 2) { boolean first = true; for (ArrayChar.StringIterator iter = ma.getStringIterator(); iter.hasNext(); ) { if (!first) out.print(", "); out.print( "\""+iter.next()+"\""); first = false; if (ct != null && ct.isCancel()) return; } return; } int [] dims = ma.getShape(); int last = dims[0]; out.print("\n" + indent + "{"); indent.incr(); for(int ii = 0; ii < last; ii++) { ArrayChar slice = (ArrayChar) ma.slice(0, ii); printStringArray(out, slice, indent, ct); if(ii != last-1) out.print(","); if (ct != null && ct.isCancel()) return; } indent.decr(); out.print("\n"+indent + "}"); }
static void printStringArray(PrintWriter out, ArrayChar ma, Indent indent, ucar.nc2.util.CancelTask ct) { if (ct != null && ct.isCancel()) return; int rank = ma.getRank();
static void printStringArray(PrintWriter out, ArrayChar ma, Indent indent, ucar.nc2.util.CancelTask ct) { if (ct != null && ct.isCancel()) return; int rank = ma.getRank();