/** * Returns <jk>true</jk> if the specified string needs to be quoted per UON notation. * * <p> * For example, strings that start with '(' or '@' or look like boolean or numeric values need to be quoted. * * @param s The string to test. * @return <jk>true</jk> if the specified string needs to be quoted per UON notation. */ public static final boolean needsQuotes(String s) { char c0 = s.isEmpty() ? 0 : s.charAt(0); return ( s.isEmpty() || c0 == '@' || c0 == '(' || needsQuoteChars.contains(s) || ( maybeNeedsQuotesFirstChar.contains(c0) && ( "true".equals(s) || "false".equals(s) || "null".equals(s) || isNumeric(s) ) ) ); } }
/** * Returns <jk>true</jk> if the specified string needs to be quoted per UON notation. * * <p> * For example, strings that start with '(' or '@' or look like boolean or numeric values need to be quoted. * * @param s The string to test. * @return <jk>true</jk> if the specified string needs to be quoted per UON notation. */ public static final boolean needsQuotes(String s) { char c0 = s.isEmpty() ? 0 : s.charAt(0); return ( s.isEmpty() || c0 == '@' || c0 == '(' || needsQuoteChars.contains(s) || ( maybeNeedsQuotesFirstChar.contains(c0) && ( "true".equals(s) || "false".equals(s) || "null".equals(s) || isNumeric(s) ) ) ); } }
/** * Returns <jk>true</jk> if the specified string needs to be quoted per UON notation. * * <p> * For example, strings that start with '(' or '@' or look like boolean or numeric values need to be quoted. * * @param s The string to test. * @return <jk>true</jk> if the specified string needs to be quoted per UON notation. */ public static final boolean needsQuotes(String s) { char c0 = s.isEmpty() ? 0 : s.charAt(0); return ( s.isEmpty() || c0 == '@' || c0 == '(' || needsQuoteChars.contains(s) || ( maybeNeedsQuotesFirstChar.contains(c0) && ( "true".equals(s) || "false".equals(s) || "null".equals(s) || isNumeric(s) ) ) ); } }
@Override /* MutableProperty */ synchronized void add(String arg, Object o) { if (arg != null && ! StringUtils.isNumeric(arg)) throw new ConfigException("Invalid argument ''{0}'' on add command for property ''{1}'' ({2})", arg, name, type); int index = arg == null ? 0 : Integer.parseInt(arg); if (index < 0) index = 0; else if (index > list.size()) index = list.size(); try { List<Object> l = normalize(type.converter, o); list.removeAll(l); list.addAll(index, l); } catch (Exception e) { throw new ConfigException(e, "Cannot add value {0} ({1}) to property ''{2}'' ({3}).", string(o), className(o), name, type); } }
@Override /* MutableProperty */ synchronized void add(String arg, Object o) { if (arg != null && ! StringUtils.isNumeric(arg)) throw new ConfigException("Invalid argument ''{0}'' on add command for property ''{1}'' ({2})", arg, name, type); int index = arg == null ? 0 : Integer.parseInt(arg); if (index < 0) index = 0; else if (index > list.size()) index = list.size(); try { List<Object> l = normalize(type.converter, o); list.removeAll(l); list.addAll(index, l); } catch (Exception e) { throw new ConfigException(e, "Cannot add value {0} ({1}) to property ''{2}'' ({3}).", string(o), className(o), name, type); } }
@Override /* MutableProperty */ synchronized void add(String arg, Object o) { if (arg != null && ! StringUtils.isNumeric(arg)) throw new ConfigException("Invalid argument ''{0}'' on add command for property ''{1}'' ({2})", arg, name, type); int index = arg == null ? 0 : Integer.parseInt(arg); if (index < 0) index = 0; else if (index > list.size()) index = list.size(); try { List<Object> l = normalize(type.converter, o); list.removeAll(l); list.addAll(index, l); } catch (Exception e) { throw new ConfigException(e, "Cannot add value {0} ({1}) to property ''{2}'' ({3}).", string(o), className(o), name, type); } }
protected void collectInstagramDataForUser(String userId) throws Exception { UserInfoResponse userInfoResponse = null; if( !StringUtils.isNumeric(userId) ) { userId = swapUsernameForId(userId); } try { userInfoResponse = getNextInstagramClient().lookupUser(userId); } catch (Exception ex) { LOGGER.error("Expection while polling instagram : {}", ex); } if ( userInfoResponse != null && userInfoResponse.getData() != null) { List<UserInfo> data = new LinkedList<>(); data.add(userInfoResponse.getData()); super.queueData(data, userId); } }
/** * Returns <jk>true</jk> if the specified string is valid JSON. * * <p> * Leading and trailing spaces are ignored. * <br>Leading and trailing comments are not allowed. * * @param s The string to test. * @return <jk>true</jk> if the specified string is valid JSON. */ public static boolean isJson(String s) { if (s == null) return false; char c1 = StringUtils.firstNonWhitespaceChar(s), c2 = StringUtils.lastNonWhitespaceChar(s); if (c1 == '{' && c2 == '}' || c1 == '[' && c2 == ']' || c1 == '\'' && c2 == '\'') return true; if (StringUtils.isOneOf(s, "true","false","null")) return true; if (StringUtils.isNumeric(s)) return true; return false; }
/** * Returns <jk>true</jk> if the specified string is valid JSON. * * <p> * Leading and trailing spaces are ignored. * <br>Leading and trailing comments are not allowed. * * @param s The string to test. * @return <jk>true</jk> if the specified string is valid JSON. */ public static boolean isJson(String s) { if (s == null) return false; char c1 = StringUtils.firstNonWhitespaceChar(s), c2 = StringUtils.lastNonWhitespaceChar(s); if (c1 == '{' && c2 == '}' || c1 == '[' && c2 == ']' || c1 == '\'' && c2 == '\'') return true; if (StringUtils.isOneOf(s, "true","false","null")) return true; if (StringUtils.isNumeric(s)) return true; return false; }
/** * Returns <jk>true</jk> if the specified string is valid JSON. * * <p> * Leading and trailing spaces are ignored. * <br>Leading and trailing comments are not allowed. * * @param s The string to test. * @return <jk>true</jk> if the specified string is valid JSON. */ public static boolean isJson(String s) { if (s == null) return false; char c1 = StringUtils.firstNonWhitespaceChar(s), c2 = StringUtils.lastNonWhitespaceChar(s); if (c1 == '{' && c2 == '}' || c1 == '[' && c2 == ']' || c1 == '\'' && c2 == '\'') return true; if (StringUtils.isOneOf(s, "true","false","null")) return true; if (StringUtils.isNumeric(s)) return true; return false; }
private static String getName(Method m, int i, UrlPathPattern pathPattern) { for (Path h : getAnnotations(Path.class, m, i)) { if (! h.name().isEmpty()) return h.name(); if (! h.value().isEmpty()) return h.value(); } if (pathPattern != null) { int idx = 0; for (int j = 0; j < i; j++) if (getAnnotation(Path.class, m, i) != null) idx++; String[] vars = pathPattern.getVars(); if (vars.length <= idx) throw new InternalServerError("Number of attribute parameters in method ''{0}'' exceeds the number of URL pattern variables.", m); // Check for {#} variables. String idxs = String.valueOf(idx); for (int j = 0; j < vars.length; j++) if (StringUtils.isNumeric(vars[j]) && vars[j].equals(idxs)) return vars[j]; return pathPattern.getVars()[idx]; } throw new InternalServerError("@Path used without name or value on method ''{0}'' parameter ''{1}''.", m, i); }
private static String getName(Method m, int i, UrlPathPattern pathPattern) { for (Path h : getAnnotations(Path.class, m, i)) { if (! h.name().isEmpty()) return h.name(); if (! h.value().isEmpty()) return h.value(); } if (pathPattern != null) { int idx = 0; for (int j = 0; j < i; j++) if (getAnnotation(Path.class, m, i) != null) idx++; String[] vars = pathPattern.getVars(); if (vars.length <= idx) throw new InternalServerError("Number of attribute parameters in method ''{0}'' exceeds the number of URL pattern variables.", m); // Check for {#} variables. String idxs = String.valueOf(idx); for (int j = 0; j < vars.length; j++) if (StringUtils.isNumeric(vars[j]) && vars[j].equals(idxs)) return vars[j]; return pathPattern.getVars()[idx]; } throw new InternalServerError("@Path used without name or value on method ''{0}'' parameter ''{1}''.", m, i); }
private static String getName(Method m, int i, UrlPathPattern pathPattern) { for (Path h : getAnnotations(Path.class, m, i)) { if (! h.name().isEmpty()) return h.name(); if (! h.value().isEmpty()) return h.value(); } if (pathPattern != null) { int idx = 0; for (int j = 0; j < i; j++) if (getAnnotation(Path.class, m, i) != null) idx++; String[] vars = pathPattern.getVars(); if (vars.length <= idx) throw new InternalServerError("Number of attribute parameters in method ''{0}'' exceeds the number of URL pattern variables.", m); // Check for {#} variables. String idxs = String.valueOf(idx); for (int j = 0; j < vars.length; j++) if (StringUtils.isNumeric(vars[j]) && vars[j].equals(idxs)) return vars[j]; return pathPattern.getVars()[idx]; } throw new InternalServerError("@Path used without name or value on method ''{0}'' parameter ''{1}''.", m, i); }
assertTrue(isNumeric("123")); assertEquals(123, parseNumber("123", null)); assertEquals(123, parseNumber("123", Integer.class)); assertTrue(isNumeric("0123")); assertEquals(0123, parseNumber("0123", null)); assertTrue(isNumeric("-0123")); assertEquals(-0123, parseNumber("-0123", null)); assertTrue(isNumeric("0x123")); assertEquals(0x123, parseNumber("0x123", null)); assertTrue(isNumeric("-0x123")); assertEquals(-0x123, parseNumber("-0x123", null)); assertTrue(isNumeric("0X123")); assertEquals(0X123, parseNumber("0X123", null)); assertTrue(isNumeric("-0X123")); assertEquals(-0X123, parseNumber("-0X123", null)); assertTrue(isNumeric("#123")); assertEquals(0x123, parseNumber("#123", null)); assertTrue(isNumeric("-#123")); assertEquals(-0x123, parseNumber("-#123", null)); assertFalse(isNumeric("x123"));
assertFalse(isNumeric(null)); assertFalse(isNumeric("")); assertFalse(isNumeric("x")); assertTrue(isNumeric(s)); assertTrue(parseNumber(s, null) instanceof Integer); assertEquals(-2147483648, parseNumber(s, null)); assertTrue(isNumeric(s)); assertTrue(parseNumber(s, null) instanceof Integer); assertEquals(2147483647, parseNumber(s, null)); assertTrue(isNumeric(s)); assertTrue(parseNumber(s, null) instanceof Long); assertEquals(-2147483649L, parseNumber(s, null)); assertTrue(isNumeric(s)); assertTrue(parseNumber(s, null) instanceof Long); assertEquals(2147483648L, parseNumber(s, null)); assertTrue(isNumeric(s)); assertTrue(parseNumber(s, null) instanceof Long); assertEquals(-9223372036854775808L, parseNumber(s, null)); assertTrue(isNumeric(s)); assertTrue(parseNumber(s, null) instanceof Long); assertEquals(9223372036854775807L, parseNumber(s, null)); assertTrue(isNumeric(s));
o = Boolean.valueOf(s); else if (! "null".equals(s)) { if (isNumeric(s)) o = StringUtils.parseNumber(s, Number.class); else
o = Boolean.valueOf(s); else if (! "null".equals(s)) { if (isNumeric(s)) o = StringUtils.parseNumber(s, Number.class); else
o = Boolean.valueOf(s); else if (! "null".equals(s)) { if (isNumeric(s)) o = StringUtils.parseNumber(s, Number.class); else