List of usage examples for org.apache.commons.lang3 StringUtils replaceChars
public static String replaceChars(final String str, final String searchChars, String replaceChars)
Replaces multiple characters in a String in one go.
From source file:br.com.fidias.chance4j.text.ParagraphTest.java
@Test public void randomParagraphFiveSentences() throws ChanceException { final int numSentences = 5; for (int i = 0; i < 1000; i++) { paragraph = chance.paragraph(numSentences); String replaceChars = StringUtils.replaceChars(paragraph, PUNCTUATION, replaceSymbols); int countMatches = StringUtils.countMatches(replaceChars, '_'); assertTrue("random paragraph 5 sentences", countMatches == 5); }//from w w w . j ava 2 s . com }
From source file:hu.bme.mit.sette.common.util.JavaFileUtils.java
/** * Converts a filename to a Java class name by transliterating the file * separator characters to the package separator character. * * @param filename//from www.j a v a2 s .c o m * The filename (e.g. hu/bme/mit/sette/MyClass.java) * @return The class name (e.g. hu.bme.mit.sette.MyClass) */ public static String filenameToClassName(final String filename) { return StringUtils.replaceChars(FilenameUtils.removeExtension(filename), File.separatorChar, JavaFileUtils.PACKAGE_SEPARATOR); }
From source file:com.haulmont.cuba.web.widgets.CubaDateField.java
@Override public void setDateFormat(String dateFormat) { super.setDateFormat(dateFormat); getState().dateMask = StringUtils.replaceChars(dateFormat, "dDMYy", "#####"); markAsDirty();// ww w . j a va 2 s. c o m }
From source file:br.com.fidias.chance4j.text.ParagraphTest.java
@Test public void randomParagraph() throws ChanceException { for (int i = 0; i < 1000; i++) { paragraph = chance.paragraph();/*from www .j a va 2 s. com*/ String replaceChars = StringUtils.replaceChars(paragraph, PUNCTUATION, replaceSymbols); int countMatches = StringUtils.countMatches(replaceChars, '_'); assertTrue("random paragraph 5 sentences", countMatches >= MIN_SENTENCES_FOR_PARAGRAPH && countMatches <= MAX_SENTENCES_FOR_PARAGRAPH); } }
From source file:com.epam.dlab.core.parser.ConditionEvaluate.java
/** Instantiate the engine to evaluate condition. * @param columnNames the list of column names. * @param condition condition for filtering data. * @throws InitializationException/*from w w w. ja va 2 s. c o m*/ */ public ConditionEvaluate(List<String> columnNames, String condition) throws InitializationException { //Replace : to . in column names List<String> colNames = new ArrayList<>(columnNames.size()); for (int i = 0; i < columnNames.size(); i++) { String name = columnNames.get(i); if (name.indexOf(':') > -1 && condition.indexOf(name) > -1) { String newName = StringUtils.replaceChars(name, ':', '.'); colNames.add(newName); condition = StringUtils.replace(condition, name, newName); } else { colNames.add(name); } } try { JexlEngine engine = new JexlBuilder().strict(true).silent(false).debug(true).create(); expression = (Script) engine.createExpression(condition); jexlContext = new MapContext(); } catch (Exception e) { throw new InitializationException( "Cannot initialize JEXL engine for condition: " + condition + ". " + e.getLocalizedMessage(), e); } // Create mapping of columns for evaluations. List<String> names = new ArrayList<>(); List<Integer> indexes = new ArrayList<>(); for (List<String> variableList : expression.getVariables()) { String columnName = StringUtils.join(variableList, '.'); int index = getColumnIndex(colNames, columnName); if (index == -1) { throw new InitializationException("Unknow source column name \"" + columnName + "\" in condition: " + expression.getSourceText() + ". Known column names: " + StringUtils.join(columnNames, ", ") + "."); } names.add(columnName); indexes.add(index); } this.columnNames = new String[names.size()]; this.columnIndexes = new int[indexes.size()]; for (int i = 0; i < indexes.size(); i++) { this.columnNames[i] = names.get(i); this.columnIndexes[i] = indexes.get(i); } }
From source file:com.haulmont.cuba.web.gui.components.table.AbbreviatedColumnGenerator.java
@Override public Object generateCell(com.vaadin.v7.ui.Table source, Object itemId, Object columnId) { Property property = source.getItem(itemId).getItemProperty(columnId); Object value = property.getValue(); if (value == null) { return null; }/*from ww w . ja va 2 s . c o m*/ String stringValue = value.toString(); if (columnId instanceof MetaPropertyPath) { MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty(); if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { stringValue = dynamicAttributesTools.getDynamicAttributeValueAsString(metaProperty, value); } } String cellValue = stringValue; boolean isMultiLineCell = StringUtils.contains(stringValue, "\n"); if (isMultiLineCell) { cellValue = StringUtils.replaceChars(cellValue, '\n', ' '); } int maxTextLength = column.getMaxTextLength(); if (stringValue.length() > maxTextLength + MAX_TEXT_LENGTH_GAP || isMultiLineCell) { return StringUtils.abbreviate(cellValue, maxTextLength); } else { return cellValue; } }
From source file:net.ontopia.xml.ContentWriter.java
protected String escape(String attrval) { return StringUtils.replace( StringUtils.replace(StringUtils.replaceChars(attrval, "&", "&"), "<", "<"), "\"", """); }
From source file:com.threewks.thundr.mailgun.MailgunImplIT.java
@Ignore @Test/*from w ww . j ava 2 s . c o m*/ public void shouldSendAnEmail() { // @formatter:off MailBuilder mailBuilder = mailgun.mail().to("test.3wks@gmail.com").cc("test.3wks@gmail.com") .bcc("test.3wks@gmail.com").from("test@thundr-mailgun-test.mailgun.org") .replyTo("test@thundr-mailgun-test.mailgun.org").subject("Test Mailgun") .body(new StringView("<html><body><h1>Yeah!</h1></body></html>")); // @formatter:on MessageSend result = mailgun.sendMailgun(mailBuilder); assertThat(result.id, is(not(nullValue()))); String expectedId = StringUtils.replaceChars(result.id, "<>", ""); String actualId = null; synchronized (this) { try { this.wait(5000); } catch (InterruptedException e) { } } Log log = mailgun.log(0, 20); for (LogItem item : log.items) { if (item.message_id.equals(expectedId)) { actualId = item.message_id; } } assertThat(actualId, is(expectedId)); }
From source file:com.haulmont.cuba.web.widgets.CubaDateField.java
@Override protected void updateInternal(String newDateString, Map<String, Integer> resolutions) { // CAUTION: copied from AbstractDateField Set<String> resolutionNames = getResolutions().map(Enum::name).collect(Collectors.toSet()); resolutionNames.retainAll(resolutions.keySet()); if (!isReadOnly() && (!resolutionNames.isEmpty() || newDateString != null)) { // Old and new dates final LocalDate oldDate = getValue(); LocalDate newDate;//w w w . j a v a2s .com String mask = StringUtils.replaceChars(getState(false).dateMask, "#U", "__"); if ("".equals(newDateString) || mask.equals(newDateString)) { newDate = null; } else { newDate = reconstructDateFromFields(resolutions, oldDate); } boolean hasChanges = !Objects.equals(dateString, newDateString) || !Objects.equals(oldDate, newDate); if (hasChanges) { dateString = newDateString; currentParseErrorMessage = null; if (newDateString == null || newDateString.isEmpty() || mask.equals(newDateString)) { setValue(newDate, true); } else { // invalid date string if (resolutions.isEmpty()) { Result<LocalDate> parsedDate = handleUnparsableDateString(dateString); parsedDate.ifOk(v -> setValue(v, true)); if (parsedDate.isError()) { dateString = null; currentParseErrorMessage = parsedDate.getMessage().orElse("Parsing error"); if (!isDifferentValue(null)) { doSetValue(null); } else { setValue(null, true); } } } else { setValue(newDate, true); } } } } }
From source file:de.jfachwert.post.PLZ.java
private static String normalize(String plz) { return StringUtils.replaceChars(plz, " -", "").toUpperCase(); }