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.aurel.track.item.ItemBL.java

/**
 * Gets the workitem by projectSpecificID
 * @param projectSpecificID// w  ww  .  j  a  va2 s.  c  o m
 * @return
 * @throws ItemLoaderException
 */
public static TWorkItemBean loadWorkItemByProjectSpecificID(String projectSpecificID)
        throws ItemLoaderException {
    if (projectSpecificID != null) {
        StringBuilder prefixBuilder = new StringBuilder();
        StringBuilder idBuilder = new StringBuilder();
        for (int i = 0; i < projectSpecificID.length(); i++) {
            char charValue = projectSpecificID.charAt(i);
            if (Character.isDigit(charValue)) {
                idBuilder.append(charValue);
            } else {
                if (idBuilder.length() > 0) {
                    prefixBuilder.append(idBuilder);
                    idBuilder = new StringBuilder();
                }
                prefixBuilder.append(charValue);
            }
        }
        String prefix = prefixBuilder.toString();
        Integer idNumber = null;
        try {
            idNumber = Integer.parseInt(idBuilder.toString());
        } catch (Exception ex) {
        }
        List<TProjectBean> projetctsWithPrefix = ProjectBL.loadByPrefix(prefix);
        if (projetctsWithPrefix != null) {
            for (TProjectBean projectBean : projetctsWithPrefix) {
                TWorkItemBean workItemBean = workItemDAO.loadByProjectSpecificID(projectBean.getObjectID(),
                        idNumber);
                if (workItemBean != null) {
                    return workItemBean;
                }
            }
        }
    }
    return null;
}

