Example usage for java.lang String chars

List of usage examples for java.lang String chars

Introduction

In this page you can find the example usage for java.lang String chars.

Prototype

@Override
public IntStream chars() 

Source Link

Document

Returns a stream of int zero-extending the char values from this sequence.

Usage

From source file:Main.java

public static void main(String[] args) {

    String s = "R2D2C3P0";
    int result = s.chars().filter(Character::isDigit).map(ch -> Character.valueOf((char) ch)).sum();

    System.out.println(result);//from  w w w.  ja v a 2  s .  com
}

From source file:Main.java

public static void main(String[] args) {
    String str = "5 123,123,qwe,1,123, 25";
    str.chars().filter(n -> !Character.isDigit((char) n) && !Character.isWhitespace((char) n))
            .forEach(n -> System.out.print((char) n));

}

From source file:net.pj.games.eulerproject.elements.StringPermutator.java

private static int getIndexOfMax(String s) {

    final MutableInt maxIndex = new MutableInt(-1);
    s.chars().max().ifPresent(m -> maxIndex.setValue(s.indexOf(m)));
    return maxIndex.intValue();
}

From source file:com.dgtlrepublic.anitomyj.StringHelper.java

/** Returns whether or not the {@code string} is a hex string. */
public static boolean isHexadecimalString(String string) {
    return StringUtils.isNotEmpty(string) && string.chars().allMatch(value -> isHexadecimalChar((char) value));
}

From source file:com.hengyi.japp.tools.PYUtil.java

public static List<String> getFirstSpell(String cs) {
    if (isBlank(cs)) {
        return null;
    }/*from   w  w w .  ja  v a2 s .c o  m*/
    List<String> result = null;
    List<Set<Character>> cs_fpys = cs.chars().mapToObj(i -> toHanyuPinyinStringArray((char) i))
            .map(a -> Arrays.stream(a).map(s -> s.charAt(0)).collect(Collectors.toSet()))
            .collect(Collectors.toList());
    for (Set<Character> fpys : cs_fpys) {
        if (result == null) {
            result = fpys.stream().map(String::valueOf).collect(Collectors.toList());
        } else {
            Stream<String> tmps = result.stream().flatMap(s -> fpys.stream().map(fpy -> s + fpy));
            result = tmps.collect(Collectors.toList());
        }
    }
    return result;
}

From source file:net.pj.games.eulerproject.elements.StringPermutator.java

public static String incrementWithNextAvailableValue(String s) {

    char[] nextValue = new char[s.length()];
    final char actual = s.charAt(0);
    nextValue[0] = (char) s.substring(1).chars().filter(c -> c > actual).min().orElse(-1);
    final int[] orderedSuffix = s.chars().filter(c -> c != nextValue[0]).sorted().toArray();
    for (int i = 0; i < orderedSuffix.length; i++) {
        nextValue[i + 1] = (char) orderedSuffix[i];
    }/*from w ww .  ja v  a2s . co m*/
    //log.debug("incremented value of {} is {}", s, nextValue);
    return new String(nextValue);
}

From source file:io.syndesis.jsondb.impl.JsonRecordSupport.java

private static String validateKey(String key) {
    if (key.chars().anyMatch(x -> {
        switch (x) {
        case '.':
        case '%':
        case '$':
        case '#':
        case '[':
        case ']':
        case '/':
        case 127:
            return true;
        default://from  w  ww.j a v a 2  s. c  o m
            if (0 < x && x < 32) {
                return true;
            }
            return false;
        }
    })) {
        throw new JsonDBException(
                "Invalid key. Cannot contain ., %, $, #, [, ], /, or ASCII control characters 0-31 or 127. Key: "
                        + key);
    }
    if (key.length() > 768) {
        throw new JsonDBException("Invalid key. Key cannot ben longer than 768 characters. Key: " + key);
    }
    return key;
}

From source file:edu.rit.flick.genetics.FastFileInflator.java

protected void writeTail() throws IOException {
    if (tailfile.hasNext()) {
        final String tail = tailfile.next();
        tail.chars().mapToObj(base -> (byte) base).forEach(base -> {
            writeNucleotide(base);//from w  ww.  j  a v a2  s  .co  m
        });
    } else
        processSequence();
    if (fastOut.available() > 0)
        writeNewline();
}

From source file:org.apache.james.server.core.MailImpl.java

private static void detectPossibleLoop(String currentName, int loopThreshold, char separator)
        throws MessagingException {
    long occurrences = currentName.chars().filter(c -> Chars.saturatedCast(c) == separator).count();

    // It looks like a configuration loop. It's better to stop.
    if (occurrences > loopThreshold) {
        throw new MessagingException(
                "Unable to create a new message name: too long. Possible loop in config.xml.");
    }/*from w  w  w .  j  ava2s  .  c  o m*/
}

From source file:org.beryx.viewreka.fxapp.Viewreka.java

private static boolean isProbablyBinary(File file) {
    try {/*from  ww w.jav  a  2 s. c  om*/
        List<String> lines = Files.readAllLines(Paths.get(file.getAbsolutePath()));
        if (!lines.isEmpty()) {
            long binCharCount = 0;
            long binLineCount = 0;
            for (String line : lines) {
                if (CONTROL_PATTERN.matcher(line).matches())
                    return true;
                if (line.chars().filter(ch -> !Character.isDefined(ch)).findFirst().isPresent())
                    return true;
                long count = line.chars().filter(ch -> (ch > 127)).count();
                if (count > 0) {
                    binCharCount += count;
                    binLineCount++;
                }
            }
            if (binCharCount == 0 || binLineCount == 0)
                return false;
            long length = file.length();
            if (length < 100) {
                if (binCharCount > 10)
                    return true;
            } else {
                if (100.0 * binCharCount / length > 10)
                    return true;
                if (100.0 * binLineCount / lines.size() > 50)
                    return true;
            }
        }
    } catch (Throwable t) {
        log.error("An error occurred while analyzing the file", t);
        return true;
    }
    return false;
}