/** * Prunes dead branches from the specified configuration tree. * @param explorer used to backtrack through the configuration tree. */ private void prune(BufferedConfigurationExplorer explorer) { ConfigurationSection current; ConfigurationSection parent; // If we're at the root level, nothing to prune. if(!explorer.hasSections()) return; current = explorer.popSection(); // Look for branches to prune until we've either found a non-empty one // or reached the root of the three. while(current.isEmpty() && current != root) { // Gets the current section's parent and prune. parent = explorer.hasSections() ? explorer.popSection() : root; parent.removeSection(current); current = parent; } }
/** * Backtracks through the section history and makes sure it contains the correct values. */ private void backtrack(BufferedConfigurationExplorer explorer, int depth) { for(int i = depth; i > 0; i--) { assert explorer.hasSections(); assert (VARIABLE_VALUE + i).equals(explorer.popSection().getVariable(VARIABLE_NAME + i)); } assert !explorer.hasSections(); }
/** * Tests path bufferisation when the requested sections are not found but created. */ @Test public void testSectionNotFoundAndCreateBuffer() { BufferedConfigurationExplorer explorer; for(int i = 0; i < DEPTH; i++) { moveTo(explorer = (BufferedConfigurationExplorer)getExplorer(), i); // Creates the section, makes sure it was created and takes it off // the section stack. assert explorer.moveTo(FAKE_SECTION + i, true); assert explorer.hasSections(); assert explorer.popSection() != null; // Makes sure backtracking through history works. backtrack(explorer, i); } } }