List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:org.sejda.core.support.prefix.processor.PrefixUtilsTest.java
@Test public void testStrictFilename() { assertEquals("1_Invoice0001.pdf", PrefixUtils.toStrictFilename("1_Invoice#0001:*<>/\\.pdf")); assertEquals(StringUtils.repeat('a', 255), PrefixUtils.toStrictFilename(StringUtils.repeat('a', 256))); }
From source file:org.sejda.model.pdf.numbering.BatesSequence.java
public BatesSequence(long startFrom, int step, int digits) { this.current = startFrom; this.step = step; this.decimalFormat = new DecimalFormat(StringUtils.repeat('0', digits)); }
From source file:org.shadowmask.core.mask.rules.generalizer.impl.ShadeGeneralizer.java
@Override public String generalize(String input, int hierarchyLevel) { if (input == null) { return null; }/*from w w w . j a va2 s . c o m*/ if (hierarchyLevel > rootLevel || hierarchyLevel < 0) { throw new MaskRuntimeException("Root hierarchy level of ShadeGeneralizer is " + rootLevel + ", invalid input hierarchy level[" + hierarchyLevel + "]"); } if (hierarchyLevel == 0) { return input; } if (input.length() <= hierarchyLevel) { return StringUtils.repeat(shadeChar, input.length()); } return input.substring(0, input.length() - hierarchyLevel) + StringUtils.repeat(shadeChar, hierarchyLevel); }
From source file:org.slf4j.impl.CasDelegatingLogger.java
/** * Remove ticket id from the log message. * * @param msg the message/* w w w . j av a2 s. com*/ * @return the modified message with tgt id removed */ private String removeTicketId(final String msg) { String modifiedMessage = msg; final Matcher matcher = TICKET_ID_PATTERN.matcher(msg); while (matcher.find()) { final String match = matcher.group(); final String newId = matcher.group(1) + "-" + StringUtils.repeat("*", match.length() - VISIBLE_ID_TAIL_LENGTH) + StringUtils.right(match, VISIBLE_ID_TAIL_LENGTH); modifiedMessage = modifiedMessage.replaceAll(match, newId); } return modifiedMessage; }
From source file:org.starnub.utilities.strings.StringUtilities.java
/** * * This will search for words and replace them if they match within a certain percentage * * @param s String to be searched//from w w w. ja v a 2 s. c o m * @param wordToSearch String the word to be matched * @param percentToMatch double the percent to match * @param replaceWholeWord boolean replace the word with characters (true) or not (false) * @param replacementChar String the character to replace the word with * @return String the cleaned string */ public static String wordSearchReplacement(String s, String wordToSearch, double percentToMatch, boolean replaceWholeWord, String replacementChar) { double highEstMatch = 0; boolean firstTime = true; while (highEstMatch > percentToMatch || firstTime) { firstTime = false; int start = 0; int end = wordToSearch.length(); int s2Len = s.length(); int highStart = 0; int highEnd = 0; highEstMatch = 0; if (end <= s2Len) { boolean replace = false; while (end <= s2Len) { int stringsToChange = StringUtils.getLevenshteinDistance(wordToSearch.toLowerCase(), s.substring(start, end).toLowerCase()); double percentMatched = (100 - ((stringsToChange * 100) / end)); if (percentMatched >= percentToMatch && highEstMatch < percentMatched) { highEstMatch = percentMatched / end; highStart = start; highEnd = end; replace = true; } start++; end++; } String rS = ""; if (replaceWholeWord) { rS = StringUtils.repeat(replacementChar, s.substring(highStart, highEnd).length()); } } } return s; }
From source file:org.tdar.core.service.ReflectionService.java
private void walkObject(Persistable p, int indent, Set<String> seen) { List<Pair<Field, Class<? extends Persistable>>> findAllPersistableFields = findAllPersistableFields( p.getClass());//from w ww .j a v a 2s.c o m String key = makeKey(p); if (seen.contains(key)) { logger.debug("{}[{}] {}", StringUtils.repeat("| ", indent + 1), "seen", p); return; } seen.add(key); for (Pair<Field, Class<? extends Persistable>> pair : findAllPersistableFields) { Object content = callFieldGetter(p, pair.getFirst()); if (content == null) { logger.trace("{}{}", StringUtils.repeat("| ", indent + 1), pair.getFirst()); continue; } logger.trace("{}, {}", content, pair.getFirst()); if (Collection.class.isAssignableFrom(content.getClass())) { @SuppressWarnings("unchecked") Collection<Persistable> originalList = (Collection<Persistable>) content; Collection<Persistable> contents = new ArrayList<Persistable>(originalList); // using a separate collection to avoid concurrent modification of bi-directional double-lists if (CollectionUtils.isNotEmpty(contents)) { logger.debug("{}{}", StringUtils.repeat("| ", indent + 1), pair.getFirst().getName()); } Iterator<Persistable> iterator = contents.iterator(); while (iterator.hasNext()) { Persistable p_ = iterator.next(); boolean sessionContains = genericDao.sessionContains(p_); logger.debug("{}[{}] {}", StringUtils.repeat("| ", indent + 2), sessionContains, p_); if (sessionContains) { walkObject(p_, indent + 2, seen); } } } else { boolean sessionContains = genericDao.sessionContains(content); logger.debug("{}[{}] {} {}", StringUtils.repeat("| ", indent + 1), sessionContains, pair.getFirst().getName(), content); if (sessionContains) { walkObject((Persistable) content, indent + 1, seen); } } } }
From source file:org.testeditor.fixture.swt.SWTFixture.java
private void printTreeItems(SWTBotTreeItem[] items, int level) { String spaces = StringUtils.repeat(" ", 4 * level); for (SWTBotTreeItem item : items) { logger.info("{}|-- {}", spaces, item.getText()); if (!item.isExpanded()) { item.expand();/* ww w . j a v a 2s . c o m*/ } printTreeItems(item.getItems(), level + 1); } }
From source file:org.trimou.engine.segment.Segments.java
private static String getSegmentTreeInternal(int level, AbstractContainerSegment container) { StringBuilder tree = new StringBuilder(); tree.append(LINE_SEPARATOR);//w ww .ja v a 2 s. c o m if (level > 1) { tree.append(StringUtils.repeat(" ", level - 1)); } tree.append("+"); if (!SegmentType.ROOT.equals(container.getType())) { tree.append(container.getTemplate().getName()); tree.append(":"); } tree.append(container.getType()); tree.append(":"); tree.append(container.getText()); for (Segment segment : container.getSegments()) { if (segment instanceof AbstractContainerSegment) { tree.append(getSegmentTreeInternal(level + 1, (AbstractContainerSegment) segment)); } else { tree.append(LINE_SEPARATOR); tree.append(StringUtils.repeat(" ", level)); tree.append("-"); tree.append(segment.getOrigin().getTemplateName()); tree.append(":"); tree.append(segment.getType()); if (segment.getType().hasName()) { tree.append(":"); tree.append(segment.getText()); } } } return tree.toString(); }
From source file:org.trnltk.util.DiffUtil.java
private static String[] diffToFormattedLines(final List<diff_match_patch.Diff> diffs, boolean ignoreWhiteSpace) { final StringBuilder modifiedSourceLineBuilder = new StringBuilder(); final StringBuilder markerLineBuilder = new StringBuilder(); final StringBuilder differenceLineBuilder = new StringBuilder(); for (int i = 0; i < diffs.size(); i++) { final diff_match_patch.Diff currentDiff = diffs.get(i); if (ignoreWhiteSpace && StringUtils.isBlank(currentDiff.text)) continue; final diff_match_patch.Diff previousDiff = getPreviousNotEqualNotBlankDiff(diffs, i); final diff_match_patch.Diff nextDiff = getNextNotEqualNotBlankDiff(diffs, i); switch (currentDiff.operation) { case INSERT: { if (previousDiff != null && previousDiff.operation.equals(diff_match_patch.Operation.DELETE)) { continue; }/*w ww. j av a 2s. c o m*/ modifiedSourceLineBuilder.append(StringUtils.repeat(' ', currentDiff.text.length())); markerLineBuilder.append(StringUtils.repeat('+', currentDiff.text.length())); differenceLineBuilder.append(currentDiff.text); break; } case DELETE: { if (nextDiff != null && nextDiff.operation.equals(diff_match_patch.Operation.INSERT)) { // consider as a replace, except trimmed str's are same. then we should act upon param ignoreWhiteSpace final int lengthDifference = currentDiff.text.length() - nextDiff.text.length(); if (currentDiff.text.trim().equals(nextDiff.text.trim()) && ignoreWhiteSpace) { modifiedSourceLineBuilder.append(currentDiff.text); markerLineBuilder.append(StringUtils.repeat(' ', currentDiff.text.length())); differenceLineBuilder.append(StringUtils.repeat(' ', currentDiff.text.length())); } else { if (lengthDifference < 0) { modifiedSourceLineBuilder.append(currentDiff.text); modifiedSourceLineBuilder.append(StringUtils.repeat(' ', -1 * lengthDifference)); markerLineBuilder.append(StringUtils.repeat('^', nextDiff.text.length())); differenceLineBuilder.append(nextDiff.text); } else { modifiedSourceLineBuilder.append(currentDiff.text); markerLineBuilder.append(StringUtils.repeat('^', currentDiff.text.length())); differenceLineBuilder.append(nextDiff.text); differenceLineBuilder.append(StringUtils.repeat(' ', lengthDifference)); } } } else { modifiedSourceLineBuilder.append(currentDiff.text); markerLineBuilder.append(StringUtils.repeat('-', currentDiff.text.length())); differenceLineBuilder.append(StringUtils.repeat(' ', currentDiff.text.length())); } break; } case EQUAL: { modifiedSourceLineBuilder.append(currentDiff.text); markerLineBuilder.append(StringUtils.repeat(' ', currentDiff.text.length())); differenceLineBuilder.append(StringUtils.repeat(' ', currentDiff.text.length())); break; } } } return new String[] { modifiedSourceLineBuilder.toString(), markerLineBuilder.toString(), differenceLineBuilder.toString() }; }
From source file:org.ut.biolab.medsavant.client.view.app.builtin.task.ServerJobMonitorTaskWorker.java
private List<GeneralLog> getSortedChildren(List<MedSavantServerJobProgress> mjps, int level) { List<GeneralLog> output = new LinkedList<GeneralLog>(); Map<Integer, List<MedSavantServerJobProgress>> m = new TreeMap<Integer, List<MedSavantServerJobProgress>>(); for (MedSavantServerJobProgress p : mjps) { List<MedSavantServerJobProgress> l = m.get(p.getStatus().ordinal()); if (l == null) { l = new LinkedList<MedSavantServerJobProgress>(); }//w w w . ja v a2s .c o m l.add(p); m.put(p.getStatus().ordinal(), l); } final String tabStr = StringUtils.repeat(" ", level); int jid = 0; for (List<MedSavantServerJobProgress> mjpList : m.values()) { for (MedSavantServerJobProgress mjp : mjpList) { String msg = mjp.getMessage(); if (msg == null) { msg = ""; } else { msg = " - " + msg; } output.add(new GeneralLog(null, tabStr + "(" + mjp.getStatus() + ") " + jid + ". " + mjp.getJobName() + msg, null)); if (mjp.childJobProgresses != null && !mjp.childJobProgresses.isEmpty()) { output.addAll(getSortedChildren(mjp.childJobProgresses, level + 1)); } jid++; } } return output; }