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; }
@Override public Integer apply(String from) { return Integer.valueOf(from); } });
@Override public Integer apply(String from) { return Integer.valueOf(from); } });
@Override public Integer apply(String from) { return Integer.valueOf(from); } }
@Override public Integer apply(String from) { return Integer.valueOf(from); } });
@Override public Integer apply(String from) { return Integer.valueOf(from); } });
public void testPutAll() { Cache<Integer, Integer> cache = CacheBuilder.newBuilder().build(); cache.putAll(ImmutableMap.of(10, 20, 30, 50, 60, 90)); assertEquals(Integer.valueOf(20), cache.getIfPresent(10)); assertEquals(Integer.valueOf(50), cache.getIfPresent(30)); assertEquals(Integer.valueOf(90), cache.getIfPresent(60)); cache.asMap().putAll(ImmutableMap.of(10, 50, 30, 20, 60, 70, 5, 5)); assertEquals(Integer.valueOf(50), cache.getIfPresent(10)); assertEquals(Integer.valueOf(20), cache.getIfPresent(30)); assertEquals(Integer.valueOf(70), cache.getIfPresent(60)); assertEquals(Integer.valueOf(5), cache.getIfPresent(5)); }
public void testCompare() { for (int x : VALUES) { for (int y : VALUES) { // note: spec requires only that the sign is the same assertEquals(x + ", " + y, Integer.valueOf(x).compareTo(y), Ints.compare(x, y)); } } }
public void testBiMapEntrySetIteratorRemove() { BiMap<Integer, String> map = HashBiMap.create(); map.put(1, "one"); Set<Entry<Integer, String>> entries = map.entrySet(); Iterator<Entry<Integer, String>> iterator = entries.iterator(); Entry<Integer, String> entry = iterator.next(); entry.setValue("two"); // changes the iterator's current entry value assertEquals("two", map.get(1)); assertEquals(Integer.valueOf(1), map.inverse().get("two")); iterator.remove(); // removes the updated entry assertTrue(map.isEmpty()); }
public void testAsMapWritesThrough() { Set<String> strings = Sets.newLinkedHashSet(); Collections.addAll(strings, "one", "two", "three"); Map<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(3), map.remove("two")); assertThat(strings).containsExactly("one", "three").inOrder(); }
public void testNewBuilder() { CacheLoader<Object, Integer> loader = constantLoader(1); LoadingCache<String, Integer> cache = CacheBuilder.newBuilder().removalListener(countingRemovalListener()).build(loader); assertEquals(Integer.valueOf(1), cache.getUnchecked("one")); assertEquals(1, cache.size()); }
public void testAsMap() { Set<String> strings = ImmutableSet.of("one", "two", "three"); Map<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(5), map.get("three")); assertNull(map.get("five")); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("two", 3), mapEntry("three", 5)) .inOrder(); }
@GwtIncompatible // NavigableMap public void testAsMapNavigableWritesThrough() { NavigableSet<String> strings = Sets.newTreeSet(); Collections.addAll(strings, "one", "two", "three"); NavigableMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(3), map.remove("two")); assertThat(strings).containsExactly("one", "three").inOrder(); assertEquals(mapEntry("three", 5), map.subMap("one", false, "zzz", true).pollLastEntry()); assertThat(strings).contains("one"); }
@Test public void hashCodeIsTheInner() { Notification<Integer> n1 = Notification.createOnNext(1337); assertEquals(Integer.valueOf(1337).hashCode(), n1.hashCode()); assertEquals(0, Notification.createOnComplete().hashCode()); }
@Test public void normal() { TestResourceSingleObserver<Integer> rso = new TestResourceSingleObserver<Integer>(); assertFalse(rso.isDisposed()); assertEquals(0, rso.start); assertNull(rso.value); assertTrue(rso.errors.isEmpty()); Single.just(1).subscribe(rso); assertTrue(rso.isDisposed()); assertEquals(1, rso.start); assertEquals(Integer.valueOf(1), rso.value); assertTrue(rso.errors.isEmpty()); }
public void testGetLargeRangeMap() { ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder(); for (int i = 0; i < 100; i++) { builder.put(Range.closedOpen(i, i + 1), i); } ImmutableRangeMap<Integer, Integer> map = builder.build(); for (int i = 0; i < 100; i++) { assertEquals(Integer.valueOf(i), map.get(i)); } }
public void testReplaceConditional() { TestMap map = new TestMap(); map.put("foo", 1); assertFalse(map.replace("foo", 2, 3)); assertFalse(map.replace("bar", 1, 2)); assertEquals(Integer.valueOf(1), map.get("foo")); assertFalse(map.containsKey("bar")); assertTrue(map.replace("foo", 1, 4)); assertEquals(Integer.valueOf(4), map.get("foo")); } }
@GwtIncompatible // SerializableTester public void testSerialization() { ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2)); ImmutableBiMap<String, Integer> copy = SerializableTester.reserializeAndAssert(bimap); assertEquals(Integer.valueOf(1), copy.get("one")); assertEquals("one", copy.inverse().get(1)); assertSame(copy, copy.inverse().inverse()); }
public void testRemove() { TestMap map = new TestMap(); map.put("foo", 1); assertFalse(map.remove("foo", 2)); assertFalse(map.remove("bar", 1)); assertEquals(Integer.valueOf(1), map.get("foo")); assertTrue(map.remove("foo", 1)); assertTrue(map.isEmpty()); }