Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * The contents of this file are subject to the Regenstrief Public License
 * Version 1.0 (the "License"); you may not use this file except in compliance with the License.
 * Please contact Regenstrief Institute if you would like to obtain a copy of the license.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) Regenstrief Institute.  All Rights Reserved.
 */

import org.w3c.dom.*;

public class Main {
    /**
     * Puts all Nodes of the source NamedNodeMap into the destination NamedNodeMap
     * 
     * @param dst the destination NamedNodeMap
     * @param src the source NamedNodeMap
     **/
    public final static void putAll(final NamedNodeMap dst, final NamedNodeMap src) {
        final int size = size(src);

        for (int i = 0; i < size; i++) {
            dst.setNamedItemNS(src.item(i));
        }
    }

    /**
     * Retrieves the number of Nodes in the NodeList
     * 
     * @param nodeList the NodeList
     * @return the number of Nodes
     **/
    public final static int size(final NodeList nodeList) {
        return nodeList == null ? 0 : nodeList.getLength();
    }

    /**
     * Retrieves the number of Nodes in the NamedNodeMap
     * 
     * @param nodeMap the NamedNodeMap
     * @return the number of Nodes
     **/
    public final static int size(final NamedNodeMap nodeMap) {
        return nodeMap == null ? 0 : nodeMap.getLength();
    }

    /**
     * Retrieves the number of Nodes in the tree rooted at the given Node
     * 
     * @param node the root Node
     * @return the number of Nodes
     **/
    public final static int size(final Node node) {
        if (node == null) {
            return 0;
        }

        final NodeList children = node.getChildNodes();
        int size = 1;
        for (int i = 0, n = size(children); i < n; i++) {
            size += size(children.item(i));
        }

        return size;
    }
}