/*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.data.api;

import java.util.Arrays;

// TODO rename to ModifyOperation

/**
 * http://tools.ietf.org/html/rfc6241#section-7.2
 */
public enum ModifyAction {
    MERGE, REPLACE, CREATE, DELETE, REMOVE, NONE;

    public static ModifyAction fromXmlValue(String xmlNameOfAction) {
        switch (xmlNameOfAction) {
        case "merge":
            return MERGE;
        case "replace":
            return REPLACE;
        case "remove":
            return REMOVE;
        case "delete":
            return DELETE;
        case "create":
            return CREATE;
        case "none":
            return NONE;
        default:
            throw new IllegalArgumentException("Unknown operation " + xmlNameOfAction + " available operations "
                    + Arrays.toString(ModifyAction.values()));
        }
    }

    public boolean isAsDefaultPermitted() {
        boolean isPermitted = this == MERGE;
        isPermitted |= this == REPLACE;
        isPermitted |= this == NONE;
        return isPermitted;
    }

    public boolean isOnElementPermitted() {
        return this != NONE;
    }

}

@@ -424,16 +424,17 @@
 %0A * http
+s
 ://tools
@@ -508,16 +508,22 @@
    MERGE
+(true)
 , REPLAC
@@ -527,16 +527,22 @@
 LACE
+(true)
 , CREATE
 , DE
@@ -541,16 +541,23 @@
 EATE
+(false)
 , DELETE
 , RE
@@ -556,16 +556,23 @@
 LETE
+(false)
 , REMOVE
 , NO
@@ -571,14 +571,34 @@
 MOVE
-, NONE
+(false), NONE(true, false)
 ;%0A%0A 
@@ -640,16 +640,22 @@
 mlValue(
+final 
 String x
@@ -1210,37 +1210,44 @@
   %7D%0A    %7D%0A%0A    p
-ublic
+rivate final
  boolean isAsDef
@@ -1243,11 +1243,9 @@
 ean 
-isA
+a
 sDef
@@ -1261,68 +1261,174 @@
 tted
-() %7B
+;
 %0A    
-    boolean isPermitted = this == MERGE;%0A        is
+private final boolean onElementPermitted;%0A%0A    private ModifyAction(final boolean asDefaultPermitted, final boolean onElementPermitted) %7B%0A        this.asDefault
 Perm
@@ -1437,64 +1437,242 @@
 ted 
-%7C
 = 
-this == REPLACE
+asDefaultPermitted;%0A        this.onElementPermitted = onElementPermitted
 ;%0A    
+%7D%0A%0A
     
-isPermitted %7C= this == NONE;
+private ModifyAction(final boolean asDefaultPermitted) %7B%0A        this(asDefaultPermitted, true);%0A    %7D%0A%0A    public boolean isAsDefaultPermitted() %7B
 %0A   
@@ -1683,18 +1683,25 @@
  return 
-is
+asDefault
 Permitte
@@ -1773,27 +1773,33 @@
 urn 
-this != NONE
+onElementPermitted
 ;%0A    %7D%0A
 %0A%7D%0A
@@ -1795,11 +1795,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Refactor ModifyAction