Example usage for org.apache.commons.lang StringUtils repeat

List of usage examples for org.apache.commons.lang StringUtils repeat

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils repeat.

Prototype

public static String repeat(String str, int repeat) 

Source Link

Document

Repeat a String repeat times to form a new String.

Usage

From source file:org.apache.openjpa.jdbc.meta.strats.AbstractLobTest.java

protected String createLobData2() {
    return StringUtils.repeat("iiIIIIii, ", 1000);
}

From source file:org.apache.openjpa.persistence.xmlmapping.query.TestXMLCustomerOrder.java

private USAAddress createUSAAddress(String name) {
    USAAddress address = new ObjectFactory().createUSAAddress();
    address.setName(name);//from www.  j  a v  a  2 s.c o m
    // Use a 4000-byte value so the entire XML string is longer than 4000 bytes - ensure Oracle handles this.
    address.getStreet().add(StringUtils.repeat("12500 Mont", 400));
    address.setCity("San Jose");
    address.setState("CA");
    address.setZIP(95141);
    return address;
}

From source file:org.apache.qpid.disttest.client.MessageProvider.java

protected String getMessagePayload(final CreateProducerCommand command) {
    FutureTask<String> createTextFuture = new FutureTask<String>(new Callable<String>() {
        @Override//from  w  w  w  .j av a2 s. c o  m
        public String call() throws Exception {
            return StringUtils.repeat("a", command.getMessageSize());
        }
    });

    Future<String> future = _payloads.putIfAbsent(command.getMessageSize(), createTextFuture);
    if (future == null) {
        createTextFuture.run();
        future = createTextFuture;
    }
    String payload = null;
    try {
        payload = future.get();
    } catch (Exception e) {
        throw new DistributedTestException("Unable to create message payload :" + e.getMessage(), e);
    }
    return payload;
}

From source file:org.apache.roller.weblogger.ui.tags.StringW.java

/**
 * Word-wrap a string./* w  ww . j  a va 2  s  .  c  o m*/
 *
 * @param str   String to word-wrap
 * @param width int to wrap at
 * @param delim String to use to separate lines
 * @param split String to use to split a word greater than width long
 * @param delimInside wheter or not delim should be included in chunk before length reaches width.
 *
 * @return String that has been word wrapped
 */
