@SuppressWarnings("unchecked") @Test public void clean() { IBufferTreeComponent<DefaultData> component1 = Mockito.mock(IBufferTreeComponent.class); when(component1.clean()).thenReturn(true); IBufferTreeComponent<DefaultData> component2 = Mockito.mock(IBufferTreeComponent.class); when(component2.clean()).thenReturn(false); Map<Object, ITreeComponent<DefaultData, DefaultData>> componentMap = MapUtils.putAll(new HashMap<Object, IBufferTreeComponent<DefaultData>>(), new Object[] { "c1", component1, "c2", component2 }); when(branch.getComponentMap()).thenReturn(componentMap); boolean isClean = branch.clean(); assertThat(isClean, is(false)); assertThat(componentMap, not(hasValue((ITreeComponent<DefaultData, DefaultData>) component1))); assertThat(componentMap, hasValue((ITreeComponent<DefaultData, DefaultData>) component2)); when(component2.clean()).thenReturn(true); isClean = branch.clean(); assertThat(isClean, is(true)); assertThat(componentMap.values(), is(empty())); }
@Override public boolean clean() { ArrayList<Object> keysToRemove = new ArrayList<>(); for (Entry<Object, ITreeComponent<E, E>> entry : getComponentMap().entrySet()) { if (entry.getValue() instanceof IBufferTreeComponent) { boolean toClear = ((IBufferTreeComponent<E>) entry.getValue()).clean(); if (toClear) { keysToRemove.add(entry.getKey()); } } } for (Object key : keysToRemove) { getComponentMap().remove(key); } if (getComponentMap().isEmpty()) { return true; } return false; }
Branch extends AbstractBranch<E, E> implements IBufferTreeComponent<E> { @Override public boolean clean() { ArrayList<Object> keysToRemove = new ArrayList<>(); for (Entry<Object, ITreeComponent<E, E>> entry : getComponentMap().entrySet()) { if (entry.getValue() instanceof IBufferTreeComponent) { boolean toClear = ((IBufferTreeComponent<E>) entry.getValue()).clean(); if (toClear) { keysToRemove.add(entry.getKey()); } } } for (Object key : keysToRemove) { getComponentMap().remove(key); } if (getComponentMap().isEmpty()) { return true; } return false; } }
Branch extends AbstractBranch<E, E> implements IBufferTreeComponent<E> { @Override public boolean clean() { ArrayList<Object> keysToRemove = new ArrayList<>(); for (Entry<Object, ITreeComponent<E, E>> entry : getComponentMap().entrySet()) { if (entry.getValue() instanceof IBufferTreeComponent) { boolean toClear = ((IBufferTreeComponent<E>) entry.getValue()).clean(); if (toClear) { keysToRemove.add(entry.getKey()); } } } for (Object key : keysToRemove) { getComponentMap().remove(key); } if (getComponentMap().isEmpty()) { return true; } return false; } Branch(IBufferBranchIndexer<E> bufferBranchIndexer); }
Branch extends AbstractBranch<E, E> implements IBufferTreeComponent<E> { @Override public boolean clean() { ArrayList<Object> keysToRemove = new ArrayList<>(); for (Entry<Object, ITreeComponent<E, E>> entry : getComponentMap().entrySet()) { if (entry.getValue() instanceof IBufferTreeComponent) { boolean toClear = ((IBufferTreeComponent<E>) entry.getValue()).clean(); if (toClear) { keysToRemove.add(entry.getKey()); } } } for (Object key : keysToRemove) { getComponentMap().remove(key); } if (getComponentMap().isEmpty()) { return true; } return false; } Branch(IBufferBranchIndexer<E> bufferBranchIndexer); @Override void cleanWithRunnable(ExecutorService executorService); @Override boolean clean(); @Override boolean clearEmptyComponents(); @Override long getNumberOfElements(); IBufferBranchIndexer<E> getBufferBranchIndexer(); }
Branch extends AbstractBranch<E, E> implements IBufferTreeComponent<E> { @Override public boolean clean() { ArrayList<Object> keysToRemove = new ArrayList<>(); for (Entry<Object, ITreeComponent<E, E>> entry : getComponentMap().entrySet()) { if (entry.getValue() instanceof IBufferTreeComponent) { boolean toClear = ((IBufferTreeComponent<E>) entry.getValue()).clean(); if (toClear) { keysToRemove.add(entry.getKey()); } } } for (Object key : keysToRemove) { getComponentMap().remove(key); } if (getComponentMap().isEmpty()) { return true; } return false; } Branch(IBufferBranchIndexer<E> bufferBranchIndexer); @Override void cleanWithRunnable(ExecutorService executorService); @Override boolean clean(); @Override boolean clearEmptyComponents(); @Override long getNumberOfElements(); IBufferBranchIndexer<E> getBufferBranchIndexer();  }