Binding codec v2 - fix augmentation #7
[mdsal.git] / binding2 / mdsal-binding2-dom-codec / src / main / java / org / opendaylight / mdsal / binding / javav2 / dom / codec / impl / context / base / IncorrectNestingException.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.mdsal.binding.javav2.dom.codec.impl.context.base;
10
11 import com.google.common.annotations.Beta;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14
15 /**
16  * Thrown where incorrect nesting of data structures was detected
17  * and was caused by user.
18  */
19 @Beta
20 class IncorrectNestingException extends IllegalArgumentException {
21
22     private static final long serialVersionUID = 1L;
23
24     protected IncorrectNestingException(final String message) {
25         super(message);
26     }
27
28     public static IncorrectNestingException create(final String message, final Object... args) {
29         return new IncorrectNestingException(String.format(message, args));
30     }
31
32     public static void check(final boolean check, final String message, final Object... args) {
33         if (!check) {
34             throw IncorrectNestingException.create(message, args);
35         }
36     }
37
38     @Nonnull
39     public static <V> V checkNonNull(@Nullable final V nullable, final String message, final Object... args) {
40         if (nullable != null) {
41             return nullable;
42         }
43         throw IncorrectNestingException.create(message, args);
44     }
45 }