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:net.sf.vfsjfilechooser.accessories.connection.ConnectionDialog.java

private void initListeners() {
    this.portTextField.addKeyListener(new KeyAdapter() {
        @Override//w w w  .  j a  va  2  s . c o m
        public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();

            if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))) {
                getToolkit().beep();
                e.consume();
            } else {
                setPortTextFieldDirty(true);
            }
        }
    });

    this.portTextField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            JFormattedTextField f = (JFormattedTextField) e.getSource();
            String text = f.getText();

            if (text.length() == 0) {
                f.setValue(null);
            }

            try {
                f.commitEdit();
            } catch (ParseException exc) {
            }
        }
    });

    this.cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (currentWorker != null) {
                if (currentWorker.isAlive()) {
                    currentWorker.interrupt();
                    setCursor(Cursor.getDefaultCursor());
                }
            }

            setVisible(false);
        }
    });

    this.connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            currentWorker = new Thread() {
                @Override
                public void run() {
                    StringBuilder error = new StringBuilder();
                    FileObject fo = null;

                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                    try {
                        String m_username = usernameTextField.getText();
                        String m_defaultRemotePath = defaultRemotePathTextField.getText();
                        char[] m_password = passwordTextField.getPassword();
                        String m_hostname = hostnameTextField.getText();
                        String m_protocol = protocolList.getSelectedItem().toString();

                        int m_port = -1;

                        if (portTextField.isEditValid() && (portTextField.getValue() != null)) {
                            String s = portTextField.getValue().toString();
                            m_port = Integer.valueOf(s);
                        }

                        Builder credentialsBuilder = Credentials.newBuilder(m_hostname)
                                .defaultRemotePath(m_defaultRemotePath).username(m_username)
                                .password(m_password).protocol(m_protocol).port(m_port);

                        Credentials credentials = credentialsBuilder.build();

                        String uri = credentials.toFileObjectURL();

                        if (isInterrupted()) {
                            setPortTextFieldDirty(false);

                            return;
                        }

                        fo = VFSUtils.resolveFileObject(uri);

                        if ((fo != null) && !fo.exists()) {
                            fo = null;
                        }
                    } catch (Exception err) {
                        error.append(err.getMessage());
                        setCursor(Cursor.getDefaultCursor());
                    }

                    if ((error.length() > 0) || (fo == null)) {
                        error.delete(0, error.length());
                        error.append("Failed to connect!");
                        error.append("\n");
                        error.append("Please check parameters and try again.");

                        JOptionPane.showMessageDialog(ConnectionDialog.this, error, "Error",
                                JOptionPane.ERROR_MESSAGE);
                        setCursor(Cursor.getDefaultCursor());

                        return;
                    }

                    if (isInterrupted()) {
                        return;
                    }

                    fileChooser.setCurrentDirectory(fo);

                    setCursor(Cursor.getDefaultCursor());

                    resetFields();

                    if (bookmarksDialog != null) {
                        String bTitle = fo.getName().getBaseName();

                        if (bTitle.trim().equals("")) {
                            bTitle = fo.getName().toString();
                        }

                        String bURL = fo.getName().getURI();
                        bookmarksDialog.getBookmarks().add(new TitledURLEntry(bTitle, bURL));
                        bookmarksDialog.getBookmarks().save();
                    }

                    setVisible(false);
                }
            };

            currentWorker.setPriority(Thread.MIN_PRIORITY);
            currentWorker.start();
        }
    });

    // add the usual right click popup menu(copy, paste, etc.)
    PopupHandler.installDefaultMouseListener(hostnameTextField);
    PopupHandler.installDefaultMouseListener(portTextField);
    PopupHandler.installDefaultMouseListener(usernameTextField);
    PopupHandler.installDefaultMouseListener(passwordTextField);
    PopupHandler.installDefaultMouseListener(defaultRemotePathTextField);

    this.protocolList.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectPortNumber();
            }
        }
    });

    this.protocolList.setSelectedItem(Protocol.FTP);
}

From source file:com.daveayan.rjson.Rjson.java

