Java Bit Shift shiftText(final int pads, final String padding, String textPassed)

Here you can find the source of shiftText(final int pads, final String padding, String textPassed)

Description

Shifts a multiline text to right the specified number of characters and the specified padding character

License

Open Source License

Parameter

Parameter Description
pads a parameter
padding a parameter
xapiText a parameter

Declaration

public static String shiftText(final int pads, final String padding, String textPassed) 

Method Source Code

//package com.java2s;
/*/*from   ww  w  .  j av a 2 s.  co m*/
       
This file is part of the Xapagy Cognitive Architecture 
Copyright (C) 2008-2017 Ladislau Boloni
    
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.
    
You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
*/

public class Main {
    /**
     * Shifts a multiline text to right the specified number of characters and
     * the specified padding character
     * 
     * @param pads
     * @param padding
     * @param xapiText
     * @return
     */
    public static String shiftText(final int pads, final String padding, String textPassed) {
        String text = textPassed;
        if (pads < 0) {
            throw new Error("Cannot pad with negatives!");
        }
        String paddingString = "";
        boolean newLineAtEnd = false;
        for (int i = 0; i < pads; i++) {
            paddingString = paddingString + padding;
        }
        if (text.endsWith("\n")) {
            text = text.substring(0, text.length() - 1);
            newLineAtEnd = true;
        }
        final String preparedText = paddingString + text.replaceAll("\n", "\n" + paddingString);
        if (newLineAtEnd) {
            return preparedText + "\n";
        } else {
            return preparedText;
        }
    }
}

Related

  1. shiftLastAlphabets(String id)
  2. shiftLeft(char ch)
  3. shiftLeft(final Character orig, final int shiftDistance)
  4. shiftPath(String uri)
  5. shiftsForNextPowerOfTwo(final int targetSize)
  6. shiftUpLeft(long b)