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 shouldReturnTextType() throws Exception { // when/* ww w. j av a2s . c om*/ FieldType fieldType = new TextType(); // then assertThat(fieldType, is(TextType.class)); assertEquals(String.class, fieldType.getType()); assertTrue(fieldType.toObject(fieldDefinition, "test").isValid()); assertTrue(fieldType.toObject(fieldDefinition, StringUtils.repeat("a", 2048)).isValid()); assertTrue(fieldType.toObject(fieldDefinition, StringUtils.repeat("a", 2049)).isValid()); }
From source file:com.enonic.cms.itest.content.ContentServiceImpl_createContentTest.java
@Test public void testCreateContentNameTooLong() { CreateContentCommand command = createCreateContentCommand(ContentStatus.DRAFT); command.setContentName(StringUtils.repeat("x", ContentNameValidator.CONTENT_NAME_MAX_LENGTH + 1)); try {/*from w w w . java 2 s . c o m*/ contentService.createContent(command); fail("Expected exception"); } catch (Throwable e) { assertTrue(e instanceof CreateContentException); assertTrue(e.getMessage().toLowerCase().contains("too long")); } }
From source file:com.github.cereda.arara.langchecker.LanguageUtils.java
/** * Prints the report for every language report. * @param languages The list of language reports. *//*from www .j av a 2s. c o m*/ public static void printReport(List<LanguageReport> languages) { // print header System.out.println(StringUtils.center(" Language coverage report ", 60, "-").concat("\n")); // let's sort our list of reports according to // each language coverage Collections.sort(languages, new Comparator<LanguageReport>() { @Override public int compare(LanguageReport t1, LanguageReport t2) { // get values of each language float a1 = t1.getCoverage(); float a2 = t2.getCoverage(); // they are equal, do nothing if (a1 == a2) { return 0; } else { // we want to sort in reverse order, // so return a negative value here if (a1 > a2) { return -1; } else { // return a positive value, since // the first statement was false return 1; } } } }); // list of languages to be fixed List<LanguageReport> fix = new ArrayList<>(); // for each report, print // the corresponding entry for (LanguageReport language : languages) { // if there are problematic lines, // add the current language report if (!language.getLines().isEmpty()) { fix.add(language); } // build the beginning of the line String line = String.format("- %s ", language.getReference().getName()); // build the coverage information String coverage = String.format(" %2.2f%%", language.getCoverage()); // generate the line by concatenating // the beginning and coverage line = line.concat(StringUtils.repeat(".", 60 - line.length() - coverage.length())).concat(coverage); // print the line System.out.println(line); } // we have some fixes to do if (!fix.isEmpty()) { // print header System.out.println(); System.out.println(StringUtils.center(" Lines to fix ", 60, "-").concat("\n")); // print legend for a simple message System.out.println(StringUtils.center("S: Simple message, single quotes should not be doubled", 60)); // print legend for a parametrized System.out.println( StringUtils.center("P: Parametrized message, single quotes must be doubled", 60).concat("\n")); // print a line separator System.out.println(StringUtils.repeat("-", 60)); // print each language and its // corresponding lines for (LanguageReport report : fix) { // build the beginning of the line String line = String.format("- %s ", report.getReference().getName()); // build the first batch String batch = pump(report.getLines(), 2); // generate the line by concatenating // the beginning and batch line = line.concat(StringUtils.repeat(" ", 60 - line.length() - batch.length())).concat(batch); // print the line System.out.println(line); // get the next batch, if any batch = pump(report.getLines(), 2); // repeat while there // are other batches while (!batch.isEmpty()) { // print current line System.out.println(StringUtils.leftPad(batch, 60)); // get the next batch and let // the condition handle it batch = pump(report.getLines(), 2); } // print a line separator System.out.println(StringUtils.repeat("-", 60)); } } }
From source file:de.codesourcery.jasm16.utils.FormattingVisitor.java
@Override public void visit(InstructionNode node, IIterationContext context) { final LabelNode label = getLabelNode(node); final String labelText = label != null ? toString(label) : ""; final StringBuilder result = new StringBuilder(); if (label == null) { result.append(StringUtils.repeat(" ", column0Width)); }//from w w w. jav a2s . co m result.append(node.getOpCode().getIdentifier() + " "); final List<OperandNode> operands = node.getOperands(); for (Iterator<OperandNode> it = operands.iterator(); it.hasNext();) { final OperandNode operandNode = it.next(); String sourceCode; try { final ITextRegion range = operandNode.getTextRegion(); if (range != null) { sourceCode = compilationUnit.getSource(range).replaceAll("\t", " ").trim(); } else { sourceCode = "<no text range available>"; } } catch (IOException e) { sourceCode = "<could not read source: " + e.getMessage() + ">"; } result.append(sourceCode); if (it.hasNext()) { result.append(","); } } final int width = 60 - labelText.length(); final String txt = Misc.padRight(result.toString(), width); if (label != null) { output(txt); } else { output(txt); } if (printOpcodesInHex) { final HexStringWriter writer = new HexStringWriter(true); for (ObjectCodeOutputNode out : getStatementNode(node).getObjectOutputNodes()) { try { out.writeObjectCode(writer, this.context); } catch (Exception e) { /* ok */ } } output("; " + writer.toString()); } }
From source file:com.qcadoo.model.integration.FieldModuleIntegrationTest.java
License:asdf
@Test public void shouldCallAndPassDefaultIntegerFieldValidators() throws Exception { // given//ww w . j a v a 2 s .c om Integer integer = Integer.parseInt(StringUtils.repeat("1", 10)); // when & then performFieldValidationTestOnPart("weight", integer, true); }
From source file:com.enonic.cms.itest.content.ContentServiceImpl_updateContentTest.java
@Test public void testUpdateContentMaximumNameLength() { UserEntity testUser = fixture.findUserByName("testuser"); CreateContentCommand createCommand = createCreateContentCommand(ContentStatus.DRAFT.getKey(), testUser); ContentKey contentKey = contentService.createContent(createCommand); fixture.flushAndClearHibernateSesssion(); ContentEntity persistedContent = contentDao.findByKey(contentKey); UpdateContentCommand command = createUpdateContentCommand(contentKey, persistedContent.getDraftVersion().getKey(), ContentStatus.DRAFT.getKey(), false, false); String newName = StringUtils.repeat("x", ContentNameValidator.CONTENT_NAME_MAX_LENGTH); command.setContentName(newName);/* w w w . j a v a 2s . c o m*/ UpdateContentResult result = contentService.updateContent(command); assertTrue("Content should have been updated", result.isAnyChangesMade()); fixture.flushAndClearHibernateSesssion(); persistedContent = contentDao.findByKey(contentKey); assertNotNull(persistedContent.getTimestamp()); assertEquals("Content name should have been updated", persistedContent.getName(), newName); }
From source file:com.griddynamics.jagger.diagnostics.reporting.ProfileReporter.java
private static MethodElement assembleMethodElement(MethodProfile profile, int offset) { MethodElement dto = new MethodElement(); dto.setMethodId(StringUtils.repeat(" ", offset) + profile.getMethod().toString()); dto.setInStackRatio(profile.getInStackRatio()); dto.setOnTopRatio(profile.getOnTopRatio()); return dto;//w w w . j av a 2 s . co m }
From source file:de.codesourcery.jasm16.emulator.devices.impl.DefaultScreen.java
protected void logDebugHeadline(String msg) { if (emulator != null && emulator.getOutput().isDebugEnabled()) { final String separator = StringUtils.repeat("*", msg.length() + 4) + "\n"; emulator.getOutput().debug("\n" + separator + "* " + msg + " *\n" + separator); }/*from w w w . j av a 2s . c o m*/ }
From source file:mitm.common.util.MiscStringUtils.java
/** * Replaces the last chars with replaceCharWith * // w w w .j a v a 2 s.c om * Example: * * replaceLastChars("abc123", 3, "mn") returns "abcmnmnmn" */ public static String replaceLastChars(String input, int lastChars, String replaceCharWith) { input = StringUtils.defaultString(input); int maxLength = input.length() - lastChars; if (maxLength < 0) { maxLength = 0; } String dots = StringUtils.repeat(StringUtils.defaultString(replaceCharWith), input.length() - maxLength); return StringUtils.substring(input, 0, maxLength) + dots; }
From source file:com.alibaba.doris.client.DataStoreTest.java
/** * Test Name: key256, Expected Result: client *///from w ww . j a v a 2 s .com public void testPutKeyLngth500() { String key = StringUtils.repeat("A", 300); System.out.println(key.length()); String value = "value003"; try { dataStore.put(key, value); fail("Out of Length Key!"); } catch (IllegalArgumentException e) { } }