List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:com.atlassian.jira.util.system.VersionNumber.java
private int parse(final String segment) { try {//from w w w . j a v a2 s . c om return segment.length() == 0 ? 0 : Integer.parseInt(getVersion(segment)); } catch (final NumberFormatException e) { final StringBuilder buffer = new StringBuilder(); for (int i = 0; i < segment.length(); i++) { final char c = segment.charAt(i); if (Character.isDigit(c)) { buffer.append(c); } } return parse(buffer.toString()); } }
From source file:eu.stratosphere.nephele.jobmanager.web.LogfileInfoServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {/*from ww w. j a v a 2 s .c o m*/ if ("stdout".equals(req.getParameter("get"))) { // Find current stdtout file for (File f : logDir.listFiles()) { // contains "jobmanager" ".log" and no number in the end ->needs improvement if (f.getName().equals("jobmanager-stdout.log") || (f.getName().indexOf("jobmanager") != -1 && f.getName().indexOf(".out") != -1 && !Character.isDigit(f.getName().charAt(f.getName().length() - 1)))) { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("text/plain "); writeFile(resp.getOutputStream(), f); break; } } } else { // Find current logfile for (File f : logDir.listFiles()) { // contains "jobmanager" ".log" and no number in the end ->needs improvement if (f.getName().equals("jobmanager-stderr.log") || (f.getName().indexOf("jobmanager") != -1 && f.getName().indexOf(".log") != -1 && !Character.isDigit(f.getName().charAt(f.getName().length() - 1)))) { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("text/plain "); writeFile(resp.getOutputStream(), f); break; } } } } catch (Throwable t) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().print(t.getMessage()); if (LOG.isWarnEnabled()) { LOG.warn(StringUtils.stringifyException(t)); } } }
From source file:com.salesmanager.core.util.StringUtil.java
/** * Can be used to decode URL /*ww w .j a v a 2s . com*/ * @param s * @return */ public static String unescape(String s) { StringBuffer sbuf = new StringBuffer(); int l = s.length(); int ch = -1; int b, sumb = 0; for (int i = 0, more = -1; i < l; i++) { /* Get next byte b from URL segment s */ switch (ch = s.charAt(i)) { case '%': ch = s.charAt(++i); int hb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a') & 0xF; ch = s.charAt(++i); int lb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a') & 0xF; b = (hb << 4) | lb; break; case '+': b = ' '; break; default: b = ch; } /* Decode byte b as UTF-8, sumb collects incomplete chars */ if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte) sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb if (--more == 0) sbuf.append((char) sumb); // Add char to sbuf } else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits) sbuf.append((char) b); // Store in sbuf } else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits) sumb = b & 0x1f; more = 1; // Expect 1 more byte } else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits) sumb = b & 0x0f; more = 2; // Expect 2 more bytes } else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits) sumb = b & 0x07; more = 3; // Expect 3 more bytes } else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits) sumb = b & 0x03; more = 4; // Expect 4 more bytes } else /*if ((b & 0xfe) == 0xfc)*/ { // 1111110x (yields 1 bit) sumb = b & 0x01; more = 5; // Expect 5 more bytes } /* We don't test if the UTF-8 encoding is well-formed */ } return sbuf.toString(); }
From source file:com.odiago.flumebase.io.CharBufferUtils.java
/** * Parses a CharSequence into an integer in base 10. *///from w w w . jav a2 s . c o m public static int parseInt(CharBuffer chars) throws ColumnParseException { int result = 0; final int limit = chars.limit(); final int start = chars.position(); if (0 == limit - start) { // The empty string can not be parsed as an integer. throw new ColumnParseException("No value provided"); } boolean isNegative = false; for (int pos = start; pos < limit; pos++) { char cur = chars.get(); if (pos == start && cur == '-') { isNegative = true; if (limit - start == 1) { // "-" is not an integer we accept. throw new ColumnParseException("No integer part provided"); } } else if (Character.isDigit(cur)) { byte digitVal = (byte) (cur - '0'); result = result * 10 - digitVal; // TODO: Detect over/underflow and signal exception? } else { throw new ColumnParseException("Invalid character in number"); } } // We built up the value as a negative, to use the larger "half" of the // integer range. If it's not negative, flip it on return. return isNegative ? result : -result; }
From source file:com.autentia.common.util.PasswordUtils.java
private static boolean atLeastOneNumber(String pwd) { final char[] pwdChars = pwd.toCharArray(); for (int i = 0; i < pwdChars.length; i++) { if (Character.isDigit(pwdChars[i])) { return true; }/*from ww w . jav a2 s .c om*/ } return false; }
From source file:boa.BoaMain.java
protected static String pascalCase(final String string) { final StringBuilder pascalized = new StringBuilder(); boolean upper = true; for (final char c : string.toCharArray()) if (Character.isDigit(c) || c == '_') { pascalized.append(c);/*from w w w. java 2 s. co m*/ upper = true; } else if (!Character.isDigit(c) && !Character.isLetter(c)) { upper = true; } else if (Character.isLetter(c)) { pascalized.append(upper ? Character.toUpperCase(c) : c); upper = false; } return pascalized.toString(); }
From source file:forge.deck.CardPool.java
public void add(String cardName, String setCode, final int artIndex, final int amount) { PaperCard cp = StaticData.instance().getCommonCards().getCard(cardName, setCode, artIndex); boolean isCommonCard = cp != null; if (!isCommonCard) { cp = StaticData.instance().getVariantCards().getCard(cardName, setCode); }/*from w ww .jav a 2 s . c o m*/ boolean artIndexExplicitlySet = artIndex > 0 || Character.isDigit(cardName.charAt(cardName.length() - 1)) && cardName.charAt(cardName.length() - 2) == CardDb.NameSetSeparator; int artCount = 1; if (cp != null) { setCode = cp.getEdition(); cardName = cp.getName(); artCount = isCommonCard ? StaticData.instance().getCommonCards().getArtCount(cardName, setCode) : 1; } else { cp = StaticData.instance().getCommonCards().createUnsuportedCard(cardName); } if (artIndexExplicitlySet || artCount <= 1) { // either a specific art index is specified, or there is only one art, so just add the card this.add(cp, amount); } else { // random art index specified, make sure we get different groups of cards with different art int[] artGroups = MyRandom.splitIntoRandomGroups(amount, artCount); for (int i = 1; i <= artGroups.length; i++) { int cnt = artGroups[i - 1]; if (cnt <= 0) continue; PaperCard cp_random = isCommonCard ? StaticData.instance().getCommonCards().getCard(cardName, setCode, i) : StaticData.instance().getVariantCards().getCard(cardName, setCode, i); this.add(cp_random, cnt); } } }
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.VirtualDataSourceValidator.java
public boolean validateSubDsId(String value, String nameField, ValidationErrors errors) { if (!validateNameString(value, nameField, errors)) { return false; }//from www.jav a2 s.c om if (subDsIdInvalidChars.matcher(value).find()) { errors.add(new ValidationErrorImpl(getErrorMessagePrefix() + "error.invalid.chars", null, "Only letters, digits and underscore allowed in subDsId", nameField)); } if (!StringUtils.isEmpty(value)) { char firstChar = value.charAt(0); if (firstChar == '_' || Character.isDigit(firstChar)) { errors.add(new ValidationErrorImpl(getErrorMessagePrefix() + "error.first.letter.required", null, "Should start with letter", nameField)); } } return true; }
From source file:br.com.renatoccosta.regexrenamer.element.FilterElement.java
@Override public String convert(String src) { StringBuilder sb = new StringBuilder(); char[] caracs = src.toCharArray(); switch (mode) { case LETTERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isLetter(c)) { sb.append(c);//from ww w. j av a2s . c o m } } return sb.toString(); case NUMBERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isDigit(c)) { sb.append(c); } } return sb.toString(); case SYMBOLS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (Character.isLetterOrDigit(c) || Character.isSpaceChar(c)) { sb.append(c); } } return sb.toString(); case WHITE_SPACE: return StringUtils.deleteWhitespace(src); } return src; }
From source file:com.baifendian.swordfish.execserver.parameter.placeholder.CalculateUtil.java
/** * ???/* w w w .j av a 2s . c o m*/ * * @param inOrderList * @return ?? */ private static List<String> getPostOrder(List<String> inOrderList) { List<String> result = new ArrayList<>(); Stack<String> stack = new Stack<>(); for (int i = 0; i < inOrderList.size(); i++) { if (Character.isDigit(inOrderList.get(i).charAt(0))) { result.add(inOrderList.get(i)); } else { switch (inOrderList.get(i).charAt(0)) { case '(': stack.push(inOrderList.get(i)); break; case ')': while (!stack.peek().equals("(")) { result.add(stack.pop()); } stack.pop(); break; default: while (!stack.isEmpty() && compare(stack.peek(), inOrderList.get(i))) { result.add(stack.pop()); } stack.push(inOrderList.get(i)); break; } } } while (!stack.isEmpty()) { result.add(stack.pop()); } return result; }