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.almarsoft.GroundhogReader.lib.MessageTextProcessor.java

public static Vector<HashMap<String, String>> saveUUEncodedAttachments(BufferedReader bodyTextReader,
        String group) throws IOException {

    Vector<HashMap<String, String>> bodyAttachments = new Vector<HashMap<String, String>>(1);
    String newBody = null;//from   w w w  .  j a v  a2 s  .co m
    Vector<HashMap<String, String>> attachDatas = null;

    StringBuilder newBodyBuilder = new StringBuilder();
    StringBuilder attachment = new StringBuilder();

    boolean inAttach = false;
    boolean firstOfTheEnd = false;

    String line, sline, filename = null;
    HashMap<String, String> attachData = null;

    attachDatas = new Vector<HashMap<String, String>>();

    while ((line = bodyTextReader.readLine()) != null) {

        // XXX: Probar a quitar esto (optimizacion)
        sline = line.trim();

        if (sline.equals("`")) {
            firstOfTheEnd = true;
            attachment.append(line + "\n");
        }

        else if (firstOfTheEnd && inAttach && sline.equals("end")) {

            attachment.append(line + "\n");
            if (attachDatas == null)
                attachDatas = new Vector<HashMap<String, String>>();

            try {
                attachData = FSUtils.saveUUencodedAttachment(attachment.toString(), filename, group);
                attachDatas.add(attachData);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (UsenetReaderException e) {
                e.printStackTrace();
            }
            attachment = null;
            inAttach = false;
            firstOfTheEnd = false;
        }

        else if (firstOfTheEnd && inAttach && !sline.equals("end")) {
            firstOfTheEnd = false; // False alarm?
        }

        // XXX: ESTO NO SOPORTA UUENCODED SIN PERMISOS!!!
        else if (sline.length() >= 11 && sline.substring(0, 6).equals("begin ")
                && Character.isDigit(sline.charAt(6)) && Character.isDigit(sline.charAt(7))
                && Character.isDigit(sline.charAt(8)) && Character.isWhitespace(sline.charAt(9))
                && !Character.isWhitespace(sline.charAt(10))) {

            filename = sline.substring(10);
            inAttach = true;
            attachment.append(line + "\n");
        }

        else if (inAttach) {
            attachment.append(line + "\n");
        }

        else {
            newBodyBuilder.append(line + "\n");
        }

    }
    newBody = newBodyBuilder.toString();

    // Add the new body as first element
    HashMap<String, String> bodyMap = new HashMap<String, String>(1);
    bodyMap.put("body", newBody);
    bodyAttachments.add(bodyMap);

    if (attachDatas != null) {
        for (HashMap<String, String> attData : attachDatas) {
            bodyAttachments.insertElementAt(attData, 1);
        }
    }

    return bodyAttachments;
}

From source file:interfazGrafica.frmMoverRFC.java

private void txtCapturaCurpKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCapturaCurpKeyTyped
    char caracter = evt.getKeyChar();
    if (Character.isDigit(caracter) || Character.isLetter(caracter)) {
        String texto = txtCapturaCurp.getText() + caracter;
        txtCapturaCurp.setText(texto.toUpperCase());
        evt.consume();/* ww w . j av a 2 s.com*/
        this.repaint();
    } else {
        getToolkit().beep();
        evt.consume();
    }
}

From source file:BayesianAnalyzer.java

private boolean allDigits(String s) {
    for (int i = 0; i < s.length(); i++) {
        if (!Character.isDigit(s.charAt(i))) {
            return false;
        }//from  w  w w. j a v a  2s .c o m
    }
    return true;
}

From source file:com.prowidesoftware.swift.io.parser.SwiftParser.java

private static final boolean tagStarts(final String str) {
    final int l = str.length();

    if (l > 0 && !Character.isDigit(str.charAt(0))) {
        return false;
    }//from ww  w.  j  a  v  a2s .  co m

    // OK el primero es digito, el segundo puede ser dos cosas: letra o numero o :final
    if (l > 1) {
        char c2 = str.charAt(1);
        if (c2 == ':') {
            /*
             * 2015.10 miguel
             * aceptamos :1: por compatibilidad, pero no es un proper tagname
             */
            return true;
        }

        /*
         * 2015.10 miguel
         * idem antes, aceptamos :1A: por compatibilidad, pero no es un proper tagname
         */
        if (Character.isLetter(c2) && l > 2) {
            if (':' == str.charAt(2)) {
                return true;
            }
        }

        //  el segundo char debe ser un numero
        // Cubre caso 11: y 11a:
        if (Character.isDigit(c2) && l > 2) {
            if (':' == str.charAt(2)) {
                return true;
            }
            if (l > 3 && ':' == str.charAt(3) && Character.isLetter(str.charAt(2))) {
                return true;
            }
        }

    }
    return false;
}

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

/**
 * <p>//from w  w  w  .j  av a  2  s. c  o m
 * Pops up a window to create a new splinter robot to add to the simulation.
 */
