View Javadoc
1   package com.atlassian.dbexporter.importer;
2   
3   import com.atlassian.dbexporter.node.NodeParser;
4   
5   import static com.google.common.base.Preconditions.checkNotNull;
6   import static com.google.common.base.Preconditions.checkState;
7   
8   public final class ImporterUtils {
9       private ImporterUtils() {
10      }
11  
12      public static void checkStartNode(NodeParser node, String nodeName) {
13          checkNode(node, nodeName, !node.isClosed());
14      }
15  
16      /**
17       * Checks that the node is the node with the given name and is not closed.
18       *
19       * @param node     the node to check
20       * @param nodeName the name that the node must match.
21       * @return {@code true} if and only if the node is of the given {@code nodeName} and {@link NodeParser#isClosed() is not closed}
22       * @throws NullPointerException is {@code node} or {@code nodeName} is {@code null}
23       */
24      public static boolean isNodeNotClosed(NodeParser node, String nodeName) {
25          checkNotNull(node);
26          checkNotNull(nodeName);
27          return !node.isClosed() && nodeName.equals(node.getName());
28      }
29  
30      public static void checkEndNode(NodeParser node, String nodeName) {
31          checkNode(node, nodeName, node.isClosed());
32      }
33  
34      private static void checkNode(NodeParser node, String nodeName, boolean closed) {
35          checkNotNull(node);
36          checkState(node.getName().equals(nodeName), "%s is not named '%s' as expected", node, nodeName);
37          checkState(closed, "%s is not closed (%s) as expected", node, closed);
38      }
39  }