de.svenjacobs.loremipsum.LoremIpsum Java Examples

The following examples show how to use de.svenjacobs.loremipsum.LoremIpsum. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StringMutatorService.java    From CogStack-Pipeline with Apache License 2.0 6 votes vote down vote up
public Mutant generateMutantDocument(String[] stringToMutate, int severity) {

        LoremIpsum loremIpsum = new LoremIpsum();
        int loremStart =0;
        int loremEnd =random.nextInt(loremLength);

        StringBuilder sb = new StringBuilder();
        sb.insert(0, loremIpsum.getWords(random.nextInt(loremLength)));
        sb.append(" ");
        Mutant parentMutant = new Mutant();
        for (int i = 0; i < stringToMutate.length; i++) {
            Mutant childMutant = mutate(stringToMutate[i], severity);
            parentMutant.getInputTokens().addAll(childMutant.getInputTokens());
            parentMutant.getOutputTokens().addAll(childMutant.getOutputTokens());
            sb.append(childMutant.getFinalText()).append(" ")
                    .append(loremIpsum.getWords(loremEnd,loremStart)).append(" ");
            loremStart = loremEnd +1;
            loremEnd = loremStart + random.nextInt(loremLength);
        }
        parentMutant.setFinalText(sb.toString());
        return parentMutant;
    }
 
Example #2
Source File: AT_03_AlignmentOptions.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	String text = new LoremIpsum().getWords(19);
	AT_Row row;
	at.addRule();
	row = at.addRow(text, text, text);
	row.getCells().get(0).getContext().setTextAlignment(TextAlignment.JUSTIFIED_LEFT);
	row.getCells().get(1).getContext().setTextAlignment(TextAlignment.JUSTIFIED);
	row.getCells().get(2).getContext().setTextAlignment(TextAlignment.JUSTIFIED_RIGHT);
	at.addRule();
	row = at.addRow(text, text, text);
	row.getCells().get(0).getContext().setTextAlignment(TextAlignment.LEFT);
	row.getCells().get(1).getContext().setTextAlignment(TextAlignment.CENTER);
	row.getCells().get(2).getContext().setTextAlignment(TextAlignment.RIGHT);
	at.addRule();
	System.out.println(at.render(79));
	// end::example[]
}
 
Example #3
Source File: AT_00g_AddColumn_DoesRenderToWidth.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectDoesRenderToWidth implements DoesRenderToWidth{
		@Override
		public String render(int width) {
			return new StrBuilder().appendWithSeparators(Text_To_FormattedText.left(new LoremIpsum().getWords(10), width), "\n").toString();
		}
	}

	at.addRule();
	at.addRow(new ObjectDoesRenderToWidth());
	at.addRule();
	System.out.println(at.render(30));
	// end::example[]
}
 
Example #4
Source File: AT_00d_AddColumn_HasText.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectHasText implements HasText{
		@Override
		public String getText() {
			return new LoremIpsum().getWords(10);
		}
	}

	at.addRule();
	at.addRow(new ObjectHasText());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #5
Source File: AT_00i_AddColumn_RendersToClusterWidth.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectRendersToClusterWidth implements RendersToClusterWidth{
		@Override
		public Collection<String> renderAsCollection(int width) {
			return ClusterElementTransformer.create().transform(
					Text_To_FormattedText.justified(new LoremIpsum().getWords(30), width),
					StrBuilder_To_String.create(),
					ArrayListStrategy.create()
			);
		}
	}

	at.addRule();
	at.addRow(new ObjectRendersToClusterWidth());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #6
Source File: AT_00h_AddColumn_RendersToCluster.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectRendersToCluster implements RendersToCluster{
		@Override
		public Collection<String> renderAsCollection() {
			ArrayList<String> text = new ArrayList<>();
			text.add(new LoremIpsum().getWords(10));
			text.add(new LoremIpsum().getWords(10));
			text.add(new LoremIpsum().getWords(10));
			return text;
		}
	}

	at.addRule();
	at.addRow(new ObjectRendersToCluster());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #7
Source File: AT_00e_AddColumn_HasTextCluster.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectHasTextCluster implements HasTextCluster{
		@Override
		public Collection<String> getTextAsCollection() {
			ArrayList<String> text = new ArrayList<>();
			text.add(new LoremIpsum().getWords(10));
			text.add(new LoremIpsum().getWords(10));
			text.add(new LoremIpsum().getWords(10));
			return text;
		}
	}

	at.addRule();
	at.addRow(new ObjectHasTextCluster());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #8
Source File: AT_00f_AddColumn_DoesRender.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectDoesRender implements DoesRender{
		@Override
		public String render() {
			return new LoremIpsum().getWords(10);
		}
	}

	at.addRule();
	at.addRow(new ObjectDoesRender());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #9