private Object convertToObject(String json, JSONTokener tokener, Class<?> to) throws JSONException {
    char firstChar = tokener.nextClean();
    if (firstChar == '\"') {
        return json_to_object_transformer.transform(tokener.nextString('\"'), String.class, "", null);
    }//  w  ww  .j  a va2  s  .c  o m
    if (firstChar == '{') {
        tokener.back();
        JSONObject jsonObject = new JSONObject(tokener);
        if (!jsonObject.has("jvm_class_name")) {
            return json_to_object_transformer.transform(jsonObject, HashMap.class, "", null);
        } else {
            tokener = new JSONTokener(json);
            tokener.nextClean();
        }
    }
    if (firstChar == '[') {
        tokener.back();
        return json_to_object_transformer.transform(new JSONArray(tokener), ArrayList.class, "", null);
    }
    if (Character.isDigit(firstChar)) {
        tokener.back();
        return json_to_object_transformer.transform(tokener.nextValue(), Double.class, "", null);
    }
    tokener.back();
    return json_to_object_transformer.transform(tokener.nextValue(), Object.class, "", null);
}

From source file:com.abstratt.mdd.frontend.textuml.renderer.TextUMLRenderingUtils.java

private static String escapeIdentifierIfNeeded(String identifier) {
    if (StringUtils.isBlank(identifier))
        return "";
    if (!StringUtils.isAlpha(identifier)) {
        StringBuffer result = new StringBuffer(identifier.length());
        char[] chars = identifier.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] != '_'
                    && ((Character.isDigit(chars[i]) && i == 0) || !Character.isLetterOrDigit(chars[i])))
                result.append('\\');
            result.append(chars[i]);//from   ww  w  . j  a v  a 2s  .c om
        }
        return result.toString();
    }
    if (Arrays.binarySearch(TextUMLConstants.KEYWORDS, identifier) >= 0)
        return "\\" + identifier;
    return identifier;
}

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

private String lexInt(final Reader in, final int firstChar) throws IOException {
    final StringBuilder sb = new StringBuilder();
    int digits = 0;
    if (firstChar == '-') {
        sb.append("-");
    } else if (Character.isDigit(firstChar)) {
        sb.append(Character.toChars(firstChar));
        digits++;/*from  w  ww.j a v a  2s  .  c  o m*/
    } else {
        final String found = new String(Character.toChars(firstChar));
        throw new ParserException("Expecting a number, instead found: '" + found + QUOTE);
    }
    while (true) {
        in.mark(MAX_BUFFER);
        final int c = in.read();
        if (Character.isDigit(c)) {
            digits++;
            sb.append(Character.toChars(c));
        } else {
            in.reset();
            if (digits == 0) {
                throw new ParserException(EXPECTED_DIGIT);
            }
            return sb.toString();
        }
    }
}

From source file:FormatTest.java

public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
        throws BadLocationException {
    StringBuilder builder = new StringBuilder(string);
    for (int i = builder.length() - 1; i >= 0; i--) {
        int cp = builder.codePointAt(i);
        if (!Character.isDigit(cp) && cp != '-') {
            builder.deleteCharAt(i);//w w w  .  j av  a2  s.  co m
            if (Character.isSupplementaryCodePoint(cp)) {
                i--;
                builder.deleteCharAt(i);
            }
        }
    }
    super.insertString(fb, offset, builder.toString(), attr);
}

From source file:com.googlecode.vfsjfilechooser2.accessories.connection.ConnectionDialog.java

