@Test public void testReplace() { MockHandler m1 = new MockHandler(); MockHandler m2 = new MockHandler(); MockHandler m3 = new MockHandler(); MockHandler m4 = new MockHandler(); _chain.addFirst("1", m1); Assert.assertFalse(_chain.replace("5", m2)); Assert.assertTrue(_chain.replace("1", m2)); Assert.assertTrue(_chain.getHandlers().contains(m2)); Assert.assertFalse(_chain.getHandlers().contains(m1)); _chain.remove("1"); Assert.assertEquals(0, _chain.getHandlers().size()); _chain.addFirst("1", m1); _chain.addFirst("2", m2); _chain.addFirst("3", m3); _chain.replace("2", m4); Assert.assertEquals(m4, _chain.getHandlers().get(1)); }
@Override public synchronized boolean replace(String handlerName, ExchangeHandler handler) { for (int i = 0; i < _chain.size(); i++) { if (_chain.get(i).getName().equals(handlerName)) { _chain.remove(i); _chain.add(i, new HandlerRef(handlerName, handler)); return true; } } return false; }
DefaultHandlerChain implements HandlerChain { @Override public synchronized boolean replace(String handlerName, ExchangeHandler handler) { for (int i = 0; i < _chain.size(); i++) { if (_chain.get(i).getName().equals(handlerName)) { _chain.remove(i); _chain.add(i, new HandlerRef(handlerName, handler)); return true; } } return false; } }
DefaultHandlerChain implements HandlerChain { @Override public synchronized boolean replace(String handlerName, ExchangeHandler handler) { for (int i = 0; i < _chain.size(); i++) { if (_chain.get(i).getName().equals(handlerName)) { _chain.remove(i); _chain.add(i, new HandlerRef(handlerName, handler)); return true; } } return false; } DefaultHandlerChain(); private  DefaultHandlerChain(List<HandlerRef> handlers); }
DefaultHandlerChain implements HandlerChain { @Override public synchronized boolean replace(String handlerName, ExchangeHandler handler) { for (int i = 0; i < _chain.size(); i++) { if (_chain.get(i).getName().equals(handlerName)) { _chain.remove(i); _chain.add(i, new HandlerRef(handlerName, handler)); return true; } } return false; } DefaultHandlerChain(); private  DefaultHandlerChain(List<HandlerRef> handlers); static DefaultHandlerChain fromList(List<ExchangeHandler> handlers); @Override synchronized void addFirst(String handlerName,
            ExchangeHandler handler); @Override synchronized void addLast(String handlerName,
            ExchangeHandler handler); @Override synchronized boolean replace(String handlerName, ExchangeHandler handler); @Override synchronized ExchangeHandler remove(String handlerName); @Override void handle(Exchange exchange); @Override void handleFault(Exchange exchange); @Override void handleMessage(Exchange exchange); @Override List<ExchangeHandler> getHandlers(); DefaultHandlerChain copy(); @Override String toString(); }
DefaultHandlerChain implements HandlerChain { @Override public synchronized boolean replace(String handlerName, ExchangeHandler handler) { for (int i = 0; i < _chain.size(); i++) { if (_chain.get(i).getName().equals(handlerName)) { _chain.remove(i); _chain.add(i, new HandlerRef(handlerName, handler)); return true; } } return false; } DefaultHandlerChain(); private  DefaultHandlerChain(List<HandlerRef> handlers); static DefaultHandlerChain fromList(List<ExchangeHandler> handlers); @Override synchronized void addFirst(String handlerName,
            ExchangeHandler handler); @Override synchronized void addLast(String handlerName,
            ExchangeHandler handler); @Override synchronized boolean replace(String handlerName, ExchangeHandler handler); @Override synchronized ExchangeHandler remove(String handlerName); @Override void handle(Exchange exchange); @Override void handleFault(Exchange exchange); @Override void handleMessage(Exchange exchange); @Override List<ExchangeHandler> getHandlers(); DefaultHandlerChain copy(); @Override String toString();  }