本文整理汇总了Java中org.apache.commons.text.WordUtils类的典型用法代码示例。如果您正苦于以下问题:Java WordUtils类的具体用法?Java WordUtils怎么用?Java WordUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WordUtils类属于org.apache.commons.text包,在下文中一共展示了WordUtils类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LineBreaker
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
public LineBreaker(String text, int wrapLength)
{
String wrappedText = WordUtils.wrap(text, wrapLength);
String[] lines = wrappedText.split(System.lineSeparator());
for(String line : lines)
{
Label lineLabel = new Label(line, Settings.DEFAULT_SKIN);
this.add(lineLabel);
this.row();
}
this.pack();
}
示例2: getDcTitle
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
/**
* Perform renderer-specific name reformatting:<p>
* Truncating and wrapping see {@code TextWrap}<br>
* Character substitution see {@code CharMap}
*
* @param name Original name
* @param suffix Additional media information
* @param dlna The actual DLNA resource
* @return Reformatted name
*/
public String getDcTitle(String name, String suffix, DLNAResource dlna) {
// Wrap + truncate
int len = 0;
if (lineWidth > 0 && (name.length() + suffix.length()) > lineWidth) {
int suffix_len = dots.length() + suffix.length();
if (lineHeight == 1) {
len = lineWidth - suffix_len;
} else {
// Wrap
int i = dlna.isFolder() ? 0 : indent;
String newline = "\n" + (dlna.isFolder() ? "" : inset);
name = name.substring(0, i + (i < name.length() && Character.isWhitespace(name.charAt(i)) ? 1 : 0))
+ WordUtils.wrap(name.substring(i) + suffix, lineWidth - i, newline, true);
len = lineWidth * lineHeight;
if (len != 0 && name.length() > len) {
len = name.substring(0, name.length() - lineWidth).lastIndexOf(newline) + newline.length();
name = name.substring(0, len) + name.substring(len, len + lineWidth).replace(newline, " ");
len += (lineWidth - suffix_len - i);
} else {
len = -1; // done
}
}
if (len > 0) {
// Truncate
name = name.substring(0, len).trim() + dots;
}
}
if (len > -1) {
name += suffix;
}
// Substitute
for (String s : charMap.keySet()) {
String repl = charMap.get(s).replaceAll("###e", "");
name = name.replaceAll(s, repl);
}
return name;
}
示例3: replaceFnString
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
private String replaceFnString(
Class<? extends PTransform> transformClass,
String transformString,
String fnFieldName)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException,
NoSuchFieldException {
Object fn =
transformClass.getMethod("get" + WordUtils.capitalize(fnFieldName)).invoke(transform);
Class<?> fnClass = fn.getClass();
String doFnName;
Class<?> enclosingClass = fnClass.getEnclosingClass();
if (enclosingClass != null && enclosingClass.equals(MapElements.class)) {
Field parent = fnClass.getDeclaredField("this$0");
parent.setAccessible(true);
Field fnField = enclosingClass.getDeclaredField(fnFieldName);
fnField.setAccessible(true);
doFnName = fnField.get(parent.get(fn)).getClass().getName();
} else {
doFnName = fnClass.getName();
}
transformString = transformString.replace("<" + fnFieldName + ">", doFnName);
return transformString;
}
示例4: normalize
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
/**
* Normalize the entry : capitalize and trimming.
*/
private void normalize(final UserOrgEditionVo importEntry) {
// Normalize the identifiers
importEntry.setCompany(Normalizer.normalize(importEntry.getCompany()));
importEntry.setId(StringUtils.trimToNull(Normalizer.normalize(importEntry.getId())));
importEntry.setGroups(new ArrayList<>(Normalizer.normalize(importEntry.getGroups())));
// Fix the names of user
importEntry.setDepartment(StringUtils.trimToNull(importEntry.getDepartment()));
importEntry.setLocalId(StringUtils.trimToNull(importEntry.getLocalId()));
importEntry.setLastName(WordUtils.capitalizeFully(StringUtils.trimToNull(importEntry.getLastName())));
importEntry.setFirstName(WordUtils.capitalizeFully(StringUtils.trimToNull(importEntry.getFirstName())));
}
示例5: logSystemInfo
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
/**
* Log system properties identifying Java, the OS and encoding and log
* warnings where appropriate.
*/
private static void logSystemInfo() {
long jvmMemory = Runtime.getRuntime().maxMemory();
LOGGER.info(
"Java: {} {} ({}-bit) by {}",
System.getProperty("java.vm.name"),
System.getProperty("java.version"),
System.getProperty("sun.arch.data.model"),
System.getProperty("java.vendor")
);
LOGGER.info(
"OS: {} {}-bit {}",
System.getProperty("os.name"),
SystemInformation.getOSBitness(),
System.getProperty("os.version")
);
LOGGER.info(
"Maximum JVM Memory: {}",
jvmMemory == Long.MAX_VALUE ? "Unlimited" : StringUtil.formatBytes(jvmMemory, true)
);
LOGGER.info("Language: {}", WordUtils.capitalize(PMS.getLocale().getDisplayName(Locale.ENGLISH)));
LOGGER.info("Encoding: {}", System.getProperty("file.encoding"));
LOGGER.info("");
if (Platform.isMac() && !IOKitUtils.isMacOsVersionEqualOrGreater(6, 0)) {
// The binaries shipped with the Mac OS X version of DMS are being
// compiled against specific OS versions, making them incompatible
// with older versions. Warn the user about this when necessary.
LOGGER.warn("-----------------------------------------------------------------");
LOGGER.warn("WARNING!");
LOGGER.warn("DMS ships with external binaries compiled for Mac OS X 10.6 or");
LOGGER.warn("higher. You are running an older version of Mac OS X which means");
LOGGER.warn("that these binaries used for example for transcoding may not work!");
LOGGER.warn("To solve this, replace the binaries found int the \"osx\"");
LOGGER.warn("subfolder with versions compiled for your version of OS X.");
LOGGER.warn("-----------------------------------------------------------------");
LOGGER.warn("");
}
}
示例6: buildPanel
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
public JPanel buildPanel() {
FormLayout layout = new FormLayout("left:pref, 400:grow");
PanelBuilder builder = new PanelBuilder(layout);
builder.border(new EmptyBorder(10, 10, 10, 10));
int y = 0;
builder.appendRow(rspec);
editBar = new JPanel();
editBar.setLayout(new BoxLayout(editBar, BoxLayout.X_AXIS));
builder.add(editBar, cc.xyw(1, ++y, 2));
if (/*renderer.loaded &&*/ !renderer.isFileless()) {
buildEditBar(false);
}
builder.appendRow(rspec);
builder.addLabel(" ", cc.xy(1, ++y));
y = addMap(renderer.getDetails(), builder, y);
if (renderer.isUpnp()) {
y = addStrings("Services", WordUtils.wrap(StringUtils.join(renderer.getUpnpServices(), ", "), 60).split("\n"),
builder, y);
}
if (renderer.isControllable()) {
builder.appendRow(rspec);
builder.addLabel(" ", cc.xy(1, ++y));
builder.appendRow(rspec);
builder.addSeparator(Messages.getString("RendererPanel.1"), cc.xyw(1, ++y, 2));
builder.appendRow(rspec);
builder.add(new PlayerControlPanel(renderer.getPlayer()), cc.xyw(1, ++y, 2));
}
return builder.getPanel();
}
示例7: removeAndSaveEditionToBeAddedLater
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
/**
* Remove and save edition information to be added later
*/
private static FormattedNameAndEdition removeAndSaveEditionToBeAddedLater(String formattedName) {
String edition = null;
Matcher m = COMMON_FILE_EDITIONS_PATTERN.matcher(formattedName);
if (m.find()) {
edition = m.group().replaceAll("\\.", " ");
edition = "(" + WordUtils.capitalizeFully(edition) + ")";
formattedName = formattedName.replaceAll(" - " + COMMON_FILE_EDITIONS, "");
formattedName = formattedName.replaceAll(COMMON_FILE_EDITIONS, "");
}
return new FormattedNameAndEdition(formattedName, edition);
}
示例8: onCreateBubbleText
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
@Override
public String onCreateBubbleText(int position) {
T item = getItem(position);
if (item instanceof Faculty) {
Faculty faculty = (Faculty) item;
if (useLongDesc)
return WordUtils.capitalizeFully(faculty.getLongDesc());
else
return faculty.getDirectoryKey().name;
} else
return "";
}
示例9: underscoredToCamelCase
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
/**
* Convert a string which is separated with underscores to camel case. Example: "UNDERSCORED_STRING_EXAMPLE" =>
* "underscoredStringExample"
*
* @param underscoredString
* the underscore-separated string
* @return the camel-cased string
*/
public static String underscoredToCamelCase(String underscoredString) {
if (underscoredString == null || underscoredString.length() == 0) {
return "";
} else {
String ret = WordUtils.capitalizeFully(underscoredString, new char[] { '_' }).replaceAll("_", "");
ret = ret.substring(0, 1).toLowerCase(Locale.ENGLISH) + ret.substring(1);
return ret;
}
}
示例10: resolveOnce
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
@Override
protected void resolveOnce() {
double titles[] = new double[100];
String cmd[] = new String[]{
configuration.getMPlayerPath(),
"-identify",
"-endpos",
"0",
"-ao",
"null",
"-vc",
"null",
"-vo",
"null",
"-dvd-device",
ProcessUtil.getShortFileNameIfWideChars(file.getAbsolutePath()),
"dvd://"
};
OutputParams params = new OutputParams(configuration);
params.maxBufferSize = 1;
params.log = true;
final ProcessWrapperImpl pw = new ProcessWrapperImpl(cmd, params, true, false);
Runnable r = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
pw.stopProcess();
}
};
Thread failsafe = new Thread(r, "DVDISO Failsafe");
failsafe.start();
pw.runInSameThread();
List<String> lines = pw.getOtherResults();
if (lines != null) {
for (String line : lines) {
if (line.startsWith("ID_DVD_TITLE_") && line.contains("_LENGTH")) {
int rank = Integer.parseInt(line.substring(13, line.indexOf("_LENGT")));
double duration = Double.parseDouble(line.substring(line.lastIndexOf("LENGTH=") + 7));
titles[rank] = duration;
} else if (line.startsWith("ID_DVD_VOLUME_ID")) {
String volumeId = line.substring(line.lastIndexOf("_ID=") + 4).trim();
if (configuration.isPrettifyFilenames()) {
volumeId = volumeId.replaceAll("_", " ");
if (isNotBlank(volumeId) && volumeId.equals(volumeId.toUpperCase(PMS.getLocale()))) {
volumeId = WordUtils.capitalize(volumeId.toLowerCase(PMS.getLocale()));
}
}
this.volumeId = volumeId;
}
}
}
double oldduration = -1;
for (int i = 1; i < 99; i++) {
/**
* Don't take into account titles less than 10 seconds
* Also, workaround for the MPlayer bug which reports a unique title with the same length several times
* The "maybe wrong" title is taken into account only if its duration is less than 1 hour.
* Common-sense is a single video track on a DVD is usually greater than 1h
*/
if (titles[i] > 10 && (titles[i] != oldduration || oldduration < 3600)) {
DVDISOTitle dvd = new DVDISOTitle(file, volumeId, i);
addChild(dvd);
oldduration = titles[i];
}
}
if (childrenNumber() > 0) {
PMS.get().storeFileInCache(file, Format.ISO);
}
}
示例11: toSource
import org.apache.commons.text.WordUtils; //导入依赖的package包/类
public static String toSource(final J48 tree, final String prefix) throws Exception {
PRINT_ID = 0;
/** The decision tree */
final ClassifierTree m_root = (ClassifierTree) getPrivateFieldValue(tree.getClass(), tree, "m_root");
/** Local model at node. */
// final ClassifierSplitModel m_localModel = (ClassifierSplitModel) getPrivateFieldValue(m_root.getClass(), m_root, "m_localModel");
final StringBuilder[] source = toSourceClassifierTree(m_root, prefix);
final StringBuilder sb = new StringBuilder();
sb.append(" function getParamFor" + WordUtils.capitalize(prefix) + "(){\n");
sb.append(" param = [").append(RetailSalePrediction.ATTR.values().length - 1).append("];\n");
for (RetailSalePrediction.ATTR attr : RetailSalePrediction.ATTR.values()) {
//для последнего делаем вычисления, поэтому его в параметрах не должно быть
if (attr.ordinal() != RetailSalePrediction.ATTR.values().length - 1) {
sb.append(" param[");
sb.append(attr.ordinal());
sb.append("] = ");
sb.append(attr.getFunctionName());
sb.append("();\n");
}
}
sb.append(" return param;\n");
sb.append(" }\n");
sb.append(" function getValueFor" + WordUtils.capitalize(prefix) + "(idx){\n");
sb.append(" values = [];\n");
sb.append(" values[0] = 'менее 50';\n");
sb.append(" values[1] = 'около 50';\n");
int idx = 2;
for (final String number : RetailSalePrediction.numbers) {
for (final String word : RetailSalePrediction.words) {
sb.append(" values[").append(idx).append("] = '").append(word).append(" ").append(number).append("';\n");
++idx;
}
}
sb.append(" return values[idx];\n");
sb.append(" }\n");
return sb.toString()
+ " function " + prefix + "() {\n"
+ " i = getParamFor" + WordUtils.capitalize(prefix) + "();\n"
+ " p = " + prefix + "Classify(i);\n"
+ " return getValueFor" + WordUtils.capitalize(prefix) + "(p);\n"
+ " }\n"
+ " function " + prefix + "Classify(i) {\n"
+ " p = NaN;\n"
+ source[0] // Assignment code
+ " return p;\n"
+ " }\n"
+ source[1] // Support code
;
}