private void initListeners() {
    this.portTextField.addKeyListener(new KeyAdapter() {
        @Override//w  w w  .j  a  v a 2  s  .  co m
        public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();

            if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))) {
                getToolkit().beep();
                e.consume();
            } else {
                setPortTextFieldDirty(true);
            }
        }
    });

    this.portTextField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            JFormattedTextField f = (JFormattedTextField) e.getSource();
            String text = f.getText();

            if (text.length() == 0) {
                f.setValue(null);
            }

            try {
                f.commitEdit();
            } catch (ParseException exc) {
            }
        }
    });

    this.cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (currentWorker != null) {
                if (currentWorker.isAlive()) {
                    currentWorker.interrupt();
                    setCursor(Cursor.getDefaultCursor());
                }
            }

            setVisible(false);
        }
    });

    this.connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            currentWorker = new Thread() {
                @Override
                public void run() {
                    StringBuilder error = new StringBuilder();
                    FileObject fo = null;

                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                    try {
                        String m_username = usernameTextField.getText();
                        String m_defaultRemotePath = defaultRemotePathTextField.getText();
                        char[] m_password = passwordTextField.getPassword();
                        String m_hostname = hostnameTextField.getText();
                        String m_protocol = protocolList.getSelectedItem().toString();

                        int m_port = -1;

                        if (portTextField.isEditValid() && (portTextField.getValue() != null)) {
                            String s = portTextField.getValue().toString();
                            m_port = Integer.valueOf(s);
                        }

                        Builder credentialsBuilder = Credentials.newBuilder(m_hostname)
                                .defaultRemotePath(m_defaultRemotePath).username(m_username)
                                .password(m_password).protocol(m_protocol).port(m_port);

                        Credentials credentials = credentialsBuilder.build();

                        String uri = credentials.toFileObjectURL();

                        if (isInterrupted()) {
                            setPortTextFieldDirty(false);

                            return;
                        }

                        fo = VFSUtils.resolveFileObject(uri);

                        if ((fo != null) && !fo.exists()) {
                            fo = null;
                        }
                    } catch (Exception err) {
                        error.append(err.getMessage());
                        setCursor(Cursor.getDefaultCursor());
                    }

                    if ((error.length() > 0) || (fo == null)) {
                        error.delete(0, error.length());
                        error.append("Failed to connect!");
                        error.append("\n");
                        error.append("Please check parameters and try again.");

                        JOptionPane.showMessageDialog(ConnectionDialog.this, error, "Error",
                                JOptionPane.ERROR_MESSAGE);
                        setCursor(Cursor.getDefaultCursor());

                        return;
                    }

                    if (isInterrupted()) {
                        return;
                    }

                    fileChooser.setCurrentDirectoryObject(fo);

                    setCursor(Cursor.getDefaultCursor());

                    resetFields();

                    if (bookmarksDialog != null) {
                        String bTitle = fo.getName().getBaseName();

                        if (bTitle.trim().equals("")) {
                            bTitle = fo.getName().toString();
                        }

                        String bURL = fo.getName().getURI();
                        bookmarksDialog.getBookmarks().add(new TitledURLEntry(bTitle, bURL));
                        bookmarksDialog.getBookmarks().save();
                    }

                    setVisible(false);
                }
            };

            currentWorker.setPriority(Thread.MIN_PRIORITY);
            currentWorker.start();
        }
    });

    // add the usual right click popup menu(copy, paste, etc.)
    PopupHandler.installDefaultMouseListener(hostnameTextField);
    PopupHandler.installDefaultMouseListener(portTextField);
    PopupHandler.installDefaultMouseListener(usernameTextField);
    PopupHandler.installDefaultMouseListener(passwordTextField);
    PopupHandler.installDefaultMouseListener(defaultRemotePathTextField);

    this.protocolList.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectPortNumber();
            }
        }
    });

    this.protocolList.setSelectedItem(Protocol.FTP);
}

From source file:de.uni_koblenz.west.splendid.tools.NQuadSourceAggregator.java

/**
 * Checks if the host name is an IP address.
 * //from w ww  .j av  a  2 s . com
 * @param host the host name to check.
 * @return true is the host name is an IP address; false otherwise.
 */
private boolean isIPAddress(String host) {
    for (char c : host.toCharArray()) {
        if (!Character.isDigit(c) && !(c == '.')) {
            return false;
        }
    }
    return true;
}

From source file:com.prowidesoftware.swift.model.IBAN.java

/**
 *
 * @param iban//from w w w. j  a  v a2 s . c  o  m
 * @return the resulting IBAN
 */
public String removeNonAlpha(final String iban) {
    final StringBuilder result = new StringBuilder();
    for (int i = 0; i < iban.length(); i++) {
        char c = iban.charAt(i);
        if (Character.isLetter(c) || Character.isDigit(c)) {
            result.append((char) c);
        }
    }
    return result.toString();
}

From source file:TPPDekuBot.BattleBot.java

