Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    /**
     * @param sampleNode
     * @return The time and time unit from a sample. e.g. "day 1" or "week 2".
     *         Returns "" if no time information is avalilable.
     */
    public static String getSampleTime(Node sampleNode) {
        String time;
        if (sampleNode.getAttributes() == null || sampleNode.getAttributes().getNamedItem("time") == null)
            time = "-1";
        else
            time = sampleNode.getAttributes().getNamedItem("time").getFirstChild().getNodeValue();
        String timeunit;
        if (sampleNode.getAttributes() == null || sampleNode.getAttributes().getNamedItem("unit") == null)
            timeunit = "-1";
        else
            timeunit = sampleNode.getAttributes().getNamedItem("unit").getFirstChild().getNodeValue();

        String timeUnitAndTime = timeunit + " " + time; // +" ("+unit+")";
        if (time.equals("-1") && timeunit.equals("-1"))
            timeUnitAndTime = ""; // "("+unit+")";

        return timeUnitAndTime;
    }
}