static public String wordWrap(String str, int width, String delim, String split, boolean delimInside) {
    int sz = str.length();

    //        System.err.println( ">>>> inside: " + delimInside  + " sz : " + sz );

    /// shift width up one. mainly as it makes the logic easier
    width++;

    // our best guess as to an initial size
    StringBuffer buffer = new StringBuffer(sz / width * delim.length() + sz);

    // every line might include a delim on the end
    //        System.err.println( "width before: "+ width );
    if (delimInside) {
        width = width - delim.length();
    } else {
        width--;
    }
    //        System.err.println( "width after: "+ width );

    int idx = -1;
    String substr = null;

    // beware: i is rolled-back inside the loop
    for (int i = 0; i < sz; i += width) {

        // on the last line
        if (i > sz - width) {
            buffer.append(str.substring(i));
            //                System.err.print("LAST-LINE: "+str.substring(i));
            break;
        }

        //            System.err.println("loop[i] is: "+i);
        // the current line
        substr = str.substring(i, i + width);
        //            System.err.println( "substr: " + substr );

        // is the delim already on the line
        idx = substr.indexOf(delim);
        //            System.err.println( "i: " + i + " idx : " + idx );
        if (idx != -1) {
            buffer.append(substr.substring(0, idx));
            //                System.err.println("Substr: '"substr.substring(0,idx)+"'");
            buffer.append(delim);
            i -= width - idx - delim.length();

            //                System.err.println("loop[i] is now: "+i);
            //                System.err.println("ounfd-whitespace: '"+substr.charAt(idx+1)+"'.");
            // Erase a space after a delim. Is this too obscure?
            if (substr.length() > idx + 1) {
                if (substr.charAt(idx + 1) != '\n') {
                    if (Character.isWhitespace(substr.charAt(idx + 1))) {
                        i++;
                    }
                }
            }
            //                System.err.println("i -= "+width+"-"+idx);
            continue;
        }

        idx = -1;

        // figure out where the last space is
        char[] chrs = substr.toCharArray();
        for (int j = width; j > 0; j--) {
            if (Character.isWhitespace(chrs[j - 1])) {
                idx = j;
                //                    System.err.println("Found whitespace: "+idx);
                break;
            }
        }

        // idx is the last whitespace on the line.
        //            System.err.println("idx is "+idx);
        if (idx == -1) {
            for (int j = width; j > 0; j--) {
                if (chrs[j - 1] == '-') {
                    idx = j;
                    //                        System.err.println("Found Dash: "+idx);
                    break;
                }
            }
            if (idx == -1) {
                buffer.append(substr);
                buffer.append(delim);
                //                    System.err.print(substr);
                //                    System.err.print(delim);
            } else {
                if (idx != width) {
                    idx++;
                }
                buffer.append(substr.substring(0, idx));
                buffer.append(delim);
                //                    System.err.print(substr.substring(0,idx));
                //                    System.err.print(delim);
                i -= width - idx;
            }
        } else {
            /*
            if(force) {
            if(idx == width-1) {
                buffer.append(substr);
                buffer.append(delim);
            } else {
                // stick a split in.
                int splitsz = split.length();
                buffer.append(substr.substring(0,width-splitsz));
                buffer.append(split);
                buffer.append(delim);
                i -= splitsz;
            }
            } else {
            */
            // insert spaces
            buffer.append(substr.substring(0, idx));
            buffer.append(StringUtils.repeat(" ", width - idx));
            //                    System.err.print(substr.substring(0,idx));
            //                    System.err.print(StringUtils.repeat(" ",width-idx));
            buffer.append(delim);
            //                    System.err.print(delim);
            //                    System.err.println("i -= "+width+"-"+idx);
            i -= width - idx;
            //                }
        }
    }
    //        System.err.println("\n*************");
    return buffer.toString();
}

From source file:org.apache.shindig.common.JsonSerializerTest.java

public static Map<String, Object> perfComparison100LargeValues() {
    Map<String, Object> data = Maps.newHashMap();
    for (int i = 0; i < 100; ++i) {
        data.put("key-" + i, StringUtils.repeat("small value", 100));
    }/*w w w  . ja  v  a 2s . com*/
    return data;
}

From source file:org.apache.shindig.common.JsonSerializerTest.java

public static Map<String, Object> perfComparison10LargeValuesAndEscapes() {
    Map<String, Object> data = Maps.newHashMap();
    for (int i = 0; i < 10; ++i) {
        data.put("key-" + i, StringUtils.repeat("\tsmall\r value \\foo\b\uFFFF\uBCAD\n\u0083", 100));
    }//w ww.java 2s . c om
    return data;
}

From source file:org.apache.shindig.gadgets.variables.SubstitutionsTest.java

@Test
@Ignore("off by default, TODO add test logic")
public void loadTest() throws Exception {
    String msg = "Random text and __UP_hello__, amongst other words __MSG_world__ stuff __weeeeee";
    subst.addSubstitution(Type.MESSAGE, "world", "planet __MSG_earth____UP_punc__");
    subst.addSubstitution(Type.MESSAGE, "earth", "Earth");
    subst.addSubstitution(Type.USER_PREF, "punc", "???");
    subst.addSubstitution(Type.USER_PREF, "hello", "Greetings __MSG_foo____UP_bar__");
    subst.addSubstitution(Type.MESSAGE, "foo", "FOO!!!");
    subst.addSubstitution(Type.USER_PREF, "bar", "BAR!!!");

    // Most real-world content contains very few substitutions.
    msg += StringUtils.repeat("foo ", 1000);

    String message = StringUtils.repeat(msg, 1000);

    long now = System.nanoTime();
    int cnt = 1000;
    for (int i = 0; i < cnt; ++i) {
        subst.substituteString(message);
    }/* w w  w .ja  v  a 2s. c  om*/
    long duration = System.nanoTime() - now;
    System.out.println("Duration: " + duration + " avg: " + duration / cnt);
}

From source file:org.apache.sling.scripting.sightly.impl.html.dom.HtmlParserTest.java

