private static short parseHextet(String ipPart) { // Note: we already verified that this string contains only hex digits. int hextet = Integer.parseInt(ipPart, 16); if (hextet > 0xffff) { throw new NumberFormatException(); } return (short) hextet; }
private static byte parseOctet(String ipPart) { // Note: we already verified that this string contains only hex digits. int octet = Integer.parseInt(ipPart); // Disallow leading zeroes, because no clear standard exists on // whether these should be interpreted as decimal or octal. if (octet > 255 || (ipPart.startsWith("0") && ipPart.length() > 1)) { throw new NumberFormatException(); } return (byte) octet; }
private static int parsePort(String input, int pos, int limit) { try { // Canonicalize the port string to skip '\n' etc. String portString = canonicalize(input, pos, limit, "", false, false, false, true, null); int i = Integer.parseInt(portString); if (i > 0 && i <= 65535) return i; return -1; } catch (NumberFormatException e) { return -1; // Invalid port. } } }
@Override public void parse(CacheBuilderSpec spec, String key, String value) { checkArgument(value != null && !value.isEmpty(), "value of key %s omitted", key); try { parseInteger(spec, Integer.parseInt(value)); } catch (NumberFormatException e) { throw new IllegalArgumentException( format("key %s value set to %s, must be integer", key, value), e); } } }
@Override public Integer apply(String input) { return Integer.parseInt(input); } };
@Override public Integer convert(String source) { return Integer.parseInt(source); } }
@Override public void onNext(String v) { int num = Integer.parseInt(v); System.out.println(num); // doSomething(num); count.incrementAndGet(); }
@Override public void onNext(String v) { int num = Integer.parseInt(v); System.out.println(num); // doSomething(num); count.incrementAndGet(); }
@Override public void onNext(String v) { int num = Integer.parseInt(v); System.out.println(num); // doSomething(num); count.incrementAndGet(); }
@Override public void onNext(String v) { int num = Integer.parseInt(v); System.out.println(num); // doSomething(num); count.incrementAndGet(); }
@Override public void onNext(String v) { int num = Integer.parseInt(v); System.out.println(num); // doSomething(num); count.incrementAndGet(); }
@Override public void onNext(String v) { int num = Integer.parseInt(v); System.out.println(num); // doSomething(num); count.incrementAndGet(); }
@Override public Integer load(String key) { wasCalled = true; return valuePrefix + Integer.parseInt(key.substring(keyPrefix.length())); } }
private void adaptForwardedHost(String hostToUse) { int portSeparatorIdx = hostToUse.lastIndexOf(':'); if (portSeparatorIdx > hostToUse.lastIndexOf(']')) { host(hostToUse.substring(0, portSeparatorIdx)); port(Integer.parseInt(hostToUse.substring(portSeparatorIdx + 1))); } else { host(hostToUse); port(null); } }
/** * Computes the mean in a way that is obvious and resilient to overflow by using BigInteger * arithmetic. */ private static int computeMeanSafely(int x, int y) { BigInteger bigX = BigInteger.valueOf(x); BigInteger bigY = BigInteger.valueOf(y); BigDecimal bigMean = new BigDecimal(bigX.add(bigY)).divide(BigDecimal.valueOf(2), BigDecimal.ROUND_FLOOR); // parseInt blows up on overflow as opposed to intValue() which does not. return Integer.parseInt(bigMean.toString()); }
@Override public void setAsText(String text) { setValue(new Integer(Integer.parseInt(text) + 1)); } });
private int nextReferredCharacterId() throws IOException { String reference = nextWordToken(); if (reference != null && reference.startsWith("&#") && reference.endsWith(";")) { return Integer.parseInt(reference.substring(2, reference.length() - 1)); } return -1; }
@Override public TestBean parse(String text, Locale locale) throws ParseException { TestBean object = new TestBean(); object.setSpecialInt(Integer.parseInt(text)); return object; } }
@Override public void setAsText(String text) { TestBean tb = new TestBean(); StringTokenizer st = new StringTokenizer(text, "_"); tb.setName(st.nextToken()); tb.setAge(Integer.parseInt(st.nextToken())); setValue(tb); } }
@Override public void setAsText(String text) { TestBean tb = new TestBean(); StringTokenizer st = new StringTokenizer(text, "_"); tb.setName(st.nextToken()); tb.setAge(Integer.parseInt(st.nextToken())); setValue(tb); } }