Search in sources :

Example 41 with StringJoiner

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();
}
Also used : Scanner(java.util.Scanner) StringJoiner(java.util.StringJoiner)

Example 42 with StringJoiner

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();
}
Also used : Scanner(java.util.Scanner) StringJoiner(java.util.StringJoiner)

Example 43 with StringJoiner

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();
}
Also used : Scanner(java.util.Scanner) StringJoiner(java.util.StringJoiner)

Example 44 with StringJoiner

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();
}
Also used : StringJoiner(java.util.StringJoiner)

Example 45 with StringJoiner

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();
}
Also used : StringJoiner(java.util.StringJoiner)

Aggregations

StringJoiner (java.util.StringJoiner)98 ArrayList (java.util.ArrayList)22 List (java.util.List)11 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 ClassName (com.squareup.javapoet.ClassName)3 FieldSpec (com.squareup.javapoet.FieldSpec)3 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)3 TypeName (com.squareup.javapoet.TypeName)3 TypeSpec (com.squareup.javapoet.TypeSpec)3 Expression (com.sri.ai.expresso.api.Expression)3 Attribute (io.requery.meta.Attribute)3 Field (java.lang.reflect.Field)3 Scanner (java.util.Scanner)3 RaptorColumnHandle (com.facebook.presto.raptor.RaptorColumnHandle)2 Range (com.facebook.presto.spi.predicate.Range)2 MaterializedResult (com.facebook.presto.testing.MaterializedResult)2