From source file:reportsas.com.formulapp.Formulario.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        if (data != null) {
            if (data.hasExtra("data")) {

                Bitmap photobmp = (Bitmap) data.getParcelableExtra("data");

                // iv.setImageBitmap(photobmp);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                photobmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                byte[] imageBytes = baos.toByteArray();
                String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);

                if (parametroCam == null) {
                    parametroCam = new ParametrosRespuesta(2);
                }/*from   w w w . ja va2 s  .c  om*/

                parametroCam.setValor(encodedImage);

                // prueba.setText(encodedImage);
                //    new MyAsyncTask(Formulario.this)
                //          .execute("POST",encodedImage, HTTP_EVENT);
            }

        }
    }

    if (requestCode == MY_REQUEST_CODE && resultCode == Pdf417ScanActivity.RESULT_OK) {
        // First, obtain scan results array. If scan was successful, array will contain at least one element.
        // Multiple element may be in array if multiple scan results from single image were allowed in settings.

        Parcelable[] resultArray = data
                .getParcelableArrayExtra(Pdf417ScanActivity.EXTRAS_RECOGNITION_RESULT_LIST);

        StringBuilder sb = new StringBuilder();

        for (Parcelable p : resultArray) {
            if (p instanceof Pdf417ScanResult) { // check if scan result is result of Pdf417 recognizer
                Pdf417ScanResult result = (Pdf417ScanResult) p;
                // getStringData getter will return the string version of barcode contents
                String barcodeData = result.getStringData();

                // isUncertain getter will tell you if scanned barcode contains some uncertainties
                boolean uncertainData = result.isUncertain();
                // getRawData getter will return the raw data information object of barcode contents
                BarcodeDetailedData rawData = result.getRawData();
                // BarcodeDetailedData contains information about barcode's binary layout, if you
                // are only interested in raw bytes, you can obtain them with getAllData getter
                byte[] rawDataBuffer = rawData.getAllData();
                DataR = rawData.toString();

                String[] arrayElements = DataR.split("Element #");
                String Nombre = "", Apellido = "", cedula = "", fecha = "", dia, mes, ano;
                if (arrayElements.length >= 7) {
                    String[] auxliarArray = arrayElements[7].split("decoded\\):");

                    String strDatos = auxliarArray[1];
                    char[] ca = strDatos.toCharArray();
                    for (int i = 0; i < strDatos.length(); i++) {
                        if (Character.isLetter(ca[i])) //Si es letra
                            Apellido += ca[i]; //Salto de lnea e imprimimos el carcter
                        else //Si no es letra
                            cedula += ca[i]; //Imprimimos el carcter
                    }
                    Apellido = Apellido.trim();
                    cedula = (cedula.replaceAll("\n", "")).trim();
                    if (cedula.length() == 0) {
                        auxliarArray = arrayElements[5].split("decoded\\):");
                        strDatos = auxliarArray[1];
                        ca = strDatos.toCharArray();
                        Apellido = "";
                        for (int i = 0; i < strDatos.length(); i++) {
                            if (Character.isLetter(ca[i])) //Si es letra
                                Apellido += ca[i]; //Salto de lnea e imprimimos el carcter
                            else //Si no es letra
                                cedula += ca[i]; //Imprimimos el carcter
                        }
                        Apellido = Apellido.trim();
                        cedula = (cedula.replaceAll("\n", "")).trim();
                        cedula = cedula.substring(cedula.length() - 10, cedula.length());
                        cedula = eliminarceros(cedula);
                        auxliarArray = arrayElements[9].split("decoded\\):");
                        Nombre = (auxliarArray[1].replaceAll("\n", "")).trim();

                    } else {

                        cedula = eliminarceros(cedula);
                        auxliarArray = arrayElements[11].split("decoded\\):");
                        Nombre = (auxliarArray[1].replaceAll("\n", "")).trim();
                    }

                    auxliarArray = result.getStringData().toString().split(Nombre);
                    strDatos = auxliarArray[1];
                    ca = strDatos.toCharArray();
                    Boolean result_ciclo = true;
                    int i = 0;
                    while (result_ciclo) {
                        if (Character.isDigit(ca[i])) {
                            fecha += ca[i];
                        }
                        if (fecha.length() >= 9) {
                            result_ciclo = false;
                        }
                        i++;
                    }
                    fecha = fecha.substring(1, fecha.length());
                } else {
                    int puntoI = 0;
                    if (barcodeData.indexOf("1F") > 0) {
                        puntoI = barcodeData.indexOf("1F");
                    } else if (barcodeData.indexOf("0M") > 0) {
                        puntoI = barcodeData.indexOf("0M");
                    } else if (barcodeData.indexOf("0F") > 0) {
                        puntoI = barcodeData.indexOf("0F");
                    } else if (barcodeData.indexOf("1M") > 0) {
                        puntoI = barcodeData.indexOf("1M");
                    } else {

                    }
                    if (puntoI > 0) {
                        String seb = barcodeData.substring(1, puntoI);
                        fecha = barcodeData.substring(puntoI + 2, puntoI + 10);

                        int posL = 0, posE;
                        char[] ca = seb.toCharArray();
                        for (int w = seb.length() - 1; w > 0; w--) {
                            if (Character.isLetter(ca[w])) {
                                posL = w;
                                break;
                            }
                        }
                        seb = seb.substring(1, posL + 1);
                        ca = seb.toCharArray();
                        for (int w = seb.length() - 1; w > 0; w--) {
                            if (Character.isLetter(ca[w])) {
                                Nombre = ca[w] + Nombre;
                                posL = w;
                            } else {
                                break;
                            }
                        }
                        seb = seb.substring(1, posL);
                        ca = seb.toCharArray();
                        for (int w = seb.length() - 1; w > 0; w--) {
                            if (Character.isDigit(ca[w])) {
                                posL = w;
                                break;
                            }
                        }

                        for (int w = posL + 1; w <= seb.length(); w++) {
                            if (Character.isLetter(ca[w])) {
                                Apellido += ca[w];
                            } else {
                                break;
                            }
                        }

                        cedula = seb.substring(posL - 9, posL + 1);
                        cedula = eliminarceros(cedula);
                    } else {
                        fecha = "";
                    }
                }
                if (fecha.length() == 0) {
                    parametroScan = null;

                    Toast toast1 = Toast.makeText(this, "Los datos de codigo no pudieron ser interpretados!",
                            Toast.LENGTH_SHORT);

                    toast1.show();

                } else {
                    dia = fecha.substring(6, 8);
                    mes = fecha.substring(4, 6);
                    ano = fecha.substring(0, 4);
                    fecha = dia + "/" + mes + "/" + ano;

                    Infocadena = "Nombre: \n" + Nombre + ".\nApellido: \n" + Apellido + ". \nCedula: \n"
                            + cedula + ". \nFecha de Nacimiento: \n" + fecha + ".";
                    if (parametroScan == null) {
                        parametroScan = new ParametrosRespuesta(3);

                    }
                    parametroScan.setValor(Infocadena);

                }

                //  new MyAsyncTask(Formulario.this)
                //        .execute("POST",Infocadena, HTTP_EVENT);

            } else if (p instanceof BarDecoderScanResult) { // check if scan result is result of BarDecoder recognizer
                /* BarDecoderScanResult result = (BarDecoderScanResult) p;
                 // with getBarcodeType you can obtain barcode type enum that tells you the type of decoded barcode
                 BarcodeType type = result.getBarcodeType();
                 // as with PDF417, getStringData will return the string contents of barcode
                 String barcodeData = result.getStringData();
                 if(checkIfDataIsUrlAndCreateIntent(barcodeData)) {
                return;
                 } else {
                sb.append(type.name());
                sb.append(" string data:\n");
                sb.append(barcodeData);
                sb.append("\n\n\n");=
                 }*/
            } else if (p instanceof ZXingScanResult) { // check if scan result is result of ZXing recognizer
                /* ZXingScanResult result= (ZXingScanResult) p;
                 // with getBarcodeType you can obtain barcode type enum that tells you the type of decoded barcode
                 BarcodeType type = result.getBarcodeType();
                 // as with PDF417, getStringData will return the string contents of barcode
                 String barcodeData = result.getStringData();
                 if(checkIfDataIsUrlAndCreateIntent(barcodeData)) {
                return;
                 } else {
                sb.append(type.name());
                sb.append(" string data:\n");
                sb.append(barcodeData);
                sb.append("\n\n\n");
                 }*/
            } else if (p instanceof USDLScanResult) { // check if scan result is result of US Driver's Licence recognizer
                USDLScanResult result = (USDLScanResult) p;

                // USDLScanResult can contain lots of information extracted from driver's licence
                // you can obtain information using the getField method with keys defined in
                // USDLScanResult class

                String name = result.getField(USDLScanResult.kCustomerFullName);

                sb.append(result.getTitle());
                sb.append("\n\n");
                sb.append(result.toString());
            }
        }

    }
}