public void createSplinterRobotDialog() {
    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 Splinter Robot", true);
    dialog.setLayout(layout);
    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 splinter: robot name empty");
                return;
            }
            for (char c : robotName.toCharArray())
                if (!Character.isDigit(c) && !Character.isLetter(c)) {
                    logger.error("Create splinter: illegal robot name");
                    return;
                }

            controller.createSplinterRobot(robotName, pose, true);
            controller.createSimSplinter(robotName);
            controller.createSimLaser(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:com.yahoo.dba.perf.myperf.springmvc.InnoController.java

private void parseIBuf(Map<String, String> valMap, String str) {
    try {/*w  ww .  j a v a 2  s .c om*/
        if (str == null || str.isEmpty())
            return;
        str = str.trim();
        if (str.startsWith("Ibuf: ")) {
            String str2 = str.substring(5).trim();
            String[] strs = str2.split(",");
            for (String s : strs) {
                String[] res = splitSpaceDelemitNameValuePair(s);
                if (res != null)
                    valMap.put("Ibuf " + res[0], res[1]);
            }

        } else if (Character.isDigit(str.charAt(0)))//value name pair
        {
            String[] strs = str.split(",");
            for (String s : strs) {
                String[] res = splitSpaceDelemitValueNamePair(s);
                if (res != null)
                    valMap.put(res[0], res[1]);
            }
        } else if (str.startsWith("Hash table")) {
            String[] strs = str.split(",");
            for (String s : strs) {
                if (s != null)
                    s = s.trim();
                else
                    continue;
                if (s.startsWith("Hash table")) {
                    String[] res = splitSpaceDelemitNameValuePair(s);
                    if (res != null)
                        valMap.put(res[0], res[1]);
                } else if (s.startsWith("node heap")) {
                    String[] ss = s.split(" ");
                    if (ss != null && ss.length > 3)
                        valMap.put("node heap buffer(s)", ss[3]);
                }
            }
        }

    } catch (Exception ex) {
    }
}

From source file:de.micromata.genome.gwiki.utils.html.Html2WikiFilter.java

@Override
public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
    flushText();/*w  w w  . j  a va  2  s  .com*/
    // todo <span style="font-family: monospace;">sadf</span> {{}}
    String en = element.rawname.toLowerCase();

    Html2WikiElement el = null;
    if (handleMacroTransformerBegin(en, attributes, true) == true) {
        ; // nothing more
    } else if (en.equals("p") == true) {
        String styleClass = attributes.getValue("class");
        String style = attributes.getValue("style");
        if (StringUtils.isNotBlank(styleClass) == true || StringUtils.isNotBlank(style) == true) {
            MacroAttributes ma = new MacroAttributes();
            ma.setCmd("p");
            if (StringUtils.isNotBlank(styleClass) == true) {
                ma.getArgs().setStringValue("class", styleClass);
            }
            if (StringUtils.isNotBlank(style) == true) {
                ma.getArgs().setStringValue("style", style);
            }
            GWikiMacroFragment mf = new GWikiMacroFragment(new GWikiHtmlBodyPTagMacro(), ma);
            parseContext.pushFragStack(mf);
            parseContext.pushFragList();
        }
    } else if (en.length() == 2 && en.charAt(0) == 'h' && Character.isDigit(en.charAt(1)) == true) {
        parseContext.addFragment(new GWikiFragmentHeading(Integer.parseInt("" + en.charAt(1))));
        parseContext.pushFragList();
    } else if (en.equals("ul") == true || en.equals("ol") == true) {
        parseContext.addFragment(new GWikiFragmentList(getListTag(en, attributes)));
        liStack.push(en);
        parseContext.pushFragList();
    } else if (en.equals("li") == true) {
        parseContext.addFragment(new GWikiFragmentLi(findFragInStack(GWikiFragmentList.class)));
        parseContext.pushFragList();
    } else if (isSimpleWordDeco(en, attributes) == true) {
        parseContext.pushFragList();
    } else if (en.equals("a") == true) {
        parseLink(attributes);
        parseContext.pushFragList();
    } else if (en.equals("table") == true) {
        createTable(element, attributes);
    } else if (en.equals("tr") == true) {
        createTr(element, attributes);
    } else if (en.equals("th") == true) {
        createThTd(element, attributes);
    } else if (en.equals("td") == true) {
        createThTd(element, attributes);
    } else if (en.equals("span") == true && handleSpanStart(element, attributes) == true) {
        // nothing
    } else if (en.equals("code") == true) {
        createCode(element, attributes);
    } else {
        if (supportedHtmlTags.contains(en) == true) {
            parseContext.addFragment(convertToBodyMacro(element, attributes, 0));
            parseContext.pushFragList();
        }
    }

}

From source file:immf.MyHtmlEmail.java

private static String random(int count, int start, int end, boolean letters, boolean numbers, char chars[],
        Random random) {//from  w w  w .j a va2  s .co m
    if (count == 0)
        return "";
    if (count < 0)
        throw new IllegalArgumentException("Requested random string length " + count + " is less than 0.");
    if (start == 0 && end == 0) {
        end = 123;
        start = 32;
        if (!letters && !numbers) {
            start = 0;
            end = 2147483647;
        }
    }
    StringBuffer buffer = new StringBuffer();
    int gap = end - start;
    while (count-- != 0) {
        char ch;
        if (chars == null)
            ch = (char) (random.nextInt(gap) + start);
        else
            ch = chars[random.nextInt(gap) + start];
        if (letters && numbers && Character.isLetterOrDigit(ch) || letters && Character.isLetter(ch)
                || numbers && Character.isDigit(ch) || !letters && !numbers)
            buffer.append(ch);
        else
            count++;
    }
    return buffer.toString();
}

From source file:me.ryanhamshire.PopulationDensity.PopulationDensity.java

String getRegionNameError(String name, boolean console) {
    if (name.length() > this.maxRegionNameLength) {
        if (console)
            return "Name too long.";
        else//from w  ww .j  a  v  a  2 s  .c om
            return this.dataStore.getMessage(Messages.RegionNameLength, String.valueOf(maxRegionNameLength));
    }

    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);
        if (!Character.isLetter(c) && !Character.isDigit(c) && c != ' ') {
            if (console)
                return "Name includes symbols or puncutation.";
            else
                return this.dataStore.getMessage(Messages.RegionNamesOnlyLettersAndNumbers);
        }
    }

    return null;
}