@Override
public void onWhisper(User sender, String target, String message) {
    append("WHISPER FROM " + sender.getNick() + ": " + message);
    if ((sender.getNick().equalsIgnoreCase("the_chef1337")
            || sender.getNick().equalsIgnoreCase("wow_deku_onehand"))
            && message.toLowerCase().startsWith("!sendrawline ")) {
        String line = message.split(" ", 2)[1];
        this.sendRawLine(line);
        return;/*from   w  w  w .  j av a  2  s. c  o m*/
    }
    if ((message.toLowerCase().startsWith("!accept")) && (waitingPlayer || waitingPWT)
            && sender.getNick().equalsIgnoreCase(waitingOn)) {
        try {
            player.put(sender.getNick());
        } catch (Exception ex) {
        }
    }
    if (isInBattle() && battle instanceof MultiplayerBattle) {
        MultiplayerBattle mpB = (MultiplayerBattle) battle;
        String channel = "#_keredau_1423645868201";
        if (message.toLowerCase().startsWith("!run") || (message.toLowerCase().startsWith("!switch")
                && message.length() >= 8 && Character.isDigit(message.charAt(7)))
                || Move.isValidMove(message)) {
            if (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())) {
                try {
                    mpB.p1msg.put(message);
                } catch (Exception ex) {
                }
            }
            if (sender.getNick().equalsIgnoreCase(mpB.getPlayer2())) {
                try {
                    mpB.p2msg.put(message);
                } catch (Exception ex) {
                }
            }
        }
        if (message.toLowerCase().startsWith("!list")) {
            if (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())) {
                try {
                    String pokemon = mpB.player1.getPokemonList();
                    this.sendMessage(channel, "/w " + sender.getNick() + " Your pokemon are: " + pokemon);
                } catch (Exception ex) {
                    this.sendMessage(channel,
                            "/w " + sender.getNick() + " You have no other Pokemon in your party!");
                }
            } else if (sender.getNick().equalsIgnoreCase(mpB.getPlayer2())) {
                try {
                    String pokemon = mpB.player2.getPokemonList();
                    this.sendMessage(channel, "/w " + sender.getNick() + " Your pokemon are: " + pokemon);
                } catch (Exception ex) {
                    this.sendMessage(channel,
                            "/w " + sender.getNick() + " You have no other Pokemon in your party!");
                }
            }
            return;
        }
        if (message.toLowerCase().startsWith("!check") && message.length() >= 7
                && Character.isDigit(message.charAt(6))) {
            int check = Integer.parseInt(message.charAt(6) + "");
            if (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())) {
                Pokemon p = mpB.player1.getPokemon(check);
                this.sendMessage(channel,
                        "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1()
                                + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): "
                                + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: "
                                + p.getMove1().getName() + ", " + p.getMove2().getName() + ", "
                                + p.getMove3().getName() + ", " + p.getMove4().getName());
            } else if (sender.getNick().equalsIgnoreCase(mpB.getPlayer2())) {
                Pokemon p = mpB.player2.getPokemon(check);
                this.sendMessage(channel,
                        "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1()
                                + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): "
                                + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: "
                                + p.getMove1().getName() + ", " + p.getMove2().getName() + ", "
                                + p.getMove3().getName() + ", " + p.getMove4().getName());
            }
        }
        if (message.toLowerCase().startsWith("!help") && (isInBattle() && battle instanceof MultiplayerBattle)
                && (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())
                        || sender.getNick().equalsIgnoreCase(mpB.getPlayer2()))) {
            this.sendMessage(channel, "/w " + sender.getNick()
                    + " Type !list to see a list of your Pokemon. Type !checkx where x is the number of the Pokemon from !list to see it's moves. Type !switchx where x is number of the Pokemon from !list to switch to a Pokemon.");
        }
    }
    if (isInBattle() && battle instanceof PWTBattle) {
        PWTBattle mpB = (PWTBattle) battle;
        String channel = "#_keredau_1423645868201";
        if (message.toLowerCase().startsWith("!run") || (message.toLowerCase().startsWith("!switch")
                && message.length() >= 8 && Character.isDigit(message.charAt(7)))
                || Move.isValidMove(message)) {
            if (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) {
                try {
                    mpB.p1msg.put(message);
                } catch (Exception ex) {
                }
            }
            if (sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) {
                try {
                    mpB.p2msg.put(message);
                } catch (Exception ex) {
                }
            }
        }
        if (message.toLowerCase().startsWith("!list")) {
            if (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) {
                try {
                    String pokemon = mpB.player1.getPokemonList();
                    this.sendMessage(channel, "/w " + sender.getNick() + " Your pokemon are: " + pokemon);
                } catch (Exception ex) {
                    this.sendMessage(channel,
                            "/w " + sender.getNick() + " You have no other Pokemon in your party!");
                }
            } else if (sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) {
                try {
                    String pokemon = mpB.player2.getPokemonList();
                    this.sendMessage(channel, "/w " + sender.getNick() + " Your pokemon are: " + pokemon);
                } catch (Exception ex) {
                    this.sendMessage(channel,
                            "/w " + sender.getNick() + " You have no other Pokemon in your party!");
                }
            }
            return;
        }
        if (message.toLowerCase().startsWith("!check") && message.length() >= 7
                && Character.isDigit(message.charAt(6))) {
            int check = Integer.parseInt(message.charAt(6) + "");
            if (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) {
                Pokemon p = mpB.player1.getPokemon(check);
                this.sendMessage(channel,
                        "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1()
                                + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): "
                                + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: "
                                + p.getMove1().getName() + ", " + p.getMove2().getName() + ", "
                                + p.getMove3().getName() + ", " + p.getMove4().getName());
            } else if (sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) {
                Pokemon p = mpB.player2.getPokemon(check);
                this.sendMessage(channel,
                        "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1()
                                + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): "
                                + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: "
                                + p.getMove1().getName() + ", " + p.getMove2().getName() + ", "
                                + p.getMove3().getName() + ", " + p.getMove4().getName());
            }
        }
        if (message.toLowerCase().startsWith("!help") && (isInBattle() && battle instanceof PWTBattle)
                && (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName()))
                || sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) {
            this.sendMessage(channel, "/w " + sender.getNick()
                    + " Type !list to see a list of your Pokemon. Type !checkx where x is the number of the Pokemon from !list to see it's moves. Type !switchx where x is number of the Pokemon from !list to switch to a Pokemon.");
        }
    }
}

