Bug 4295: Fixed incorrectly introduced nodes when MERGE was followed by DELETE
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / LatestOperationHolder.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
9
10 /**
11  * Holder and factory for upgradable root modifications
12  *
13  * This class is factory for upgradable root modifications and provides an
14  * access to set latest backing implementation.
15  */
16 final class LatestOperationHolder {
17
18     private ModificationApplyOperation current = AlwaysFailOperation.INSTANCE;
19
20     /**
21      * Return latest backing implemenation
22      *
23      * @return
24      */
25     ModificationApplyOperation getCurrent() {
26         return current;
27     }
28
29     /**
30      * Sets latest backing implementation of associated
31      * {@link RootModificationApplyOperation}.
32      * <p>
33      * Note: This does not result in upgrading implementation of already
34      * existing {@link RootModificationApplyOperation}. Users, which
35      * obtained instances using {@link #newSnapshot()}, deriving
36      * {@link RootModificationApplyOperation} from this modification must
37      * explicitly invoke
38      * {@link RootModificationApplyOperation#upgradeIfPossible()} on their
39      * instance to be updated to latest backing implementation.
40      *
41      * @param newApplyOper
42      *            New backing implementation
43      */
44     void setCurrent(final ModificationApplyOperation newApplyOper) {
45         current = newApplyOper;
46     }
47
48     /**
49      *
50      * Creates new upgradable {@link RootModificationApplyOperation}
51      * associated with holder.
52      *
53      * @return New upgradable {@link RootModificationApplyOperation} with
54      *         {@link #getCurrent()} used as backing implementation.
55      */
56     RootModificationApplyOperation newSnapshot() {
57         return new UpgradableModificationApplyOperation(this, current);
58     }
59
60 }