/**
 * Pretty print a template nodes structure for debugging of failed tests
 *
 * @param indentation - indentation level (the method is used recursively)
 * @param node - template nodes to print
 *///from  w  w w  .j a  v a2s  .co  m
private static void print(int indentation, TemplateNode node) {
    if (node == null) {
        return;
    }

    List<TemplateNode> children = null;
    String name = "UNKNOWN";

    if (node.getClass() == Template.class) {
        Template template = (Template) node;
        children = template.getChildren();
        name = template.getName();
    } else if (node.getClass() == TemplateElementNode.class) {
        TemplateElementNode element = (TemplateElementNode) node;
        children = element.getChildren();
        name = "ELEMENT: " + element.getName();
    } else if (node.getClass() == TemplateTextNode.class) {
        name = "TEXT: " + ((TemplateTextNode) node).getText();
    } else if (node.getClass() == TemplateCommentNode.class) {
        name = "COMMENT: " + ((TemplateCommentNode) node).getText();
    }

    System.out.print(StringUtils.repeat("\t", indentation));
    System.out.println(name.replace("\n", "\\n").replace("\r", "\\r"));
    if (children == null) {
        return;
    }
    for (TemplateNode child : children) {
        print(indentation + 1, child);
    }
}

From source file:org.apache.solr.common.util.TestJsonRecordReader.java

License:asdf

public void testSrcField() throws Exception {
    String json = "{\n" + "  \"id\" : \"123\",\n" + "  \"description\": \"Testing /json/docs srcField 1\",\n"
            + "\n" + "  \"nested_data\" : {\n" + "    \"nested_inside\" : \"check check check 1\"\n" + "  }\n"
            + "}";

    String json2 = " {\n" + "  \"id\" : \"345\",\n" + "  \"payload\": \""
            + StringUtils.repeat("0123456789", 819) + "\",\n"
            + "  \"description\": \"Testing /json/docs srcField 2\",\n" + "\n" + "  \"nested_data\" : {\n"
            + "    \"nested_inside\" : \"check check check 2\"\n" + "  }\n" + "}";

    String json3 = " {\n" + "  \"id\" : \"678\",\n" + "  \"description\": \"Testing /json/docs srcField 3\",\n"
            + "\n" + "  \"nested_data\" : {\n" + "    \"nested_inside\" : \"check check check 3\"\n" + "  }\n"
            + "}";

    JsonRecordReader streamer = JsonRecordReader.getInst("/", Arrays.asList("id:/id"));
    RecordingJSONParser parser = new RecordingJSONParser(new StringReader(json + json2 + json3));

    streamer.streamRecords(parser, new JsonRecordReader.Handler() {
        int count = 0;

        @Override/*  w  ww.j av a2  s . c  o m*/
        public void handle(Map<String, Object> record, String path) {
            count++;
            String buf = parser.getBuf();
            parser.resetBuf();

            Map m = (Map) Utils.fromJSONString(buf);
            if (count == 1) {
                assertEquals(m.get("id"), "123");
                assertEquals(m.get("description"), "Testing /json/docs srcField 1");
                assertEquals(((Map) m.get("nested_data")).get("nested_inside"), "check check check 1");
            }
            if (count++ == 2) {
                assertEquals(m.get("id"), "345");
                assertEquals(m.get("description"), "Testing /json/docs srcField 2");
                assertEquals(((Map) m.get("nested_data")).get("nested_inside"), "check check check 2");
            }
            if (count++ == 3) {
                assertEquals(m.get("id"), "678");
                assertEquals(m.get("description"), "Testing /json/docs srcField 3");
                assertEquals(((Map) m.get("nested_data")).get("nested_inside"), "check check check 3");
            }

        }
    });

}

From source file:org.apache.sqoop.shell.utils.TableDisplayer.java

/**
 * Draw border line// ww  w.ja  v a2 s .  c om
 *
 * @param widths List of widths of each column
 */
private static void drawLine(List<Integer> widths) {
    int last = widths.size() - 1;
    print("+-");
    for (int i = 0; i < widths.size(); i++) {
        print(StringUtils.repeat("-", widths.get(i)));
        print((i == last) ? "-+" : "-+-");
    }
    println();
}