Coverage Report - com.puppycrawl.tools.checkstyle.checks.LineSeparatorOption
 
Classes in this File Line Coverage Branch Coverage Complexity
LineSeparatorOption
100%
11/11
N/A
1
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 // checkstyle: Checks Java source code for adherence to a set of rules.
 3  
 // Copyright (C) 2001-2014  Oliver Burn
 4  
 //
 5  
 // This library is free software; you can redistribute it and/or
 6  
 // modify it under the terms of the GNU Lesser General Public
 7  
 // License as published by the Free Software Foundation; either
 8  
 // version 2.1 of the License, or (at your option) any later version.
 9  
 //
 10  
 // This library is distributed in the hope that it will be useful,
 11  
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 // Lesser General Public License for more details.
 14  
 //
 15  
 // You should have received a copy of the GNU Lesser General Public
 16  
 // License along with this library; if not, write to the Free Software
 17  
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 ////////////////////////////////////////////////////////////////////////////////
 19  
 package com.puppycrawl.tools.checkstyle.checks;
 20  
 
 21  
 /**
 22  
  * Represents the options for line separator settings.
 23  
  *
 24  
  * @author lkuehne
 25  
  * @see NewlineAtEndOfFileCheck
 26  
  */
 27  2
 public enum LineSeparatorOption
 28  
 {
 29  
     /** Windows-style line separators. **/
 30  1
     CRLF("\r\n"),
 31  
 
 32  
     /** Mac-style line separators. **/
 33  1
     CR("\r"),
 34  
 
 35  
     /** Unix-style line separators. **/
 36  1
     LF("\n"),
 37  
 
 38  
     /** System default line separators. **/
 39  1
     SYSTEM(System.getProperty("line.separator"));
 40  
 
 41  
     /** the line separator representation */
 42  
     private final String mLineSeparator;
 43  
 
 44  
     /**
 45  
      * Creates a new <code>LineSeparatorOption</code> instance.
 46  
      * @param aSep the line separator, e.g. "\r\n"
 47  
      */
 48  
     private LineSeparatorOption(String aSep)
 49  4
     {
 50  4
         mLineSeparator = aSep;
 51  4
     }
 52  
 
 53  
     /**
 54  
      * @param aBytes a bytes array to check
 55  
      * @return if aBytes is equal to the byte representation
 56  
      * of this line separator
 57  
      */
 58  
     public boolean matches(byte[] aBytes)
 59  
     {
 60  2
         final String s = new String(aBytes);
 61  2
         return s.equals(mLineSeparator);
 62  
     }
 63  
 
 64  
     /**
 65  
      * @return the length of the file separator,
 66  
      * e.g. 1 for CR, 2 for CRLF, ...
 67  
      */
 68  
     public int length()
 69  
     {
 70  3
         return mLineSeparator.length();
 71  
     }
 72  
 }