Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*************************************************************************************
 * Copyright (c) 2006, 2008 The Sakai Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.osedu.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
    
 *************************************************************************************/

public class Main {
    /**
     * 
     * @param etiqueta
     * @param posEtiqueta
     * @param documento
     * @return
     */
    private static boolean esUnaEtiquetaDeAperturaYCierre(String etiqueta, int posEtiqueta, String documento) {
        if (esElCaracterElPrimerPredecesorQueNoSeaBlanco('<', posEtiqueta, documento)
                && esElCaracterElPrimerSucesorQueNoSeaBlanco('/', posEtiqueta + etiqueta.length(), documento))
            return true;
        return false;
    }

    /**
     * 
     * @param caracter
     * @param pos
     * @param cadena
     * @return
     */
    private static boolean esElCaracterElPrimerPredecesorQueNoSeaBlanco(char caracter, int pos, String cadena) {
        if (pos == 0)
            return false;

        while (true) {
            pos = pos - 1;
            char predecesor = cadena.charAt(pos);
            if ((predecesor == caracter && pos == 0) || (predecesor == caracter && cadena.charAt(pos - 1) != '\\')) //para saltar los caracteres con \
                return true;
            if (!Character.isWhitespace(predecesor) && predecesor != caracter)
                return false;
            if (pos == 0)
                return false;
        }
    }

    /**
     * 
     * @param caracter
     * @param pos
     * @param cadena
     * @return
     */
    private static boolean esElCaracterElPrimerSucesorQueNoSeaBlanco(char caracter, int pos, String cadena) {
        if (pos == cadena.length())
            return false;
        while (true) {
            char sucesor = cadena.charAt(pos);
            if (sucesor == caracter && cadena.charAt(pos - 1) != '\\') //para saltar los caracteres con \
                return true;
            if (!Character.isWhitespace(sucesor) && sucesor != caracter)
                return false;
            if (pos == cadena.length())
                return false;
            pos = pos + 1;

        }
    }
}