List of usage examples for org.apache.commons.lang StringUtils repeat
public static String repeat(String str, int repeat)
Repeat a String repeat
times to form a new String.
From source file:com.qcadoo.model.types.FieldTypeFactoryTest.java
@Test public void shouldReturnStringType() throws Exception { // when//from w w w .java 2s. c o m FieldType fieldType = new StringType(); // then assertThat(fieldType, is(StringType.class)); assertEquals(String.class, fieldType.getType()); assertTrue(fieldType.toObject(fieldDefinition, "test").isValid()); assertTrue(fieldType.toObject(fieldDefinition, StringUtils.repeat("a", 255)).isValid()); assertTrue(fieldType.toObject(fieldDefinition, StringUtils.repeat("a", 300)).isValid()); }
From source file:com.runstate.util.StringW.java
/** * Word-wrap a string./*from w w w .j a v a 2 s. c om*/ * * @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 * * @return String that has been word wrapped */ static public String wordWrap(String str, int width, String delim, String split) { int sz = str.length(); /// 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 will include a delim on the end width = width - delim.length(); 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); // is the delim already on the line idx = substr.indexOf(delim); 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:com.enonic.cms.itest.content.ContentServiceImpl_createContentTest.java
@Test public void testCreateContentMaximumNameLength() { Date startTime = Calendar.getInstance().getTime(); CreateContentCommand command = createCreateContentCommand(ContentStatus.DRAFT); command.setContentName(StringUtils.repeat("x", ContentNameValidator.CONTENT_NAME_MAX_LENGTH)); ContentKey contentKey = contentService.createContent(command); ContentEntity persistedContent = contentDao.findByKey(contentKey); assertNotNull(persistedContent.getTimestamp()); assertTrue(startTime.compareTo(persistedContent.getTimestamp()) <= 0); }
From source file:com.tesora.dve.common.PEStringUtils.java
public static String buildIndent(final int numIndents) { return StringUtils.repeat(DEFAULT_INDENT, numIndents); }
From source file:de.codesourcery.jasm16.ast.ASTUtils.java
private static void printAST(ICompilationUnit unit, ASTNode currentNode, int currentDepth, StringBuilder result) throws IOException { final String indent = StringUtils.repeat(" ", currentDepth * 2); final String contents = unit.getSource(currentNode.getTextRegion()); final String src = ">" + contents + "<"; result.append(indent + " " + currentNode.getClass().getSimpleName() + " (" + src + ")").append("\n"); for (ASTNode child : currentNode.getChildren()) { printAST(unit, child, currentDepth + 1, result); }/*from w ww. j av a 2 s . co m*/ }
From source file:com.tesora.dve.common.PEStringUtils.java
public static String buildIndent(final String indent, final int numIndents) { return StringUtils.repeat(indent, numIndents); }
From source file:adalid.core.DisplayField.java
@Override protected String mapsToString(int n, String key, boolean verbose, boolean fields, boolean maps) { String tab = verbose ? StringUtils.repeat(" ", 4) : ""; String fee = verbose ? StringUtils.repeat(tab, n) : ""; String faa = " = "; String foo = verbose ? EOL : ", "; String string = super.mapsToString(n, key, verbose, fields, maps); if (maps || verbose) { if (_children != null && !_children.isEmpty()) { string += fee + tab + DisplayField.class.getSimpleName() + "[] children {" + foo; for (DisplayField field : _children) { string += field.toString(n + 2, null, verbose, fields, maps); }/*w w w .ja v a2 s . c om*/ string += fee + tab + "}"; } } return string; }
From source file:com.qcadoo.model.integration.FieldModuleIntegrationTest.java
License:asdf
@Test public void shouldCallAndFailDefaultMaxUnscaledValueLenFieldValidators() throws Exception { // given/*from w w w. j av a 2s. co m*/ BigDecimal tooPreciseDecimal = new BigDecimal(StringUtils.repeat("9", 20) + ".0"); // when & then Entity savedPart = performFieldValidationTestOnPart("price", tooPreciseDecimal, false); Assert.assertEquals("qcadooView.validate.field.error.invalidPrecision.max", savedPart.getError("price").getMessage()); }
From source file:info.magnolia.cms.filters.FilterManagerImpl.java
private void printFilter(int indentation, MgnlFilter filter) { log.debug("{}{} ({})", new Object[] { StringUtils.repeat(" ", indentation), filter.getName(), filter.toString() }); if (filter instanceof CompositeFilter) { for (MgnlFilter nestedFilter : ((CompositeFilter) filter).getFilters()) { printFilter(indentation + 2, nestedFilter); }/* www. j a v a 2 s . c o m*/ } }
From source file:adalid.core.Report.java
@Override protected String fieldsToString(int n, String key, boolean verbose, boolean fields, boolean maps) { String tab = verbose ? StringUtils.repeat(" ", 4) : ""; String fee = verbose ? StringUtils.repeat(tab, n) : ""; String faa = " = "; String foo = verbose ? EOL : ", "; String string = super.fieldsToString(n, key, verbose, fields, maps); if (fields || verbose) { if (verbose) { if (_entity != null) { string += fee + tab + "entity" + faa + _entity + foo; }//from w w w .j a va2s. com if (_view != null) { string += fee + tab + "view" + faa + _view + foo; } } } return string; }