Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*-----------------------------------------------------------------------
 * Copyright (C) 2001 Green Light District Team, Utrecht University 
 *
 * This program (Green Light District) is free software.
 * You may redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by
 * the Free Software Foundation (version 2 or later).
 *
 * 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.
 * See the documentation of Green Light District for further information.
 *------------------------------------------------------------------------*/

import java.util.StringTokenizer;

public class Main {
    /**
     * Convert a full XML name to its generic name. This is done by checking if
     * each part of the name is complex (if it consists of a generic name plus a
     * specific name). If so, then the specific part is removed. Array elements
     * are also removed from the name. Example of a complex name :
     * model.infrastructure.node-edge.spdata Result of getGenericName :
     * model.infrastructure.node.spdata
     *
     * @param name The XML name
     * @return The result
     */
    public static String getGenericName(String fullName) {
        return getGenericName(fullName, true);
    }

    /**
     * Convert a full XML name to its generic name. This is done by checking if
     * each part of the name is complex (if it consists of a generic name plus a
     * specific name). If so, then the specific part is removed. Example of a
     * complex name : model.infrastructure.node-edge.spdata Result of
     * getGenericName : model.infrastructure.node.spdata
     *
     * @param name The XML name
     * @param removeArrays Wether array elements have to be removed from the
     * name.
     * @return The result
     */
    public static String getGenericName(String fullName, boolean removeArrays) {
        StringTokenizer s = new StringTokenizer(fullName, ".");
        String result = "", tmp;
        int dashIndex;
        while (s.hasMoreTokens()) {
            tmp = s.nextToken();
            if (removeArrays && (("array").equals(tmp) || ("element").equals(tmp))) {
                continue;
            }
            if (result.length() > 0) {
                result += ".";
            }
            if ((dashIndex = tmp.indexOf('-')) == -1) {
                result += tmp;
            } else {
                result += tmp.substring(0, dashIndex);
            }
        }
        return result;
    }
}