/* Copyright 2016 Sven van der Meer <[email protected]> * * 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 de.vandermeer.asciitable.examples; import org.apache.commons.lang3.text.StrBuilder; import de.svenjacobs.loremipsum.LoremIpsum; import de.vandermeer.asciitable.AsciiTable; import de.vandermeer.skb.interfaces.StandardExampleAsCmd; import de.vandermeer.skb.interfaces.render.HasText; /** * AsciiTable example demonstrating that {@link HasText} objects are automatically added as text. * * @author Sven van der Meer <[email protected]> * @version v0.3.2 build 170502 (02-May-17) for Java 1.8 * @since v0.0.3 */ public class AT_00d_AddColumn_HasText implements StandardExampleAsCmd { @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[] } @Override public StrBuilder getSource(){ String[] source = new String[]{ "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());", }; return new StrBuilder().appendWithSeparators(source, "\n"); } @Override public String getDescription() { // TODO Auto-generated method stub return null; } @Override public String getID() { // TODO Auto-generated method stub return null; } }