/** * Called from the {@link Sender} to add information to the control packet dispatcher. * * @param publication to add to the dispatcher */ public void registerForSend(final NetworkPublication publication) { publicationBySessionAndStreamId.put(publication.sessionId(), publication.streamId(), publication); }
/** * If the specified key is not already associated with a value (or is mapped * to {@code null}), attempts to compute its value using the given mapping * function and enters it into this map unless {@code null}. * * @param keyPartA for the key * @param keyPartB for the key * @param mappingFunction creates values based upon keys if the key pair is missing * @return the newly created or stored value. */ public V computeIfAbsent(final int keyPartA, final int keyPartB, final EntryFunction<? extends V> mappingFunction) { V value = get(keyPartA, keyPartB); if (value == null) { value = mappingFunction.apply(keyPartA, keyPartB); if (value != null) { put(keyPartA, keyPartB, value); } } return value; }
@Test public void shouldIterateValues() { final Set<String> expectedSet = new HashSet<>(); final int count = 7; for (int i = 0; i < count; i++) { final String value = String.valueOf(i); expectedSet.add(value); map.put(i, i + 97, value); } final Set<String> actualSet = new HashSet<>(); map.forEach(actualSet::add); assertThat(actualSet, equalTo(expectedSet)); }
@Test public void shouldToString() { final int count = 7; for (int i = 0; i < count; i++) { final String value = String.valueOf(i); map.put(i, i + 97, value); } assertThat(map.toString(), is("{1_98=1, 3_100=3, 2_99=2, 5_102=5, 6_103=6, 4_101=4, 0_97=0}")); }
@Test public void shouldIterateEntries() { final Set<EntryCapture<String>> expectedSet = new HashSet<>(); final int count = 7; for (int i = 0; i < count; i++) { final String value = String.valueOf(i); expectedSet.add(new EntryCapture<>(i, i + 97, value)); map.put(i, i + 97, value); } final Set<EntryCapture<String>> actualSet = new HashSet<>(); map.forEach((keyPartA, keyPartB, value) -> actualSet.add(new EntryCapture<>(keyPartA, keyPartB, value))); assertThat(actualSet, equalTo(expectedSet)); }
@Test public void shouldPutAndGetKeysOfNegativeValue() { map.put(721632679, 333118496, "a"); assertThat(map.get(721632679, 333118496), is("a")); map.put(721632719, -659033725, "b"); assertThat(map.get(721632719, -659033725), is("b")); map.put(721632767, -235401032, "c"); assertThat(map.get(721632767, -235401032), is("c")); map.put(721632839, 1791470537, "d"); assertThat(map.get(721632839, 1791470537), is("d")); map.put(721633069, -939458690, "e"); assertThat(map.get(721633069, -939458690), is("e")); map.put(721633127, 1620485039, "f"); assertThat(map.get(721633127, 1620485039), is("f")); map.put(721633163, -1503337805, "g"); assertThat(map.get(721633163, -1503337805), is("g")); map.put(721633229, -2073657736, "h"); assertThat(map.get(721633229, -2073657736), is("h")); map.put(721633255, -1278969172, "i"); assertThat(map.get(721633255, -1278969172), is("i")); map.put(721633257, -1230662585, "j"); assertThat(map.get(721633257, -1230662585), is("j")); map.put(721633319, -532637417, "k"); assertThat(map.get(721633319, -532637417), is("k")); }
@Test public void shouldPutItem() { final String testValue = "Test"; final int keyPartA = 3; final int keyPartB = 7; assertNull(map.put(keyPartA, keyPartB, testValue)); assertThat(map.size(), is(1)); }
@Test public void shouldPutAndGetItem() { final String testValue = "Test"; final int keyPartA = 3; final int keyPartB = 7; assertNull(map.put(keyPartA, keyPartB, testValue)); assertThat(map.get(keyPartA, keyPartB), is(testValue)); }
@Test public void shouldRemoveItem() { final String testValue = "Test"; final int keyPartA = 3; final int keyPartB = 7; map.put(keyPartA, keyPartB, testValue); assertThat(map.remove(keyPartA, keyPartB), is(testValue)); assertNull(map.get(keyPartA, keyPartB)); }
activeRetransmitsMap.put(termId, termOffset, action);
/** * Called from the {@link Sender} to add information to the control packet dispatcher. * * @param publication to add to the dispatcher */ public void registerForSend(final NetworkPublication publication) { publicationBySessionAndStreamId.put(publication.sessionId(), publication.streamId(), publication); }
/** * Called from the {@link Sender} to add information to the control packet dispatcher. * * @param publication to add to the dispatcher */ public void registerForSend(final NetworkPublication publication) { publicationBySessionAndStreamId.put(publication.sessionId(), publication.streamId(), publication); }
/** * If the specified key is not already associated with a value (or is mapped * to {@code null}), attempts to compute its value using the given mapping * function and enters it into this map unless {@code null}. * * @param keyPartA for the key * @param keyPartB for the key * @param mappingFunction creates values based upon keys if the key pair is missing * @return the newly created or stored value. */ public V computeIfAbsent(final int keyPartA, final int keyPartB, final EntryFunction<? extends V> mappingFunction) { V value = get(keyPartA, keyPartB); if (value == null) { value = mappingFunction.apply(keyPartA, keyPartB); if (value != null) { put(keyPartA, keyPartB, value); } } return value; }
/** * If the specified key is not already associated with a value (or is mapped * to {@code null}), attempts to compute its value using the given mapping * function and enters it into this map unless {@code null}. * * @param keyPartA for the key * @param keyPartB for the key * @param mappingFunction creates values based upon keys if the key pair is missing * @return the newly created or stored value. */ public V computeIfAbsent(final int keyPartA, final int keyPartB, final EntryFunction<? extends V> mappingFunction) { V value = get(keyPartA, keyPartB); if (value == null) { value = mappingFunction.apply(keyPartA, keyPartB); if (value != null) { put(keyPartA, keyPartB, value); } } return value; }
activeRetransmitsMap.put(termId, termOffset, action);
activeRetransmitsMap.put(termId, termOffset, action);