/*
* [NL.java]
*
* Summary: Describes one NL new line token for display.
*
* Copyright: (c) 2004-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
*
* Licence: This software may be copied and used freely for any purpose but military.
* http://mindprod.com/contact/nonmil.html
*
* Requires: JDK 1.8+
*
* Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
*
* Version History:
* 2.0 2009-04-19 tidy comments, more accurate colour names
*/
package com.mindprod.jtokens;
/**
* Describes one NL new line token for display.
*
* @author Roedy Green, Canadian Mind Products
* @version 2.0 2009-04-19 tidy comments, more accurate colour names
* @since 2004-04-24
*/
public final class NL extends WhiteSpace
{
/**
* version number for the class
*/
static final long serialVersionUID = 1L;
/**
* used to efficiently reconstruct string of nls.
*/
@SuppressWarnings( { "ConstantNamingConvention" } )
private static final String nls =
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\"; " +
" ";
/**
* The count of the string of nls to render
*/
private final int count;
/**
* Constructor
*/
public NL()
{
super( null );
this.count = 1;
}
/**
* Constructor
*
* @param count of how many newlines
*/
public NL( int count )
{
super( null );
assert count > 0 : "NL 0";
this.count = count;
}
/**
* Get number of newline characters.
*
* @return count of newline characters this token represents.
*/
public int getCount()
{
return count;
}
/**
* gets the raw text to render this token , possibly containing \n.
*
* @return The plain String representation of the text
*/
public String getText()
{
return nls.substring( 0, Math.min( nls.length(), count ) );
}
// default getHtml will return getText. We don't need
since we use
// simple \n inside
.../** * Is this token useless? In other words would rendering it have no visible effect? NL and Space are not considered * useless, unless they have 0 counts. Usually a token is useless because it has and empty or null text string. * * @return true if this token can be thrown away as useless */ public boolean isUseless() { return count == 0; } /** * debugging tool to display a Token * * @return String representation of the token. */ public String toString() { return "Token: " + getName() + "\n" + " nls: " + count + "\n"; } }