Source File: Test_CWC_LongestWord.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Test
public void test_Statics(){
	AsciiTable at;
	int[] cols;

	at = new AsciiTable();
	at.addRule();
	at.addRow("first row (col1)", "with some information (col2)");
	at.addRule();
	at.addRow("second row (col1)", "with some information (col2)");
	at.addRule();
	at.setPaddingLeftRight(1);

	cols = CWC_LongestWord.longestWord(at.getRawContent(), at.getColNumber());
	assertEquals(2, cols.length);
	assertEquals(8,  cols[0]);		// longest word: second (6) + padding
	assertEquals(13, cols[1]);		// longest word: information (11) + padding
	System.out.println(ArrayUtils.toString(cols));

	at = new AsciiTable();
	at.addRow(new LoremIpsum().getWords());
	at.setPaddingLeftRight(1);
	cols = CWC_LongestWord.longestWord(at.getRawContent(), at.getColNumber());
	assertEquals(1, cols.length);
	assertEquals(12,  cols[0]);		// longest word: sadipscing (10) + padding
	System.out.println(ArrayUtils.toString(cols));
}
 
Example #10
Source File: StringMutatorService.java    From CogStack-Pipeline with Apache License 2.0 5 votes vote down vote up
public Mutant generateMutantDocument(String[] stringsToMutate, String[] nonMutantStrings, int severity) {

        LoremIpsum loremIpsum = new LoremIpsum();
        int loremStart =0;
        int loremEnd =random.nextInt(loremLength);

        StringBuilder sb = new StringBuilder();
        sb.insert(0, loremIpsum.getWords(random.nextInt(loremLength)));
        Mutant parentMutant = new Mutant();
            for (int i = 0; i < stringsToMutate.length; i++) {
                Mutant childMutant = mutate(stringsToMutate[i], severity);
                parentMutant.getInputTokens().addAll(childMutant.getInputTokens());
                parentMutant.getOutputTokens().addAll(childMutant.getOutputTokens());
                sb.append(childMutant.getFinalText()).append(" ")
                        .append(loremIpsum.getWords(loremEnd,loremStart)).append(" ");
                loremStart = loremEnd +1;
                loremEnd = loremStart + random.nextInt(loremLength);
                if(loremEnd>49 ||loremStart>49){
                    loremStart =0;
                    loremEnd =random.nextInt(loremLength);
                }

                for(int j = 0;j<nonMutantStrings.length;j++){
                    sb.append(nonMutantStrings[j]).append(" ")
                            .append(loremIpsum.getWords(loremEnd,loremStart)).append(" ");
                    loremStart = loremEnd +1;
                    loremEnd = loremStart + random.nextInt(loremLength);
                    if(loremEnd>49 ||loremStart>49){
                        loremStart =0;
                        loremEnd =random.nextInt(loremLength);
                    }
                }
            }
        parentMutant.setFinalText(sb.toString());
        return parentMutant;
    }
 
Example #11
Source File: AT_03b_AlignmentRow.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	String text = new LoremIpsum().getWords(9);
	at.addRule();
	at.addRow(text, text, text);
	at.addRule();
	AT_Row row = at.addRow(text, text, text);
	at.addRule();
	row.setTextAlignment(TextAlignment.RIGHT);
	System.out.println(at.render(76));
	// end::example[]
}
 
Example #12
Source File: AT_03a_AlignmentTable.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	String text = new LoremIpsum().getWords(9);
	at.addRule();
	at.addRow(text, text, text);
	at.addRule();
	at.addRow(text, text, text);
	at.addRule();
	at.setTextAlignment(TextAlignment.RIGHT);
	System.out.println(at.render(76));
	// end::example[]
}
 
Example #13
Source File: AT_00c_AddColumn_ST.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	ST st = new ST(new LoremIpsum().getWords(10));
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow(st);
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #14
Source File: AT_03c_AlignmentCell.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	String text = new LoremIpsum().getWords(9);
	at.addRule();
	at.addRow(text, text, text);
	at.addRule();
	AT_Row row = at.addRow(text, text, text);
	at.addRule();
	row.getCells().get(2).getContext().setTextAlignment(TextAlignment.RIGHT);
	System.out.println(at.render(76));
	// end::example[]
}
 
Example #15
Source File: Article.java    From jinjava with Apache License 2.0 5 votes vote down vote up
public Article(int id, User user) throws NoSuchAlgorithmException {
  this.id = id;
  this.href = "/article/" + id;

  LoremIpsum ipsum = new LoremIpsum();
  SecureRandom rnd = SecureRandom.getInstanceStrong();

  this.title = ipsum.getWords(10);
  this.user = user;
  this.body = ipsum.getParagraphs();
  this.pubDate = Date.from(LocalDateTime.now().minusHours(rnd.nextInt(128)).toInstant(ZoneOffset.UTC));
  this.published = true;
}
 
