List<Object> getParentScopesNames() { List<Object> parentScopesNames = new ArrayList<>(); for (ScopeNode parentScope : parentScopes) { parentScopesNames.add(parentScope.getName()); } return parentScopesNames; }
void removeChild(ScopeNode child) { if (child == null) { throw new IllegalArgumentException("Child must be non null."); } //this variable is important. It takes a snapshot of the node final ScopeNode parentScope = child.getParentScope(); if (parentScope == null) { throw new IllegalStateException(format("The scope has no parent: %s", child.getName())); } if (parentScope != this) { throw new IllegalStateException(format("The scope %s has parent: different of this: %s", // child.getName(), parentScope.getName(), getName())); } childrenScopes.remove(child.getName()); //make the ex-child a new root. child.parentScopes.clear(); }
/** * Removes all nodes of {@code scope} using DFS. We don't lock here. * * @param scope the parent scope of which all children will recursively be removed * from the map. We don't do anything else to the children nodes are they will be * garbage collected soon. We just cut a whole sub-graph in the references graph of the JVM * normally. */ private static void removeScopeAndChildrenFromMap(ScopeNode scope) { MAP_KEY_TO_SCOPE.remove(scope.getName()); scope.close(); for (ScopeNode childScope : scope.childrenScopes.values()) { removeScopeAndChildrenFromMap(childScope); } }
ScopeNode scope = childrenScopes.putIfAbsent(child.getName(), child); if (scope != null) { return scope;
@Test public void testGetParentScopeNames_shouldReturnParentNames_whenThereAreParents() { //GIVEN ScopeNode parentScope = new ScopeImpl("root"); ScopeNode childScope = new ScopeImpl("child"); parentScope.addChild(childScope); //WHEN final List<Object> parentScopesNames = childScope.getParentScopesNames(); //THEN assertThat(parentScopesNames.size(), is(1)); assertThat(parentScopesNames.iterator().next(), is(parentScope.getName())); }
@Test public void testGetParentScopeNames_shouldReturnParentNamesInOrder_whenThereAreParents() { //GIVEN ScopeNode parentScope = new ScopeImpl("root"); ScopeNode childScope = new ScopeImpl("child"); ScopeNode grandChildScope = new ScopeImpl("grandChild"); parentScope.addChild(childScope); childScope.addChild(grandChildScope); //WHEN final List<Object> grandParentScopesNames = grandChildScope.getParentScopesNames(); //THEN assertThat(grandParentScopesNames.size(), is(2)); final Iterator<Object> iterator = grandParentScopesNames.iterator(); assertThat(iterator.next(), is(childScope.getName())); assertThat(iterator.next(), is(parentScope.getName())); }
List<Object> getParentScopesNames() { List<Object> parentScopesNames = new ArrayList<>(); for (ScopeNode parentScope : parentScopes) { parentScopesNames.add(parentScope.getName()); } return parentScopesNames; }
void removeChild(ScopeNode child) { if (child == null) { throw new IllegalArgumentException("Child must be non null."); } //this variable is important. It takes a snapshot of the node final ScopeNode parentScope = child.getParentScope(); if (parentScope == null) { throw new IllegalStateException(format("The scope has no parent: %s", child.getName())); } if (parentScope != this) { throw new IllegalStateException(format("The scope %s has parent: different of this: %s", // child.getName(), parentScope.getName(), getName())); } childrenScopes.remove(child.getName()); //make the ex-child a new root. child.parentScopes.clear(); }
void removeChild(ScopeNode child) { if (child == null) { throw new IllegalArgumentException("Child must be non null."); } //this variable is important. It takes a snapshot of the node final ScopeNode parentScope = child.getParentScope(); if (parentScope == null) { throw new IllegalStateException(format("The scope has no parent: %s", child.getName())); } if (parentScope != this) { throw new IllegalStateException(format("The scope %s has parent: different of this: %s", // child.getName(), parentScope.getName(), getName())); } childrenScopes.remove(child.getName()); //make the ex-child a new root. child.parentScopes.clear(); }
/** * Removes all nodes of {@code scope} using DFS. We don't lock here. * * @param scope the parent scope of which all children will recursively be removed * from the map. We don't do anything else to the children nodes are they will be * garbage collected soon. We just cut a whole sub-graph in the references graph of the JVM normally. */ private static void removeScopeAndChildrenFromMap(ScopeNode scope) { MAP_KEY_TO_SCOPE.remove(scope.getName()); for (ScopeNode childScope : scope.childrenScopes.values()) { removeScopeAndChildrenFromMap(childScope); } }
/** * Removes all nodes of {@code scope} using DFS. We don't lock here. * * @param scope the parent scope of which all children will recursively be removed * from the map. We don't do anything else to the children nodes are they will be * garbage collected soon. We just cut a whole sub-graph in the references graph of the JVM * normally. */ private static void removeScopeAndChildrenFromMap(ScopeNode scope) { MAP_KEY_TO_SCOPE.remove(scope.getName()); scope.close(); for (ScopeNode childScope : scope.childrenScopes.values()) { removeScopeAndChildrenFromMap(childScope); } }
ScopeNode scope = childrenScopes.putIfAbsent(child.getName(), child); if (scope != null) { return scope;
ScopeNode scope = childrenScopes.putIfAbsent(child.getName(), child); if (scope != null) { return scope;