Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/***************************************
 *            ViPER                    *
 *  The Video Processing               *
 *         Evaluation Resource         *
 *                                     *
 *  Distributed under the GPL license  *
 *        Terms available at gnu.org.  *
 *                                     *
 *  Copyright University of Maryland,  *
 *                      College Park.  *
 ***************************************/

public class Main {
    /**
     * Gets the local part of a uri.
     * @param uri the uri to split
     * @return the local part, if found
     */
    public static String localName(String uri) {
        int i = getQNameSplitPoint(uri) + 1;
        if (i < uri.length()) {
            return uri.substring(i);
        } else {
            return "";
        }
    }

    /**
     * Given a uri that represents a qualified name, tries to 
     * determine the index of the split point between the namespace
     * and the local name. Returns the last index of #, /, or :,
     * checking for each. If the string contains no :, it doesn't count 
     * as a uri and nothing is returned.
     * @param uri the uri
     * @return the split point, or -1 if not found
     */
    public static int getQNameSplitPoint(String uri) {
        int col = uri.indexOf(":");
        if (col < 0) {
            return -1;
        } else {
            int hash = uri.indexOf("#");
            if (hash < 0) {
                int slash = Math.max(uri.lastIndexOf("/"), uri.lastIndexOf("\\"));
                if (slash > 0) {
                    return slash;
                } else {
                    return col;
                }
            } else {
                return hash;
            }
        }
    }
}