Example usage for java.lang Character isDigit

List of usage examples for java.lang Character isDigit

Introduction

In this page you can find the example usage for java.lang Character isDigit.

Prototype

public static boolean isDigit(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a digit.

Usage

From source file:com.github.anba.es6draft.util.TestGlobals.java

private static void optionsFromStage(EnumSet<CompatibilityOption> options, String stage) {
    options.addAll(Arrays.stream(CompatibilityOption.Stage.values()).filter(s -> {
        if (stage.length() == 1 && Character.isDigit(stage.charAt(0))) {
            return s.getLevel() == Character.digit(stage.charAt(0), 10);
        } else {//from w  ww  . ja v a 2  s  .  com
            return s.name().equalsIgnoreCase(stage);
        }
    }).findAny().map(CompatibilityOption::Stage).orElseThrow(IllegalArgumentException::new));
}

From source file:net.metanotion.json.StreamingParser.java

private String lexDigits(final Reader in) throws IOException {
    final StringBuilder sb = new StringBuilder();
    while (true) {
        in.mark(MAX_BUFFER);//ww  w  .  j  av  a  2  s  . c o m
        final int c = in.read();
        if (Character.isDigit(c)) {
            sb.append(Character.toChars(c));
        } else {
            in.reset();
            if (sb.length() == 0) {
                throw new ParserException(EXPECTED_DIGIT);
            }
            return sb.toString();
        }
    }
}

From source file:edu.chalmers.dat076.moviefinder.service.TitleParser.java

/**
 * Check if mySb has the potential to contain an episode of some series. It
 * is assumed that vital season information is available in index 0.
 *
 * @param mySb//from  ww w .j av  a  2s . co  m
 * @return true if mySb contains season and episode information
 */
public boolean getEpisodePotential(StringBuilder mySb) {

    if (mySb.length() >= 4 && (mySb.charAt(0) == 'S' || mySb.charAt(0) == 's')) {

        if (Character.isDigit(mySb.charAt(1))) {
            if (Character.isDigit(mySb.charAt(3)) && (mySb.charAt(2) == 'E' || mySb.charAt(2) == 'e')) {
                return true; // SxEx
            } else if (mySb.length() >= 6 && (Character.isDigit(mySb.charAt(2))
                    && Character.isDigit(mySb.charAt(4)) && (mySb.charAt(3) == 'E' || mySb.charAt(3) == 'e'))) {
                return true; //SxxEx
            }
        } else if (mySb.length() > 13 && mySb.substring(0, 6).equalsIgnoreCase("season")) {
            for (int i = 6; i < mySb.length() - 7; i++) {
                if (mySb.substring(i, i + 7).equalsIgnoreCase("episode")) {
                    return true; // season ... episode
                }
            }
        }
    } else if (mySb.length() >= 3 && Character.isDigit(mySb.charAt(0))) {
        if ((Character.isDigit(mySb.charAt(2)) && (mySb.charAt(1) == 'x' || mySb.charAt(1) == 'X'))
                || (mySb.length() >= 4 && Character.isDigit(mySb.charAt(1)) && Character.isDigit(mySb.charAt(3))
                        && (mySb.charAt(2) == 'x' || mySb.charAt(2) == 'X'))) {
            return true; // xXx xxXx
        }
    }
    return false;
}

From source file:com.compomics.colims.distributed.playground.AnnotatedSpectraParser.java

/**
 * Parse the APL files for given aplKeys and put the peaks in the spectrumPeaks list.
 *//*from  ww w. jav  a  2s .  c o m*/
private void parseAplFile() throws IOException {
    for (Path aplFilePath : aplFilePaths.keySet()) {
        if (!Files.exists(aplFilePath)) {
            throw new FileNotFoundException(
                    "The apl spectrum file " + aplFilePath.toString() + " could not be found.");
        }
        try (BufferedReader bufferedReader = Files.newBufferedReader(aplFilePath)) {
            String line;
            Map<String, String> headers = new HashMap<>();

            while ((line = bufferedReader.readLine()) != null) {
                //look for a spectrum entry
                if (line.startsWith(APL_SPECTUM_START)) {
                    //go to the next line
                    line = bufferedReader.readLine();
                    //parse spectrum header part
                    while (!Character.isDigit(line.charAt(0))) {
                        String[] split = line.split(APL_HEADER_DELIMITER);
                        headers.put(split[0], split[1]);
                        line = bufferedReader.readLine();
                    }
                    //" Precursor: 0 _multi_" is removed before looking up the key in the spectra map
                    String header = org.apache.commons.lang3.StringUtils
                            .substringBefore(headers.get(APL_HEADER), " Precursor");
                    //check if the spectrum was identified and therefore can be found in the spectra map
                    if (aplKeys.contains(header)) {
                        List<Peak> peakList = new ArrayList<>();
                        while (!line.startsWith(APL_SPECTUM_END)) {
                            String[] splitLine = line.split(MaxQuantConstants.PARAM_TAB_DELIMITER.value());
                            Peak peak = new Peak(Double.parseDouble(splitLine[0]),
                                    Double.parseDouble(splitLine[1]));

                            peakList.add(peak);
                            line = bufferedReader.readLine();
                        }
                        spectrumPeaks.put(header, peakList);
                    }
                    //clear headers map
                    headers.clear();
                }
            }
        }
    }
}

From source file:com.SCI.centraltoko.utility.UtilityTools.java

public static void setNumericTextOnly(final JTextField textField) {
    textField.addKeyListener(new KeyAdapter() {

        @Override/*  w  ww  . j a  va  2s .c  o m*/
        public void keyTyped(KeyEvent e) {
            if (!Character.isDigit(e.getKeyChar()) || BAD_CHARS.indexOf(e.getKeyChar()) > -1) {
                e.consume();
            }
        }

    });

}

From source file:herudi.controller.microMarketController.java

@FXML
private void keyRadius(KeyEvent event) {
    char[] data = txtRadius.getText().toCharArray();
    boolean valid = true;
    for (char c : data) {
        if (!Character.isDigit(c)) {
            valid = false;/*  w ww.  j a  va2  s. c om*/
            break;
        }
    }
    if (!valid) {
        config2.dialog(Alert.AlertType.ERROR, "Please, Fill With Number");
        txtRadius.clear();
        txtRadius.requestFocus();
    }
}

From source file:org.dasein.cloud.openstack.nova.os.NovaOpenStack.java

public @Nonnegative int getMajorVersion() throws CloudException, InternalException {
    AuthenticationContext ctx = getAuthenticationContext();
    String endpoint = ctx.getComputeUrl();

    if (endpoint == null) {
        endpoint = ctx.getStorageUrl();/*from  w  ww .  j  a va  2 s. c  o  m*/
        if (endpoint == null) {
            return 1;
        }
    }
    while (endpoint.endsWith("/") && endpoint.length() > 1) {
        endpoint = endpoint.substring(0, endpoint.length() - 1);
    }
    String[] parts = endpoint.split("/");
    int idx = parts.length - 1;

    do {
        endpoint = parts[idx];
        while (!Character.isDigit(endpoint.charAt(0)) && endpoint.length() > 1) {
            endpoint = endpoint.substring(1);
        }
        if (Character.isDigit(endpoint.charAt(0))) {
            int i = endpoint.indexOf('.');

            try {
                if (i == -1) {
                    return Integer.parseInt(endpoint);
                }
                String[] d = endpoint.split("\\.");

                return Integer.parseInt(d[0]);
            } catch (NumberFormatException ignore) {
                // ignore
            }
        }
    } while ((idx--) > 0);
    return 1;
}

From source file:net.sourceforge.processdash.data.util.ResultSet.java

public void setFormat(int col, String format) {
    int len = 0, p, s;
    if (format == null || (len = format.length()) == 0) {
        multiplier[col] = 1.0;/*  w w  w  .ja va  2  s .  c om*/
        prefix[col] = suffix[col] = "";
    }

    // find end of prefix
    for (p = 0; p < len && !Character.isDigit(format.charAt(p)); p++)
        ;
    // find beginning of suffix
    for (s = len; s > 0 && !Character.isDigit(format.charAt(s - 1)); s--)
        ;

    if (p > 0)
        prefix[col] = format.substring(0, p);
    if (s > p) {
        suffix[col] = format.substring(s);
        String mult = format.substring(p, s);
        try {
            if (mult.indexOf('.') == -1)
                multiplier[col] = Integer.parseInt(mult);
            else
                multiplier[col] = Double.parseDouble(mult);
        } catch (NumberFormatException nfe) {
        }
        if (multiplier[col] == 0)
            multiplier[col] = 1.0;
    }
}

From source file:com.allmycode.flags.MyActivity.java

boolean isDec(String string) {
    boolean temp = true;
    for (char character : string.toCharArray()) {
        temp = temp && Character.isDigit(character);
    }/*  w  ww  . j a v  a 2s .  co m*/
    return temp;
}

From source file:com.qwazr.utils.StringUtils.java

public static boolean anyDigit(CharSequence chars) {
    if (chars == null)
        return false;
    return chars.chars().anyMatch(new IntPredicate() {
        @Override//from   w w w .  ja v  a 2 s .  c o m
        public boolean test(int value) {
            return Character.isDigit(value);
        }
    });
}