org.apache.commons.configuration2.tree.ReferenceTracker Maven / Gradle / Ivy
Show all versions of commons-configuration2 Show documentation
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.configuration2.tree;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
*
* A class which allows an {@link InMemoryNodeModel} to associate arbitrary objects with nodes.
*
*
* Some special configuration implementations need additional data to be stored with their nodes structure. We call such
* data "references" because objects required by a configuration are referenced. In such constellations, it is
* necessary to keep track about the nodes associated with references even if they are replaced by others during an
* update operation of the model. This is the task of this class.
*
*
* Basically, an instance manages a map associating nodes with reference objects. When a node is replaced the map gets
* updated. References becoming orphans because the nodes pointing to them were removed are tracked, too. They may be of
* importance for special configuration implementations as they might require additional updates. A concrete use case
* for this class is {@code XMLConfiguration} which stores the DOM nodes represented by configuration nodes as
* references.
*
*
* Implementation note: This class is intended to work in a concurrent environment. Instances are immutable. The
* represented state can be updated by creating new instances which are then stored by the owning node model.
*
*/
final class ReferenceTracker {
/** A map with reference data. */
private final Map references;
/** A list with the removed references. */
private final List