/** * Formats a message. If the message begins with "@", the remainder is assumed to be a label * identifier that is resolved. * * @param msg Message to format or, if starts with "@", a label reference. * @param args Optional replaceable parameters. * @return The formatted message. */ public static String formatMessage(String msg, Object... args) { return formatMessage(msg, null, args); }
private String formatResult(String id, Object... args) { return StrUtil.getLabel("org.fujion.console.cache." + id + ".result", args); }
/** * Converts a string containing a delimited list of elements to a string list. * * @param text The string containing the delimited elements. * @param delimiter The delimiter that separates the elements in the input string. * @return A list containing the parsed elements. */ public static List<String> toList(String text, String delimiter) { return toList(text, null, delimiter); }
public Version(String value) { if (value != null && !value.isEmpty()) { String[] pcs = StrUtil.split(value, ".", 4); for (int i = 0; i < 4; i++) { seq[i] = StrUtil.extractInt(pcs[i]); } } }
/** * Control parameters for the dialog. * * @param message Text message * @param title Title of dialog * @param styles Style classes for icon, message text, and panel (pipe-delimited) * @param responses Responses for the dialog. * @param saveResponseId Uniquely identifies this response for purposes of saving and retrieving * the last response. If not specified (null or empty), the response is not saved. * Otherwise, if a saved response exists, it is returned without displaying the * dialog. If a saved response does not exist, the user is prompted in the normal * manner with the addition of a check box on the dialog asking if the response is to * be saved. If this box is checked, the user's response is then saved as a user * preference. * @param callback Callback to receive response. */ public DialogControl(String message, String title, String styles, List<DialogResponse<T>> responses, String saveResponseId, IPromptCallback<T> callback) { this.message = StrUtil.formatMessage(message); this.title = StrUtil.formatMessage(title); this.saveResponseId = saveResponseId; this.callback = callback; this.responses = responses; String[] sclass = styles == null ? null : StrUtil.split(styles, "|", 3, false); iconClass = sclass == null ? null : sclass[0]; textClass = sclass == null ? null : sclass[1]; panelClass = sclass == null || sclass[2] == null ? "panel-primary" : sclass[2]; }
String original = "1,2,3,4,5"; List<String> strList = StrUtil.toList(original, ","); assertEquals(5, strList.size()); String str = StrUtil.fromList(strList, ","); assertEquals(original, str); strList = StrUtil.toList(",,3,4,5,", ","); assertEquals(5, strList.size()); str = StrUtil.fromList(intList, ","); assertEquals(original, str); str = StrUtil.fromList(intList, ","); assertEquals("1,2,,4,5", str); str = StrUtil.fromList(intList, ",", null); assertEquals("1,2,4,5", str); str = StrUtil.fromList(intList, ",", "3"); assertEquals(original, str); List<Object> iterList = new ArrayList<>();
/** * Builds a delimited string from a list. * * @param list The list of strings to concatenate. * @param delimiter The delimiter to use to separate elements. * @return A string contains the list of elements separated by the specified delimiter. */ public static String fromList(Iterable<?> list, String delimiter) { return fromList(list, delimiter, ""); }
/** * Splits a string using the specified delimiter. * * @param text The string to split. * @param delimiter The delimiter for the split operation. * @return A string array containing the split values. The returned array is guaranteed not to * contain null values by replacing every occurrence of a null value with an empty * string. */ public static String[] split(String text, String delimiter) { return split(text, delimiter, 0); }
/** * Returns the first piece of text as delimited by delimiter. * * @param text Text to piece. * @param delimiter Delimiter for piecing. * @return First piece of text. */ public static String piece(String text, String delimiter) { return piece(text, delimiter, 1); }
/** * Sets the default flag. * * @param value Boolean string expression. */ private void setDefault(String value) { this.dflt = StrUtil.toBoolean(value); }
/** * Builds a newline-delimited string from a list. * * @param list The list of strings to concatenate. * @return A string contains the list of elements separated by the newline character. */ public static String fromList(Iterable<?> list) { return fromList(list, "\n"); }
/** * Splits a string using the specified delimiter. * * @param text The string to split. * @param delimiter The delimiter for the split operation. * @param count Specifies a minimum number of elements to be returned. If the result of the * split operation results in fewer elements, the returned array is expanded to * contain the minimum number of elements. * @return A string array containing the split values. The returned array is guaranteed not to * contain null values by replacing every occurrence of a null value with an empty * string. */ public static String[] split(String text, String delimiter, int count) { return split(text, delimiter, count, true); }
/** * Returns the specified piece of text as delimited by delimiter. * * @param text Text to piece. * @param delimiter Delimiter for piecing. * @param position Position of piece to extract. * @return The requested text piece. */ public static String piece(String text, String delimiter, int position) { return piece(text, delimiter, position, position); }
/** * Returns true if the specified feature is enabled. * * @param featureName Name of the feature. This maps to the property that is prefixed by the * current property prefix. * @param deflt The default value if the feature state is not found. * @return True if the feature is enabled. */ public boolean isEnabled(String featureName, boolean deflt) { String value = getValue(featureName, ""); return value.isEmpty() ? deflt : StrUtil.toBoolean(value); }
public SearchException(String label, Throwable cause) { super(StrUtil.formatMessage(label), cause); }
/** * Returns a formatted message given a label identifier. * * @param id A label identifier. * @param args Optional replaceable parameters. * @return The formatted label. */ public static String getLabel(String id, Object... args) { return getLabel(id, null, args); }
/** * Converts a string containing a '\n'-delimited list of elements to a string list. * * @param text The string containing the '\n'-delimited elements. * @return A list containing the parsed elements. */ public static List<String> toList(String text) { return toList(text, null, LINE_TERMINATOR); }
/** * Returns css gradient specifier. * * @param colors List of colors for gradient. * @return The gradient specifier. */ private String getGradValue(String... colors) { return "linear-gradient(to right," + StrUtil.fromList(Arrays.asList(colors), ", ", "none") + ")"; }
public static String formatName(String name) { if (StringUtils.isEmpty(name)) { return ""; } String pcs[] = StrUtil.split(WordUtils.capitalizeFully(name, WORD_DELIMITERS), ","); StringBuilder sb = new StringBuilder(name.length() + 5); for (String pc : pcs) { if (sb.length() > 0) { sb.append(", "); } sb.append(pc.trim()); } return sb.toString(); }
/** * Strip version to only major and minor portions. * * @param version The version. * @return The version stripped of all but major and minor portions. */ public static String formatVersion(String version) { if (!StringUtils.isEmpty(version)) { version = new Version(version).toString(VersionPart.MINOR); version = StrUtil.piece(version, ".", 1, 2); } return version; }