From source file:au.org.ala.delta.util.Utils.java

/**
 * The main job of this method is to terminate RTF control words with {}
 * instead of a space./* ww  w  .j  ava  2s .c om*/
 */
// Not all cases are handled correctly in the current code.
// For example, text with \bin might not always give correct results
// A few other things, such as \'xx, should perhaps also be given
// explicit treatment, but should not substantially affect the outcome.
public static String despaceRtf(String text, boolean quoteDelims) {
    if (StringUtils.isEmpty(text)) {
        return "";
    }
    int srcPos;
    boolean inRTF = false;
    boolean inParam = false;
    boolean inUnicode = false;
    boolean bracketed = text.charAt(0) == '<' && text.charAt(text.length() - 1) == '>';

    StringBuilder outputText = new StringBuilder(text);
    if (bracketed) // If a "comment", temporarily chop off the terminating
                   // bracket
        outputText.setLength(outputText.length() - 1);
    for (srcPos = 0; srcPos < outputText.length(); ++srcPos) {
        char ch = outputText.charAt(srcPos);
        // Always convert a tab character into a \tab control word
        if (ch == '\t') {
            outputText.replace(srcPos, srcPos + 1, "\\tab{}");
            ch = '\\';
        }
        if (inRTF) {
            if (Character.isDigit(ch) || (!inParam && ch == '-')) {
                if (!inParam && outputText.charAt(srcPos - 1) == 'u' && outputText.charAt(srcPos - 2) == '\\')
                    inUnicode = true;
                inParam = true;
            } else if (inParam || !Character.isLetter(ch)) {
                boolean wasInUnicode = inUnicode;
                inUnicode = inParam = inRTF = false;
                if (Character.isSpaceChar(ch)) {
                    // Check for the absence of a control; when this
                    // happens,
                    // the terminating character IS the control word!
                    if (srcPos > 0 && outputText.charAt(srcPos - 1) == '\\') {
                        // \<NEWLINE> is treated as a \par control. We make
                        // this
                        // change here explicitly, to make it more apparent.
                        // But should we keep the <NEWLINE> character around
                        // as well,
                        // as a clue for breaking lines during output?
                        if (ch == '\n' || ch == '\r') {
                            // text.replace(--srcPos, 2, "\\par{}");
                            outputText.insert(srcPos, "par{}");
                            srcPos += 5;
                        }
                        // (Note that if we don't catch this here, replacing
                        // "\ " could yield
                        // "\{}" which is WRONG. But rather than just get
                        // rid of this, it
                        // is probably better to replace with {} to ensure
                        // that any preceding
                        // RTF is terminated)
                        else if (ch == ' ') {
                            outputText.replace(srcPos - 1, 2, "{}");
                        }
                    }
                    // This is the chief condition we are trying to fix.
                    // Terminate the RTF
                    // control phrase with {} instead of white space...
                    // But if the terminator is a new line, we keep it
                    // around
                    // for assistance in wrapping output lines.
                    // else if (ch == '\n')
                    // {
                    // text.insert(srcPos, "{}");
                    // srcPos += 2;
                    // }
                    else if (ch != '\n') {
                        outputText.setCharAt(srcPos, '{');
                        outputText.insert(++srcPos, '}');
                    }
                }
                // No reason to do the following. Probably better to leave
                // the
                // character quoted.
                // Reinstated 8 December 1999 because we need to be sure
                // all text is in a consistent state when linking characters
                // One exception - if the quoted character is a Unicode
                // "replacement"
                // character, we'd better leave it quoted.
                else if (ch == '\'' && !wasInUnicode && srcPos + 2 < outputText.length()) {
                    char[] buff = new char[3];
                    buff[0] = outputText.charAt(srcPos + 1);
                    buff[1] = outputText.charAt(srcPos + 2);
                    buff[2] = 0;

                    int[] endPos = new int[1];
                    int value = strtol(new String(buff), endPos, 16);
                    if ((endPos[0] == 2) && value > 127 && outputText.charAt(srcPos - 1) == '\\') {

                        srcPos--;
                        outputText.replace(srcPos, srcPos + 4, new String(new char[] { (char) value }));

                    }
                } else if (ch == '\\' && outputText.charAt(srcPos - 1) != '\\') // Terminates
                                                                                // RTF,
                                                                                // but
                                                                                // starts
                                                                                // new
                                                                                // RTF
                {
                    inRTF = true;
                    if (wasInUnicode && srcPos + 1 < outputText.length()
                            && outputText.charAt(srcPos + 1) == '\'')
                        inUnicode = true;
                } else if (ch == '>') {
                    // Append a space after the RTF (it was probably
                    // stripped by the attribute parsing)
                    outputText.insert(srcPos, "{}");
                }
            }
        } else if (ch == '\\')
            inRTF = true;
        // TEST - to allow outputting of a "*" or "#" character in arbitrary
        // text...
        else if (quoteDelims && (ch == '*' || ch == '#')
                && (srcPos == 0 || Character.isSpaceChar(outputText.charAt(srcPos - 1)))) {
            // //char buffer[5];
            // Always build a 4-character replacement string, like:
            // \'20
            // //sprintf(buffer, "\\\'%2.2x", (int)ch);
            // //text.replace(srcPos, buffer, 4);
            // //srcPos += 3;
            outputText.insert(srcPos, "{}");
            srcPos += 2;
        }
    }
    if (inRTF)
        outputText.append("{}");
    if (bracketed)
        outputText.append('>');
    return outputText.toString();
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.parser.GWikiWikiParser.java

protected void parseLineHeadingText(GWikiWikiTokens tks, GWikiWikiParserContext ctx) {
    char tk = tks.curToken();
    String l = tks.curTokenString();
    if (l.length() == 2 && l.charAt(0) == 'h' && Character.isDigit(l.charAt(1)) == true) {
        if (tks.peekToken(1) == '.') {
            GWikiFragmentHeading hf = new GWikiFragmentHeading(Integer.valueOf(l.substring(1, 2)), "");
            try {
                ctx.pushFragStack(hf);//from   ww w  . ja  va2s. c  o  m
                tk = tks.nextToken();
                tk = tks.nextToken();
                tk = tks.skipWs();
                ctx.pushFragList();
                parseWords(tks, ctx);
                hf.addChilds(ctx.popFragList());
                ctx.addFragment(hf);
                // ctx.addTextFragement("\n");
                tk = tks.skipWsNl(false);
                if (tk != -1) {
                    tks.pushBack();
                }
            } finally {
                ctx.popFragStack();
            }
            return;
        }
    }
    parseLineText(tks, ctx);
}

From source file:org.botlibre.util.Utils.java

/**
 * Compress the text to be a proper identifier within the size limit.
 * Replace space with '-' and remove any non alpha numerics.
 */// w ww . j  av a2 s  .  co m
public static String compress(String text, int size) {
    TextStream stream = new TextStream(text);
    StringWriter writer = new StringWriter(text.length());
    int count = 0;
    while (!stream.atEnd()) {
        if (count >= size) {
            break;
        }
        char next = stream.next();
        if (Character.isLetter(next) || Character.isDigit(next) || (next == '_')) {
            writer.write(next);
        } else {
            writer.write('_');
        }
        count++;
    }
    return writer.toString();
}

From source file:practica1.Babage.java

private void textoEncriptadoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textoEncriptadoKeyTyped
    char c = evt.getKeyChar();
    if (Character.isDigit(c)) {
        getToolkit().beep();/*w w  w.j a v  a2 s .c  o  m*/
        evt.consume();
    }
}

