@Test public void containsValuesAddedFromDisjointSetPrimitive() { addTwoElements(testSet); final IntHashSet disjoint = new IntHashSet(100); disjoint.add(2); disjoint.add(1002); assertTrue(testSet.addAll(disjoint)); assertTrue(testSet.contains(1)); assertTrue(testSet.contains(1001)); assertTrue(testSet.containsAll(disjoint)); }
@Test public void chainCompactionShouldNotCauseElementsToBeMovedBeforeTheirHash() { final IntHashSet requiredFields = new IntHashSet(14); requiredFields.add(8); requiredFields.add(9); requiredFields.add(35); requiredFields.add(49); requiredFields.add(56); assertTrue("Failed to remove 8", requiredFields.remove(8)); assertTrue("Failed to remove 9", requiredFields.remove(9)); assertThat(requiredFields, containsInAnyOrder(35, 49, 56)); }
public void removeSubscription(final int streamId, final int sessionId) { final StreamInterest streamInterest = streamInterestByIdMap.get(streamId); if (null == streamInterest) { throw new UnknownSubscriptionException("No subscription registered on stream " + streamId); } final SessionInterest sessionInterest = streamInterest.sessionInterestByIdMap.remove(sessionId); if (null != sessionInterest && null != sessionInterest.image) { sessionInterest.image.ifActiveGoInactive(); } streamInterest.subscribedSessionIds.remove(sessionId); if (!streamInterest.isForAllSessions && streamInterest.subscribedSessionIds.isEmpty()) { streamInterestByIdMap.remove(streamId); } }
/** * {@inheritDoc} */ public Object[] toArray() { final Object[] arrayCopy = new Object[size()]; copyValues(arrayCopy); return arrayCopy; }
if (value != MISSING_VALUE && !other.contains(value)) difference = new IntHashSet(); difference.add(value); difference = new IntHashSet(); difference.add(MISSING_VALUE);
@Test public void doesNotContainDisjointSet() { addTwoElements(testSet); final IntHashSet other = new IntHashSet(100); other.add(1); other.add(1002); assertFalse(testSet.containsAll(other)); assertFalse(testSet.containsAll((Collection<?>)other)); }
@Test public void doesNotContainRemovedIntersectingSetPrimitive() { addTwoElements(testSet); final IntHashSet intersecting = new IntHashSet(100); intersecting.add(1); intersecting.add(1002); assertTrue(testSet.removeAll(intersecting)); assertTrue(testSet.contains(1001)); assertFalse(testSet.containsAll(intersecting)); }
@Test public void hashCodeAccountsForMissingValue() { addTwoElements(testSet); testSet.add(MISSING_VALUE); final IntHashSet other = new IntHashSet(100); addTwoElements(other); assertNotEquals(testSet.hashCode(), other.hashCode()); other.add(MISSING_VALUE); assertEquals(testSet.hashCode(), other.hashCode()); testSet.remove(MISSING_VALUE); assertNotEquals(testSet.hashCode(), other.hashCode()); }
@Test public void setsWithTheDifferentValuesAreNotEqual() { final IntHashSet other = new IntHashSet(100); addTwoElements(testSet); other.add(2); other.add(1001); assertNotEquals(testSet, other); }
/** * {@inheritDoc} */ public boolean addAll(final Collection<? extends Integer> coll) { boolean added = false; for (final Integer value : coll) { added |= add(value); } return added; }
private void confirmSessionIdNotInUse(final int sessionId) { if (activeSessionIds.contains(sessionId)) { throw new IllegalStateException("existing publication has same session id: " + sessionId); } }
@Test public void iteratorCanRemoveMissingValue() { addTwoElements(testSet); testSet.add(MISSING_VALUE); final IntHashSet.IntIterator iterator = testSet.iterator(); while (iterator.hasNext()) { if (iterator.nextValue() == MISSING_VALUE) { iterator.remove(); } } assertFalse(testSet.contains(MISSING_VALUE)); }
@Test public void differenceReturnsSetDifference() { addTwoElements(testSet); final IntHashSet other = new IntHashSet(100); other.add(1); final IntHashSet diff = testSet.difference(other); assertThat(diff, containsInAnyOrder(1001)); }
@Test public void removingDisjointSetDoesNothing() { addTwoElements(testSet); final IntHashSet disjoint = new IntHashSet(100); disjoint.add(2); disjoint.add(1002); assertFalse(testSet.removeAll(disjoint)); assertFalse(testSet.removeAll(new HashSet<Integer>())); assertContainsElements(testSet); }
@Test public void addingSubsetDoesNothing() { addTwoElements(testSet); final IntHashSet subset = new IntHashSet(100); subset.add(1); final HashSet<Integer> subSetCollection = new HashSet<>(subset); assertFalse(testSet.addAll(subset)); assertFalse(testSet.addAll(subSetCollection)); assertContainsElements(testSet); }
public void removeSubscription(final int streamId) { final StreamInterest streamInterest = streamInterestByIdMap.get(streamId); if (null == streamInterest) { throw new UnknownSubscriptionException("No subscription registered on stream " + streamId); } for (final int sessionId : streamInterest.sessionInterestByIdMap.keySet()) { final SessionInterest sessionInterest = streamInterest.sessionInterestByIdMap.get(sessionId); if (!streamInterest.subscribedSessionIds.contains(sessionId)) { if (null != sessionInterest.image) { sessionInterest.image.ifActiveGoInactive(); } streamInterest.sessionInterestByIdMap.remove(sessionId); } } streamInterest.isForAllSessions = false; if (streamInterest.subscribedSessionIds.isEmpty()) { streamInterestByIdMap.remove(streamId); } }