/** * Get the optional int value associated with an index. * The defaultValue is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number. * @param index The index must be between 0 and length() - 1. * @param defaultValue The default value. * @return The value. */ public int optInt(int index, int defaultValue) { try { return getInt(index); } catch (Exception e) { return defaultValue; } }
/** * Get the optional int value associated with an index. * The defaultValue is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number. * @param index The index must be between 0 and length() - 1. * @param defaultValue The default value. * @return The value. */ public int optInt(int index, int defaultValue) { try { return getInt(index); } catch (Exception e) { return defaultValue; } }
@Override public void setFieldFromJSON(GPOMutable gpo, String field, JSONArray jo, int index) { int val; try { val = jo.getInt(index); } catch (JSONException ex) { throw new IllegalArgumentException("The key " + field + " does not have a valid int value.", ex); } gpo.setField(field, val); }
@Override public void setFieldFromJSON(GPOMutable gpo, String field, JSONArray jo, int index) { int val; try { val = jo.getInt(index); } catch (JSONException ex) { throw new IllegalArgumentException("The key " + field + " does not have a valid short value.", ex); } if (val < (int)Short.MIN_VALUE) { throw new IllegalArgumentException("The key " + field + " has a value " + val + " which is too small to fit into a short."); } if (val > (int)Short.MAX_VALUE) { throw new IllegalArgumentException("The key " + field + " has a value " + val + " which is too large to fit into a short."); } gpo.setField(field, (short)val); }
@Override public void setFieldFromJSON(GPOMutable gpo, String field, JSONArray jo, int index) { int val; try { val = jo.getInt(index); } catch (JSONException ex) { throw new IllegalArgumentException("The key " + field + " does not have a valid byte value.", ex); } if (val < (int)Byte.MIN_VALUE) { throw new IllegalArgumentException("The key " + field + " has a value " + val + " which is too small to fit into a byte."); } if (val > (int)Byte.MAX_VALUE) { throw new IllegalArgumentException("The key " + field + " has a value " + val + " which is too larg to fit into a byte."); } gpo.setField(field, (byte)val); }
intVal = ja.getInt(index); } catch (JSONException ex) { throw new IllegalArgumentException("The index " + index + " does not have a valid " + type + " value.", ex);
@Override public IntCollection getMatchingPartitions(String graphId, URI locationToMatch) { if (graphId == null) { throw new IllegalArgumentException(); } if (locationToMatch == null) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId).queryParam(NameNodeServer.GET_GRAPH_PARTITIONS_LOCATIONTOMATCH_QP, locationToMatch.toString()); ClientResponse response = r.get(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { JSONArray array = response.getEntity(JSONArray.class); IntArrayList partitions = new IntArrayList(array.length()); try { for (int i = 0; i < array.length(); i++) { partitions.add(array.getInt(i)); } } catch (JSONException e) { throw new IllegalStateException(e); } return partitions; } else if (Status.NOT_FOUND.equals(status)) { return null; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
@Override public IntCollection getPartitions(String graphId) { if (graphId == null) { throw new IllegalArgumentException(); } WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId); ClientResponse response = r.get(ClientResponse.class); Status status = response.getClientResponseStatus(); if (Status.OK.equals(status)) { JSONArray array = response.getEntity(JSONArray.class); IntArrayList partitions = new IntArrayList(array.length()); try { for (int i = 0; i < array.length(); i++) { partitions.add(array.getInt(i)); } } catch (JSONException e) { throw new IllegalStateException(e); } return partitions; } else if (Status.NOT_FOUND.equals(status)) { return null; } else if (Status.BAD_REQUEST.equals(status)) { throw new IllegalArgumentException(response.getEntity(String.class)); } throw new RuntimeException(status.toString()); }
JSONArray dateArray = dateParts.getJSONArray(0); publicationDate.setYear(new Year(dateArray.getInt(0))); publicationDate.setMonth(new Month(dateArray.getInt(1))); publicationDate.setDay(new Day(dateArray.getInt(2))); } catch (JSONException e) { int day = 0; if (date.length() > 0 && !JSONObject.NULL.equals(date.get(0))) { year = date.getInt(0); month = date.getInt(1); day = date.getInt(2);
private boolean sameScalar(ScalarValue want, JSONArray parent, int index) throws Exception { trace("comparing array scalar element " + index); String regexp = want.getRegexp(); if (want instanceof StringValue) { return sameString(((StringValue) want).getValue(), regexp, parent.getString(index)); } if (want instanceof LongValue) { return sameString(longToString(((LongValue) want).getValue()), regexp, longToString(parent.getLong(index))); } if (want instanceof IntValue) { return sameString(intToString(((IntValue) want).getValue()), regexp, intToString(parent.getInt(index))); } if (want instanceof DoubleValue) { return sameString(doubleToString(((DoubleValue) want).getValue()), regexp, doubleToString(parent.getDouble(index))); } if (want instanceof BooleanValue) { return sameString(booleanToString(((BooleanValue) want).getValue()), regexp, booleanToString(parent.getBoolean(index))); } throw new AssertionError(want + " is not a valid scalar type. Valid types are string, long, int, double, boolean"); }
count = 1; }else { count = params.getInt(0); try { if(params.length() == 1) { limit = params.getInt(0); }else if(params.length() == 2) { limit = params.getInt(0); try { confirm = params.getInt(1); }catch (Exception e) { address = params.getString(1); limit = params.getInt(0); confirm = params.getInt(1); address = params.getString(2);