From source file:com.unboundid.scim2.common.utils.JsonUtils.java

/**
 * Try to parse out a date from a JSON text node.
 *
 * @param node The JSON node to parse.// w w  w . j a  v  a2  s  .  c om
 *
 * @return A parsed date instance or {@code null} if the text is not an
 * ISO8601 formatted date and time string.
 */
private static Date dateValue(final JsonNode node) {
    String text = node.textValue().trim();
    if (text.length() >= 19 && Character.isDigit(text.charAt(0)) && Character.isDigit(text.charAt(1))
            && Character.isDigit(text.charAt(2)) && Character.isDigit(text.charAt(3))
            && text.charAt(4) == '-') {
        try {
            return ISO8601Utils.parse(text, new ParsePosition(0));
        } catch (ParseException e) {
            // This is not a date after all.
        }
    }
    return null;
}

From source file:edu.umich.robot.GuiApplication.java

public void createSuperdroidRobotDialog() {
    final Pose pose = new Pose();

    FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu",
            "pref, 2dlu, pref, 2dlu, pref");

    layout.setRowGroups(new int[][] { { 1, 3 } });

    final JDialog dialog = new JDialog(frame, "Create Superdroid Robot", true);
    dialog.setLayout(layout);/*from   w ww.ja v a  2  s.  co m*/
    final JTextField name = new JTextField();
    final JTextField x = new JTextField(Double.toString((pose.getX())));
    final JTextField y = new JTextField(Double.toString((pose.getY())));
    final JButton cancel = new JButton("Cancel");
    final JButton ok = new JButton("OK");

    CellConstraints cc = new CellConstraints();
    dialog.add(new JLabel("Name"), cc.xy(1, 1));
    dialog.add(name, cc.xyw(3, 1, 5));
    dialog.add(new JLabel("x"), cc.xy(1, 3));
    dialog.add(x, cc.xy(3, 3));
    dialog.add(new JLabel("y"), cc.xy(5, 3));
    dialog.add(y, cc.xy(7, 3));
    dialog.add(cancel, cc.xyw(1, 5, 3));
    dialog.add(ok, cc.xyw(5, 5, 3));

    x.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setX(Double.parseDouble(x.getText()));
            } catch (NumberFormatException ex) {
                x.setText(Double.toString(pose.getX()));
            }
        }
    });

    y.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setY(Double.parseDouble(y.getText()));
            } catch (NumberFormatException ex) {
                y.setText(Double.toString(pose.getX()));
            }
        }
    });

    final ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String robotName = name.getText().trim();
            if (robotName.isEmpty()) {
                logger.error("Create Superdroid: robot name empty");
                return;
            }
            for (char c : robotName.toCharArray())
                if (!Character.isDigit(c) && !Character.isLetter(c)) {
                    logger.error("Create Superdroid: illegal robot name");
                    return;
                }

            controller.createSuperdroidRobot(robotName, pose, true);
            controller.createSimSuperdroid(robotName);
            dialog.dispose();
        }
    };
    name.addActionListener(okListener);
    x.addActionListener(okListener);
    y.addActionListener(okListener);
    ok.addActionListener(okListener);

    ActionListener cancelAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    dialog.setLocationRelativeTo(frame);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:models.persistence.lecture.Lecture.java

