All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sortpom.parameter.IndentCharacters Maven / Gradle / Ivy

There is a newer version: 2.3.1
Show newest version
package sortpom.parameter;

import sortpom.exception.FailureException;

import java.util.Arrays;

/**
 * Encapsulates functionality to get indent characters from the nrOfIndentSpace
 * parameter
 */
class IndentCharacters {
    /** Indicates that a tab character should be used instead of spaces. */
    private static final int INDENT_TAB = -1;

    private static final int MAX_INDENT_SPACES = 255;

    private final int nrOfIndentSpace;

    IndentCharacters(int nrOfIndentSpace) {
        this.nrOfIndentSpace = nrOfIndentSpace;
    }

    /**
     * Gets the indent characters from parameter.
     *
     * @return the indent characters
     */
    public String getIndentCharacters() {
        if (nrOfIndentSpace == 0) {
            return "";
        }
        if (nrOfIndentSpace == INDENT_TAB) {
            return "\t";
        }
        if (nrOfIndentSpace < INDENT_TAB || nrOfIndentSpace > MAX_INDENT_SPACES) {
            throw new FailureException("nrOfIndentSpace cannot be below -1 or above 255, was: " + nrOfIndentSpace);
        }
        char[] chars = new char[nrOfIndentSpace];
        Arrays.fill(chars, ' ');
        return new String(chars);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy