com.arosbio.commons.StringUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of confai Show documentation
Show all versions of confai Show documentation
Conformal AI package, including all data IO, transformations, machine learning models and predictor classes. Without inclusion of chemistry-dependent code.
/*
* Copyright (C) Aros Bio AB.
*
* CPSign is an Open Source Software that is dual licensed to allow you to choose a license that best suits your requirements:
*
* 1) GPLv3 (GNU General Public License Version 3) with Additional Terms, including an attribution clause as well as a limitation to use the software for commercial purposes.
*
* 2) CPSign Proprietary License that allows you to use CPSign for commercial activities, such as in a revenue-generating operation or environment, or integrate CPSign in your proprietary software without worrying about disclosing the source code of your proprietary software, which is required if you choose to use the software under GPLv3 license. See arosbio.com/cpsign/commercial-license for details.
*/
package com.arosbio.commons;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.text.CaseUtils;
import org.apache.commons.text.WordUtils;
public class StringUtils {
private static final String NEW_LINE_SEP = System.lineSeparator();
private static final String NL_REGEX = "\\R|%n";
public static String wrap(String txt, int width) {
return wrap(txt,width,null);
}
public static String wrap(String txt, int totalWidth, String newLineStart) {
return wrap(txt, totalWidth, newLineStart, true);
}
public static String wrap(final String txt, int totalWidth, final String newLineStart, boolean applyToFirst) {
return wrap(txt, totalWidth, newLineStart, applyToFirst ? newLineStart : "");
}
public static String wrap(final String txt, int totalWidth, final String newLineStart, final String beginFirstLine) {
// Handle the input text
if (txt == null || txt.isEmpty())
return "";
if (totalWidth < 10)
return txt;
// Handle the new-line-text
int indentW = 0;
String indent = null, indentToWordUtils = ' ' +NEW_LINE_SEP;
boolean containsNL = false;
if (newLineStart == null) {
indent = "";
} else {
indent = newLineStart; //.replaceAll("\t", TAB);
String[] splits = indent.split(NL_REGEX);
if (splits.length>=2) {
// Only the width of the last thing actually matters
indentW = splits[splits.length-1].length();
containsNL = true;
indentToWordUtils = ' ' +newLineStart;
} else {
indentW = indent.length();
indentToWordUtils = ' '+NEW_LINE_SEP + indent;
}
}
String[] lines = txt.split(NL_REGEX);
StringBuilder sb = new StringBuilder();
// Special-treat first index in the array
if (beginFirstLine != null && !beginFirstLine.isEmpty()) {
sb.append(beginFirstLine);
sb.append(WordUtils.wrap(lines[0], totalWidth-Math.max(indentW, beginFirstLine.length()), indentToWordUtils,false));
} else {
sb.append(WordUtils.wrap(lines[0], totalWidth-indentW, indentToWordUtils,false));
}
for (int i=1; i Logistic Regression)
String[] camelCaseQueries = withBlanks.split("(?1)
return txt+"s";
return txt;
}
public static String joinCollection(String delimiter, Collection extends Object> args) {
List