Bacon Ipsum


package de.eknori;

/**
 * Simple bacon ipsum text generator. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT
 * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 * <p>
 * Suitable for creating sample data for test cases and performance tests.
 * </p>
 * 
 * @author Ulrich Krause
 * @version 1.0
 */
public class BaconIpsum {

	/* sample usage */
	public static void main(String[] args) {

		BaconIpsum bi = new BaconIpsum();
		System.out.println(bi.getWords(100));
		System.out.println(bi.getWords(100, 25));
		System.out.println(bi.getParagraphs(3));
	}

	public static final String BACON_IPSUM = "Bacon ipsum dolor sit amet turkey leberkas meatloaf ham hock sirloin salami short loin shank. Fatback ham tenderloin capicola turkey jowl pancetta swine. Sausage corned beef pastrami pork chop shoulder doner. Ribeye pig filet mignon sausage brisket pork belly beef ribs.T-bone strip steak pancetta leberkas filet mignon flank prosciutto capicola doner chuck. Chuck strip steak ball tip, biltong andouille rump corned beef ham hock pork chop prosciutto tri-tip boudin beef ribs sirloin swine. Pork fatback prosciutto pancetta venison boudin pastrami sirloin leberkas corned beef tenderloin strip steak. Turducken ham hock boudin, shoulder prosciutto short ribs turkey spare ribs strip steak jerky.Short ribs spare ribs turkey sirloin biltong, rump beef ribs andouille turducken short loin prosciutto fatback hamburger sausage. Swine pancetta flank prosciutto pork. Boudin pork loin hamburger pancetta sirloin ribeye meatball venison filet mignon tenderloin tri-tip. Meatloaf brisket cow beef chicken flank ham pork belly. Sausage beef prosciutto andouille boudin. Filet mignon rump boudin ham. Swine hamburger jowl meatloaf. Kielbasa pork chop short loin tenderloin pastrami turkey. Bresaola t-bone frankfurter, doner corned beef ball tip jerky short ribs ground round jowl flank strip steak bacon ham. Short loin bacon sausage meatloaf andouille jowl shankle. Beef pork loin jerky jowl, tri-tip beef ribs pork belly shoulder sirloin short loin hamburger tail leberkas pork pastrami. Pork belly tail chicken, tri-tip capicola boudin pork ham shoulder ball tip beef ribs. Ball tip spare ribs tri-tip jerky pork hamburger pancetta, prosciutto doner rump. Meatloaf jerky pancetta, swine tongue bacon ribeye shoulder spare ribs ground round ball tip. Spare ribs frankfurter capicola, leberkas shoulder turducken pork loin t-bone shank rump short loin ham tongue meatloaf.";
	private String[] baconIpsumWords;

	public BaconIpsum() {
		this.baconIpsumWords = BACON_IPSUM.split("\\s");
	}

	/**
	 * Returns 250 words of the bacon ipsum text.
	 * 
	 * @return 250 words of bacon ipsum text
	 */
	public String getWords() {
		return getWords(250);
	}

	/**
	 * Returns words from the bacon ipsum text.
	 * 
	 * @param amount
	 *            Amount of words
	 * @return bacon ipsum text
	 */
	public String getWords(int amount) {
		return getWords(amount, 0);
	}

	/**
	 * Returns words from the bacon ipsum text.
	 * 
	 * @param amount
	 *            Amount of words
	 * @param startIndex
	 *            Start index of word to begin with (must be >= 0 and < 50)
	 * @return bacon ipsum text
	 * @throws IndexOutOfBoundsException
	 *             If startIndex is < 0 or > 249
	 */
	public String getWords(int amount, int startIndex) {
		if (startIndex < 0 || startIndex > 249) {
			throw new IndexOutOfBoundsException(
					"startIndex must be >= 0 and < 250");
		}

		int word = startIndex;
		StringBuilder bacon = new StringBuilder();

		for (int i = 0; i < amount; i++) {
			if (word == 50) {
				word = 0;
			}

			bacon.append(baconIpsumWords[word]);

			if (i < amount - 1) {
				bacon.append(' ');
			}

			word++;
		}

		return bacon.toString();
	}

	/**
	 * Returns two paragraphs of bacon ipsum.
	 * 
	 * @return bacon ipsum paragraphs
	 */
	public String getParagraphs() {
		return getParagraphs(2);
	}

	/**
	 * Returns paragraphs of bacon ipsum.
	 * 
	 * @param amount
	 *            Amount of paragraphs
	 * @return bacon ipsum paragraphs
	 */
	public String getParagraphs(int amount) {
		StringBuilder bacon = new StringBuilder();

		for (int i = 0; i < amount; i++) {
			bacon.append(BACON_IPSUM);

			if (i < amount - 1) {
				bacon.append("\n\n");
			}
		}

		return bacon.toString();
	}
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...