Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Node;

public class Main {
    public static int readInt(Node node, String attributeName, int def) {
        try {
            return Integer.parseInt(node.getAttributes().getNamedItem(attributeName).getNodeValue());
        } catch (Exception ex) {
            return def;
        }
    }

    /**
     * Parses an integer from a string, if the string is null returns def.
     *
     * @param i The string to parse
     * @param def The default value if the string is null
     * @return
     * @throws SAXException
     */
    public static int parseInt(String i, int def) {
        if (i == null) {
            return def;
        } else {
            try {
                return Integer.parseInt(i);
            } catch (NumberFormatException ex) {
                return 0;
            }
        }
    }

    public static int parseInt(String i) {
        if (i == null) {
            return 0;
        } else {
            try {
                return Integer.parseInt(i);
            } catch (NumberFormatException ex) {
                return 0;
            }
        }

    }
}