com.github.jlangch.venice.impl.util.LoremIpsum Maven / Gradle / Ivy
/* __ __ _
* \ \ / /__ _ __ (_) ___ ___
* \ \/ / _ \ '_ \| |/ __/ _ \
* \ / __/ | | | | (_| __/
* \/ \___|_| |_|_|\___\___|
*
*
* Copyright 2017-2024 Venice
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jlangch.venice.impl.util;
/**
* Creates arbitrary length Lorem Ipsum based texts.
*/
public class LoremIpsum {
private LoremIpsum() {
}
/**
* Creates a Lorem Ipsum text with the given text length.
*
* @param length
* The length of the text to be created. Returns an empty
* string if the length
is lower than 1
*
* @return The created Lorem Ipsum text
*/
public static String loremIpsum_Chars(final int length) {
int len = clip(length);
if (len <= 0) {
return "";
}
final StringBuilder sb = new StringBuilder();
int pg = 0;
while(len > 0) {
final String paragraph = LOREM_IPSUM[pg];
final int l = Math.min(len, paragraph.length());
sb.append(paragraph.substring(0, l));
len -= l;
pg = (pg + 1) % LOREM_IPSUM.length;
if (len > 0) {
sb.append("\n");
len -= 1;
}
}
return sb.toString();
}
/**
* Creates a Lorem Ipsum text with the given number of paragraphs.
*
* @param paragraphs
* The number of paragraphs (limited to 100). Returns an empty
* string if the paragraphs
is lower than 1
*
* @return The created Lorem Ipsum text
*/
public static String loremIpsum_Paragraphs(final int paragraphs) {
int len = Math.min(MAX_PARAGRAPHS, paragraphs);
if (len <= 0) {
return "";
}
final StringBuilder sb = new StringBuilder();
for(int ii=0; ii