@JsonIgnore
public String getShortName() {
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < name.length(); i++) {
        if (Character.isUpperCase(name.charAt(i)) || Character.isDigit(name.charAt(i)) || name.charAt(i) == '/'
                || name.charAt(i) == ' ' || name.charAt(i) == '+' || name.charAt(i) == '-') {
            sb.append(name.charAt(i));/* w  w w.j  ava  2 s .co m*/

            if (Character.isUpperCase(name.charAt(i))) {
                for (int j = i; j < i + 3 && j < name.length(); j++) {
                    if (Character.isLowerCase(name.charAt(j))) {
                        sb.append(name.charAt(j));
                    }
                }
            }
        }
    }

    return sb.toString().replaceAll("  ", "").replaceAll("AE", "").replaceAll("OE", "")
            .replaceAll("UE", "").trim();
    //return sb.toString().replaceAll("","AE").replaceAll("","OE").replaceAll("","UE").trim();
}

From source file:org.codehaus.griffon.commons.GriffonClassUtils.java

private static String convertPropertyName(String prop) {
    if (Character.isUpperCase(prop.charAt(0)) && Character.isUpperCase(prop.charAt(1))) {
        return prop;
    } else if (Character.isDigit(prop.charAt(0))) {
        return prop;
    } else {/*from  w ww. j a va2s.  c o m*/
        return String.valueOf(prop.charAt(0)).toLowerCase() + prop.substring(1);
    }
}