From source file:Game.InteractionCase.java

public boolean process(Card c, String id) {
    if (reaction_only) {
        if (c.is_block()) {
            selectedSpecials.add(c);/* www .j  ava  2  s .  c  o  m*/
            selectedIds.add(id);
            return true;
        } else
            return false;
    }

    String name = c.getName();
    int cost = c.getCost();
    if ((cost > maximum_cost) || (cost < minimum_cost))
        return false;
    if (selectedSpecials.size() >= maximum_amount)
        return false;
    System.out.println("INCOMING INTERACTIONCASE REQUEST");
    System.out.println("Cardname : " + c.getName() + " - " + "ID: " + id);
    System.out.println("======= ALLOWEDIDS ======");
    for (String s : allowedIds)
        System.out.print(s + " , ");
    System.out.println("=========================");

    if (Character.isDigit(id.charAt(0))) {
        for (String s : selectedIds) {
            if (s.startsWith(id.split("_")[0]))
                return false;
        }
        if (c instanceof ActionCard) {
            if (!action_hand_enabled)
                return false;
        } else if (c instanceof TreasureCard) {
            if (!treasure_hand_enabled)
                return false;
        } else if (c instanceof VictoryCard) {
            if (!victory_hand_enabled)
                return false;
        }
    } else {
        ArrayList<String> nextallowedids = new ArrayList<>();
        nextallowedids.addAll(allowedIds);
        boolean allowed = false;
        for (String s : allowedIds) {
            if (id.startsWith(s)) {
                allowed = true;
                nextallowedids.remove(s);
                break;
            }
        }

        if (c instanceof ActionCard) {
            if (!action_env_enabled)
                return false;
        } else if (c instanceof TreasureCard) {
            if (!treasure_env_enabled)
                return false;
        } else if (c instanceof VictoryCard) {
            if (!victory_env_enabled)
                return false;
        }
        if (!allowed)
            return false;
        else
            allowedIds = nextallowedids;
    }
    System.out.println("INTERACTIONCASE PROCESSING FINISHED.");
    System.out.println("=====  LEAVING CASE WITH ALLOWED IDS: ========");
    for (String s : allowedIds)
        System.out.println(s + " , ");
    System.out.println("===============================================");
    // If this code is reached, all validations have passed, and nothing returned false.
    selectedSpecials.add(c);
    selectedIds.add(id);
    return true;
}