Java Scanner Usage equalsToIgnoreEndline(String expected, String actual)

Here you can find the source of equalsToIgnoreEndline(String expected, String actual)

Description

compares two strings for equality, line by line, ignoring any difference of end line delimiters contained within the 2 Strings.

License

GNU General Public License

Parameter

Parameter Description
expected a parameter
actual a parameter

Declaration

public static boolean equalsToIgnoreEndline(String expected, String actual) 

Method Source Code

//package com.java2s;
/*/*from  www.  j a  v a 2  s .c  o  m*/
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on Sep 14, 2011
 * Author: Amr AL-Hossary 
 *
 */

import java.util.Scanner;

public class Main {
    /**
     * compares two strings for equality, line by line, ignoring any difference
     * of end line delimiters contained within the 2 Strings. This method should
     * be used if and only if two Strings are considered identical when all nodes
     * are identical including their relative order. Generally useful when
     * asserting identity of <b>automatically regenerated</b> XML or PDB.
     * 
     * @param expected
     * @param actual
     */
    public static boolean equalsToIgnoreEndline(String expected, String actual) {
        if (expected == null && actual == null) {
            return true;
        }
        if (expected != null ^ actual != null) {
            return false;
        }
        Scanner scanner1 = new Scanner(expected);
        Scanner scanner2 = new Scanner(actual);
        String line1, line2;
        while (scanner1.hasNextLine()) {
            line1 = scanner1.nextLine();
            line2 = scanner2.nextLine();
            if (!line1.equals(line2))
                return false;
        }
        if (scanner2.hasNextLine()) {
            return false;
        }

        return true;
    }
}

Related

  1. confirmAction(String warning)
  2. countFileLines(Scanner fin)
  3. createKeyboardScanner()
  4. createScannerForString(String s)
  5. enterToContinue()
  6. fromStringToQuery(String value)
  7. getBoolean()
  8. getChar()
  9. getConstantPoolsFromText(String text)