Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * LABPipe - Natural Language Processing Pipeline for Bulgarian
 * Copyright (C) 2011 Institute for Information and Communication Technologies
 * 
 * The development of this program was funded by the EuroMatrixPlus Project as 
 * part of the Seventh Framework Program of the European Commission.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    /**
     * Compares the attributes of two XML <code>Node</code> objects. This method
     * returns <code>true</code> if all attribute name-value pairs match 
     * disregarding their order of placement.
     * 
     * @param   n1    first <code>Node</code>
     * @param   n2    second <code>Node</code>
     * 
     * @return  boolean
     * 
     */
    public static boolean diffAttributes(Node n1, Node n2) {
        NamedNodeMap n1Atts = n1.getAttributes();
        NamedNodeMap n2Atts = n2.getAttributes();

        if (n1Atts.getLength() != n2Atts.getLength()) {
            return false;
        }

        for (int i = 0; i < n1Atts.getLength(); i++) {
            Node a1 = n1Atts.item(i);
            Node a2Val = n2Atts.getNamedItem(a1.getNodeName());
            if (a2Val == null || !a1.getNodeValue().equals(a2Val.getNodeValue())) {
                return false;
            }
        }
        return true;
    }
}