use of java.util.StringJoiner in project jabref by JabRef.
the class BibtexKeyPatternUtil method getTitleWordsWithSpaces.
private static String getTitleWordsWithSpaces(int number, String title) {
StringJoiner stringJoiner = new StringJoiner(" ");
String formattedTitle = formatTitle(title);
int words = 0;
try (Scanner titleScanner = new Scanner(formattedTitle)) {
while (titleScanner.hasNext() && (words < number)) {
String word = titleScanner.next();
stringJoiner.add(word);
words++;
}
}
return stringJoiner.toString();
}
use of java.util.StringJoiner in project jabref by JabRef.
the class BibtexKeyPatternUtil method removeSmallWords.
public static String removeSmallWords(String title) {
StringJoiner stringJoiner = new StringJoiner(" ");
String formattedTitle = formatTitle(title);
try (Scanner titleScanner = new Scanner(formattedTitle)) {
mainl: while (titleScanner.hasNext()) {
String word = titleScanner.next();
for (String smallWord : Word.SMALLER_WORDS) {
if (word.equalsIgnoreCase(smallWord)) {
continue mainl;
}
}
stringJoiner.add(word);
}
}
return stringJoiner.toString();
}
use of java.util.StringJoiner in project jabref by JabRef.
the class BibtexKeyPatternUtil method camelizeSignificantWordsInTitle.
/**
* Capitalises the significant words of the "title" field in the given BibTeX entry
*/
public static String camelizeSignificantWordsInTitle(String title) {
StringJoiner stringJoiner = new StringJoiner(" ");
String formattedTitle = formatTitle(title);
Boolean camelize;
try (Scanner titleScanner = new Scanner(formattedTitle)) {
while (titleScanner.hasNext()) {
String word = titleScanner.next();
camelize = true;
// Camelize the word if it is significant
for (String smallWord : Word.SMALLER_WORDS) {
if (word.equalsIgnoreCase(smallWord)) {
camelize = false;
continue;
}
}
// We want to capitalize significant words and the first word of the title
if (camelize || (stringJoiner.length() == 0)) {
word = word.substring(0, 1).toUpperCase(Locale.ROOT) + word.substring(1);
} else {
word = word.substring(0, 1).toLowerCase(Locale.ROOT) + word.substring(1);
}
stringJoiner.add(word);
}
}
return stringJoiner.toString();
}
use of java.util.StringJoiner in project jdk8u_jdk by JetBrains.
the class String method join.
/**
* Returns a new String composed of copies of the
* {@code CharSequence elements} joined together with a copy of
* the specified {@code delimiter}.
*
* <blockquote>For example,
* <pre>{@code
* String message = String.join("-", "Java", "is", "cool");
* // message returned is: "Java-is-cool"
* }</pre></blockquote>
*
* Note that if an element is null, then {@code "null"} is added.
*
* @param delimiter the delimiter that separates each element
* @param elements the elements to join together.
*
* @return a new {@code String} that is composed of the {@code elements}
* separated by the {@code delimiter}
*
* @throws NullPointerException If {@code delimiter} or {@code elements}
* is {@code null}
*
* @see java.util.StringJoiner
* @since 1.8
*/
public static String join(CharSequence delimiter, CharSequence... elements) {
Objects.requireNonNull(delimiter);
Objects.requireNonNull(elements);
// Number of elements not likely worth Arrays.stream overhead.
StringJoiner joiner = new StringJoiner(delimiter);
for (CharSequence cs : elements) {
joiner.add(cs);
}
return joiner.toString();
}
use of java.util.StringJoiner in project ddf by codice.
the class FilterPlugin method listToString.
private String listToString(List<String> list) {
StringJoiner stringJoiner = new StringJoiner(",");
list.forEach(stringJoiner::add);
return stringJoiner.toString();
}
Aggregations