@Override public int getHandlerCount() { return this.handlers.size(); }
/** * Add the handler to the internal Set. * * @param handler The handler to add. * @return the result of {@link Set#add(Object)} */ @Override public synchronized boolean addHandler(MessageHandler handler) { Assert.notNull(handler, "handler must not be null"); Assert.isTrue(this.handlers.size() < this.maxSubscribers, "Maximum subscribers exceeded"); boolean added = this.handlers.add(handler); if (this.handlers.size() == 1) { this.theOneHandler = handler; } else { this.theOneHandler = null; } return added; }
/** * Remove the handler from the internal handler Set. * * @return the result of {@link Set#remove(Object)} */ @Override public synchronized boolean removeHandler(MessageHandler handler) { Assert.notNull(handler, "handler must not be null"); boolean removed = this.handlers.remove(handler); if (this.handlers.size() == 1) { this.theOneHandler = this.handlers.iterator().next(); } else { this.theOneHandler = null; } return removed; }
@Override public int getHandlerCount() { return this.handlers.size(); }
/** * Add the handler to the internal Set. * * @param handler The handler to add. * @return the result of {@link Set#add(Object)} */ @Override public synchronized boolean addHandler(MessageHandler handler) { Assert.notNull(handler, "handler must not be null"); Assert.isTrue(this.handlers.size() < this.maxSubscribers, "Maximum subscribers exceeded"); boolean added = this.handlers.add(handler); if (this.handlers.size() == 1) { this.theOneHandler = handler; } else { this.theOneHandler = null; } return added; }
assertEquals(15, setToTest.size());
/** * Tests that semantics of the LinkedHashSet were not broken */ @SuppressWarnings("rawtypes") @Test public void testAddUnordered() { OrderedAwareCopyOnWriteArraySet setToTest = new OrderedAwareCopyOnWriteArraySet(); setToTest.add("foo"); setToTest.add("bar"); setToTest.add("baz"); assertEquals(3, setToTest.size()); Object[] elements = setToTest.toArray(); assertEquals("foo", elements[0]); assertEquals("bar", elements[1]); assertEquals("baz", elements[2]); } /**
/** * Remove the handler from the internal handler Set. * * @return the result of {@link Set#remove(Object)} */ @Override public synchronized boolean removeHandler(MessageHandler handler) { Assert.notNull(handler, "handler must not be null"); boolean removed = this.handlers.remove(handler); if (this.handlers.size() == 1) { this.theOneHandler = this.handlers.iterator().next(); } else { this.theOneHandler = null; } return removed; }
setToTest.add(o9); setToTest.add(o10); assertEquals(10, setToTest.size()); Object[] elements = setToTest.toArray(); assertEquals(o7, elements[0]);