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; }
@Override public String toString() { return Integer.toString(value); } }
private int retryAfter(Response userResponse, int defaultDelay) { String header = userResponse.header("Retry-After"); if (header == null) { return defaultDelay; } // https://tools.ietf.org/html/rfc7231#section-7.1.3 // currently ignores a HTTP-date, and assumes any non int 0 is a delay if (header.matches("\\d+")) { return Integer.valueOf(header); } return Integer.MAX_VALUE; }
@Test public void testSynchronousNext() { assertEquals(1, BehaviorProcessor.createDefault(1).take(1).blockingSingle().intValue()); assertEquals(2, BehaviorProcessor.createDefault(2).blockingIterable().iterator().next().intValue()); assertEquals(3, BehaviorProcessor.createDefault(3).blockingNext().iterator().next().intValue()); }
@Override public WeakReference<Object> call() { WeakReference<Object> wr = new FinalizableWeakReference<Object>(new Integer(23), frq) { @Override public void finalizeReferent() { finalized.release(); } }; return wr; } }
@Test public void testCustomNumberEditorWithHex() { CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false); editor.setAsText("0x" + Integer.toHexString(64)); assertEquals(new Integer(64), editor.getValue()); }
/** * Return a hex String form of an object's identity hash code. * @param obj the object * @return the object's identity code in hex notation */ public static String getIdentityHexString(Object obj) { return Integer.toHexString(System.identityHashCode(obj)); }
public void testToStringLenient_oneIntegerField() { String toTest = MoreObjects.toStringHelper(new TestClass()).add("field1", new Integer(42)).toString(); assertTrue(toTest, toTest.matches(".*\\{field1\\=42\\}")); }
/** * Build an identification String for the given {@link DataSource}, * primarily for logging purposes. * @param dataSource the {@code DataSource} to introspect * @return the identification String */ private String identify(DataSource dataSource) { return dataSource.getClass().getName() + '@' + Integer.toHexString(dataSource.hashCode()); }
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; }
@Override public Integer apply(String from) { return Integer.valueOf(from); } });
@Override public String apply(Integer v) throws Exception { return v.toString(); } }).test().assertResult("1");
@Test public void testSynchronousNext() { assertEquals(1, BehaviorProcessor.createDefault(1).take(1).blockingSingle().intValue()); assertEquals(2, BehaviorProcessor.createDefault(2).blockingIterable().iterator().next().intValue()); assertEquals(3, BehaviorProcessor.createDefault(3).blockingNext().iterator().next().intValue()); }
public void testLeastOfIterator_ties() { Integer foo = new Integer(Integer.MAX_VALUE - 10); Integer bar = new Integer(Integer.MAX_VALUE - 10); assertNotSame(foo, bar); assertEquals(foo, bar); List<Integer> list = Arrays.asList(3, foo, bar, -1); List<Integer> result = numberOrdering.leastOf(list.iterator(), list.size()); assertEquals(ImmutableList.of(-1, 3, foo, bar), result); }
private static @Nullable String convertDottedQuadToHex(String ipString) { int lastColon = ipString.lastIndexOf(':'); String initialPart = ipString.substring(0, lastColon + 1); String dottedQuad = ipString.substring(lastColon + 1); byte[] quad = textToNumericFormatV4(dottedQuad); if (quad == null) { return null; } String penultimate = Integer.toHexString(((quad[0] & 0xff) << 8) | (quad[1] & 0xff)); String ultimate = Integer.toHexString(((quad[2] & 0xff) << 8) | (quad[3] & 0xff)); return initialPart + penultimate + ":" + ultimate; }
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. } } }