Example #16
Source File: SampleFragment.java    From Fragment-Switcher with Apache License 2.0 5 votes vote down vote up
private ArrayList<String> generateRandomStrings() {
  ArrayList<String> strings = new ArrayList<String>(100);
  LoremIpsum loremIpsum = new LoremIpsum();
  Random random = new Random();
  for (int i = 0; i < 100; i++) {
    strings.add(loremIpsum.getWords(10,random.nextInt(50)));
  }
  return strings;
}
 
Example #17
Source File: FeedApp.java    From myfeed with Apache License 2.0 5 votes vote down vote up
@Bean
public RandomText randomText() {
	return new RandomText() {
		LoremIpsum loremIpsum = new LoremIpsum();

		@Override
		public String getText(int numWords) {
			String lorem = loremIpsum.getWords(numWords);
			String[] words = lorem.split(" ");
			List<String> list = Arrays.asList(words);
			Collections.shuffle(list);
			return StringUtils.collectionToDelimitedString(list, " ");
		}
	};
}
 
Example #18
Source File: PDFUtils.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate sample PDF
 */
public static void generateSample(int paragraphs, OutputStream os) throws DocumentException {
	LoremIpsum li = new LoremIpsum();
	Document doc = new Document(PageSize.A4, 25, 25, 25, 25);
	PdfWriter.getInstance(doc, os);
	doc.open();

	for (int i = 0; i < paragraphs; i++) {
		doc.add(new Paragraph(li.getParagraphs()));
	}

	doc.close();
}
 
Example #19
Source File: MSOUtils.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate sample docx
 */
public static void generateSample(int paragraphs, OutputStream os) throws Exception {
	WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
	MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
	LoremIpsum li = new LoremIpsum();

	for (int i = 0; i < paragraphs; i++) {
		mdp.addParagraphOfText(li.getParagraphs());
	}

	wordMLPackage.save(os);
}
 
Example #20
Source File: OOUtils.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate sample odt 
 */
public static void generateSample(int paragraphs, OutputStream os) throws Exception {
	LoremIpsum li = new LoremIpsum();
	OdfTextDocument odt = OdfTextDocument.newTextDocument();

	for (int i = 0; i < paragraphs; i++) {
		odt.newParagraph(li.getParagraphs());
		odt.newParagraph();
	}

	odt.save(os);
}
 
Example #21
Source File: Test_CWC_LongestWord.java    From asciitable with Apache License 2.0 4 votes vote down vote up
@Test
public void test_CodeForDoc(){
	AsciiTable at;
	int[] cols;
	CWC_LongestWord cwc = new CWC_LongestWord();

	at = new AsciiTable();
	at.addRule();
	at.addRow("first", "information");
	at.addRule();
	at.addRow("second", "info");
	at.addRule();
	cols = cwc.calculateColumnWidths(at.getRawContent(), at.getColNumber(), at.getContext());

	assertEquals(2, cols.length);
	assertEquals(6,  cols[0]);		// longest word: second (6)
	assertEquals(11, cols[1]);		// longest word: information (11)
	System.out.println(ArrayUtils.toString(cols));

	at = new AsciiTable();
	at.addRule();
	at.addRow("first", "information");
	at.addRule();
	at.addRow("second", "info");
	at.addRule();
	at.setPaddingLeftRight(1);
	cols = cwc.calculateColumnWidths(at.getRawContent(), at.getColNumber(), at.getContext());
	assertEquals(2, cols.length);
	assertEquals(8,  cols[0]);		// longest word: second (6) + padding 1*2
	assertEquals(13, cols[1]);		// longest word: information (11) + padding 1*2
	System.out.println(ArrayUtils.toString(cols));


	at = new AsciiTable();
	at.addRule();
	AT_Row row = at.addRow("first", "information");
	row.getCells().get(0).getContext().setPaddingLeftRight(2);
	row.getCells().get(1).getContext().setPaddingLeftRight(3);
	at.addRule();
	row = at.addRow("second", "info");
	row.getCells().get(0).getContext().setPaddingLeftRight(3);
	row.getCells().get(1).getContext().setPaddingLeftRight(4);
	at.addRule();
	cols = cwc.calculateColumnWidths(at.getRawContent(), at.getColNumber(), at.getContext());
	assertEquals(2, cols.length);
	assertEquals(12,  cols[0]);		// longest word: second (6) + padding 3*2
	assertEquals(17, cols[1]);		// longest word: information (11) + padding 3*2
	System.out.println(ArrayUtils.toString(cols));


	at = new AsciiTable();
	at.addRow(new LoremIpsum().getWords());
	at.setPaddingLeftRight(1);
	cols = cwc.calculateColumnWidths(at.getRawContent(), at.getColNumber(), at.getContext());
	assertEquals(1, cols.length);
	assertEquals(12,  cols[0]);		// longest word: sadipscing (10) + padding 1
	System.out.println(ArrayUtils.toString(cols));
}