/** * Make an array of int elements from an array of String objects. * If the String can't be parsed as a number, it will be set to zero. * <p/> * String s[] = { "1", "300", "44" }; * int numbers[] = parseInt(s); * <p/> * numbers will contain { 1, 300, 44 } */ static public int[] parseInt(String what[]) { return parseInt(what, 0); }
/** * Make an array of int elements from an array of String objects. * If the String can't be parsed as a number, it will be set to zero. * * String s[] = { "1", "300", "44" }; * int numbers[] = parseInt(s); * * numbers will contain { 1, 300, 44 } */ static public int[] parseInt(String what[]) { return parseInt(what, 0); }
/** * Parse a String into an int value. Returns 0 if the value is bad. */ static final public int parseInt(String what) { return parseInt(what, 0); }
/** * Parse a String into an int value. Returns 0 if the value is bad. */ static final public int parseInt(String what) { return parseInt(what, 0); }
/** * @param defaultValue the default value of the attribute */ public int getIntContent(int defaultValue) { return PApplet.parseInt(node.getTextContent(), defaultValue); }
/** * @param defaultValue the default value of the attribute */ public int getIntContent(int defaultValue) { return PApplet.parseInt(node.getTextContent(), defaultValue); }
static protected int parseRGB(String what) { int leftParen = what.indexOf('(') + 1; int rightParen = what.indexOf(')'); String sub = what.substring(leftParen, rightParen); int[] values = PApplet.parseInt(PApplet.splitTokens(sub, ", ")); return (values[0] << 16) | (values[1] << 8) | (values[2]); }
/** * Construct an IntList from a random pile of objects. * Un-parseable or null values will be set to zero. */ public IntList(Object... items) { final int missingValue = 0; // nuts, can't be last/final/second arg count = items.length; data = new int[count]; int index = 0; for (Object o : items) { int value = missingValue; if (o != null) { if (o instanceof Number) { value = ((Number) o).intValue(); } else { value = PApplet.parseInt(o.toString().trim(), missingValue); } } data[index++] = value; } }
private static boolean hasBadSize(SurfaceInfo surfaceInfo) { String width = getPrivateSurfaceInfoField(surfaceInfo, "width", String.class); String height = getPrivateSurfaceInfoField(surfaceInfo, "height", String.class); if (width == null || height == null) { return true; } if (!width.equals("displayWidth") && !width.equals("displayHeight") && PApplet.parseInt(width, -1) == -1) { return true; } if (!height.equals("displayWidth") && !height.equals("displayHeight") && PApplet.parseInt(height, -1) == -1) { return true; } return false; }
public boolean write(PrintWriter output, String options) { int indentFactor = 2; if (options != null) { String[] opts = PApplet.split(options, ','); for (String opt : opts) { if (opt.equals("compact")) { indentFactor = -1; } else if (opt.startsWith("indent=")) { indentFactor = PApplet.parseInt(opt.substring(7), -2); if (indentFactor == -2) { throw new IllegalArgumentException("Could not read a number from " + opt); } } else { System.err.println("Ignoring " + opt); } } } output.print(format(indentFactor)); output.flush(); return true; }
public boolean write(PrintWriter output, String options) { int indentFactor = 2; if (options != null) { String[] opts = PApplet.split(options, ','); for (String opt : opts) { if (opt.equals("compact")) { indentFactor = -1; } else if (opt.startsWith("indent=")) { indentFactor = PApplet.parseInt(opt.substring(7), -2); if (indentFactor == -2) { throw new IllegalArgumentException("Could not read a number from " + opt); } } else { System.err.println("Ignoring " + opt); } } } output.print(format(indentFactor)); output.flush(); return true; }
/** * Read a set of entries from a Reader that has each key/value pair on * a single line, separated by a tab. * * @nowebref */ public IntDict(BufferedReader reader) { String[] lines = PApplet.loadStrings(reader); keys = new String[lines.length]; values = new int[lines.length]; for (int i = 0; i < lines.length; i++) { String[] pieces = PApplet.split(lines[i], '\t'); if (pieces.length == 2) { keys[count] = pieces[0]; values[count] = PApplet.parseInt(pieces[1]); indices.put(pieces[0], count); count++; } } }
class AsyncImageLoader extends Thread { String filename; String extension; PImage vessel; public AsyncImageLoader(String filename, String extension, PImage vessel) { // Give these threads distinct name so we can check whether we are loading // on the main/background thread; for now they are all named the same super(ASYNC_IMAGE_LOADER_THREAD_PREFIX); this.filename = filename; this.extension = extension; this.vessel = vessel; } @Override public void run() { while (requestImageCount == requestImageMax) { try { Thread.sleep(10); } catch (InterruptedException e) { } } requestImageCount++; PImage actual = loadImage(filename, extension); // An error message should have already printed if (actual == null) { vessel.width = -1; vessel.height = -1;
static protected int parseRGB(String what) { int leftParen = what.indexOf('(') + 1; int rightParen = what.indexOf(')'); String sub = what.substring(leftParen, rightParen); String[] values = PApplet.splitTokens(sub, ", "); int rgbValue = 0; if (values.length == 3) { // Color spec allows for rgb values to be percentages. for (int i = 0; i < 3; i++) { rgbValue <<= 8; if (values[i].endsWith("%")) { rgbValue |= (int)(PApplet.constrain(255*parseFloatOrPercent(values[i]), 0, 255)); } else { rgbValue |= PApplet.constrain(PApplet.parseInt(values[i]), 0, 255); } } } else System.err.println("Could not read color \"" + what + "\"."); return rgbValue; }
/** * @webref table:method * @brief Get an integer value from the specified row and column * @param row ID number of the row to reference * @param column ID number of the column to reference * @see Table#getFloat(int, int) * @see Table#getString(int, int) * @see Table#getStringColumn(String) * @see Table#setInt(int, int, int) * @see Table#setFloat(int, int, float) * @see Table#setString(int, int, String) */ public int getInt(int row, int column) { checkBounds(row, column); if (columnTypes[column] == INT || columnTypes[column] == CATEGORY) { int[] intData = (int[]) columns[column]; return intData[row]; } String str = getString(row, column); return (str == null || str.equals(missingString)) ? missingInt : PApplet.parseInt(str, missingInt); }
/** * @webref table:method * @brief Get an integer value from the specified row and column * @param row ID number of the row to reference * @param column ID number of the column to reference * @see Table#getFloat(int, int) * @see Table#getString(int, int) * @see Table#getStringColumn(String) * @see Table#setInt(int, int, int) * @see Table#setFloat(int, int, float) * @see Table#setString(int, int, String) */ public int getInt(int row, int column) { checkBounds(row, column); if (columnTypes[column] == INT || columnTypes[column] == CATEGORY) { int[] intData = (int[]) columns[column]; return intData[row]; } String str = getString(row, column); return (str == null || str.equals(missingString)) ? missingInt : PApplet.parseInt(str, missingInt); }
static public String[] parseSketchSmooth(String code, boolean fussy, Context context) { String[] matches = PApplet.match(scrubComments(code), SMOOTH_REGEX); if (matches != null) { boolean badSmooth = false; if (PApplet.parseInt(matches[1], -1) == -1) { badSmooth = true; } if (badSmooth && fussy) { // found a reference to smooth, but it didn't seem to contain numbers // final String message = // "The smooth level of this applet could not automatically\n" + // "be determined from your code. Use only a numeric\n" + // "value (not variables) for the smooth() command.\n" + // "See the smooth() reference for an explanation."; // Messages.showWarning("Could not find smooth level", message, null); showWarning(context.getResources().getString(R.string.preproc_no_smooth), context.getResources().getString(R.string.preproc_no_smooth_message)); // new Exception().printStackTrace(System.out); return null; } return matches; } return new String[] { null, null }; // not an error, just empty }
/** * Construct an IntList from an iterable pile of objects. * For instance, a float array, an array of strings, who knows). * Un-parseable or null values will be set to 0. * @nowebref */ public IntList(Iterable<Object> iter) { this(10); for (Object o : iter) { if (o == null) { append(0); // missing value default } else if (o instanceof Number) { append(((Number) o).intValue()); } else { append(PApplet.parseInt(o.toString().trim())); } } crop(); }
/** * Read a set of entries from a Reader that has each key/value pair on * a single line, separated by a tab. * * @nowebref */ public IntDict(BufferedReader reader) { // public IntHash(PApplet parent, String filename) { String[] lines = PApplet.loadStrings(reader); keys = new String[lines.length]; values = new int[lines.length]; // boolean csv = (lines[0].indexOf('\t') == -1); for (int i = 0; i < lines.length; i++) { // String[] pieces = csv ? Table.splitLineCSV(lines[i]) : PApplet.split(lines[i], '\t'); String[] pieces = PApplet.split(lines[i], '\t'); if (pieces.length == 2) { keys[count] = pieces[0]; values[count] = PApplet.parseInt(pieces[1]); count++; } } }
int[] viewBox = PApplet.parseInt(PApplet.splitTokens(viewBoxStr)); width = viewBox[2]; height = viewBox[3];