List of usage examples for org.apache.commons.lang3 StringUtils isNumeric
public static boolean isNumeric(final CharSequence cs)
Checks if the CharSequence contains only Unicode digits.
From source file:nl.kpmg.lcm.server.integration.atlas.AtlasMetadataTransformer.java
private void setSize(ColumnType columnType, String size, ColumnDescription description) throws TransformationException { try {// w ww.ja va 2 s. c om if (columnType.equals(ColumnType.DECIMAL)) { String[] sizeArr = StringUtils.split(size, ","); if (sizeArr.length != 2) { throw new TransformationException("Illegal Desimal size structure: " + size); } size = sizeArr[0]; if (!StringUtils.isNumeric(sizeArr[1])) { throw new TransformationException("Presicion must be numeric: " + sizeArr[1]); } description.setPrecision(Integer.parseInt(sizeArr[1])); } if (!StringUtils.isNumeric(size)) { throw new TransformationException("Size must be numeric: " + size); } description.setSize(Integer.parseInt(size)); } catch (NumberFormatException nfe) { throw new TransformationException("Unable to parse size value: " + nfe.getMessage()); } }
From source file:org.ahp.commons.validator.ValidatorUtil.java
public static boolean isNumeric(String pInputString) { return StringUtils.isNumeric(pInputString); }
From source file:org.aliuge.crawler.extractor.selector.action.string.StringSplitAction.java
/** * //from w w w.j a va 2 s. c om * @param split * @param index */ public StringSplitAction(String split, String index) { if (StringUtils.isNotBlank(split)) { this.split = split; } else { this.split = ","; } if (StringUtils.isNotBlank(index)) { String is[] = index.split(","); for (String i : is) { if (StringUtils.isNumeric(i)) { set.add(Integer.parseInt(i)); } } } }
From source file:org.aliuge.crawler.extractor.selector.action.string.StringSplitAction.java
public StringSplitAction(String split, String index, String newsplit) { if (StringUtils.isNotBlank(split)) { this.split = split; } else {/*from w w w . jav a 2 s .com*/ this.split = ","; } if (StringUtils.isNotBlank(index)) { String is[] = index.split(","); for (String i : is) { if (StringUtils.isNumeric(i)) { set.add(Integer.parseInt(i)); } } if (set.size() > 0) { if (StringUtils.isNotBlank(newsplit)) this.newsplit = newsplit; } } }
From source file:org.aliuge.crawler.extractor.selector.action.string.StringSubAction.java
/** * "4,4"??4.<br>//from www .j a va 2s .c o m * "4"4?? * @param subExpression */ public StringSubAction(String subExpression) { if (StringUtils.isNotBlank(subExpression)) { String[] ss = StringUtils.split(subExpression, ","); if (ss.length == 1) { if (StringUtils.isNumeric(ss[0])) { this.pos = Integer.parseInt(ss[0]); } else { this.spos = ss[0]; } } else if (ss.length == 2) { if (StringUtils.isNumeric(ss[0])) { this.pos = Integer.parseInt(ss[0]); } else { this.spos = ss[0]; } this.lenth = Integer.parseInt(ss[1]); } } }
From source file:org.apache.calcite.adapter.druid.DruidDateTimeUtils.java
private static Comparable toTimestamp(Object literal) { if (literal instanceof Timestamp) { return (Timestamp) literal; }/*from w w w . j a va2s . c om*/ if (literal instanceof Date) { return new Timestamp(((Date) literal).getTime()); } if (literal instanceof Calendar) { return new Timestamp(((Calendar) literal).getTime().getTime()); } if (literal instanceof Number) { return new Timestamp(((Number) literal).longValue()); } if (literal instanceof String) { String string = (String) literal; if (StringUtils.isNumeric(string)) { return new Timestamp(Long.valueOf(string)); } try { return Timestamp.valueOf(string); } catch (NumberFormatException e) { // ignore } } return null; }
From source file:org.apache.cassandra.cache.CachingOptions.java
private static void validateCacheConfig(Map<String, String> cacheConfig) throws ConfigurationException { for (Map.Entry<String, String> entry : cacheConfig.entrySet()) { String value = entry.getValue().toUpperCase(); if (entry.getKey().equals("keys")) { if (!(value.equals("ALL") || value.equals("NONE"))) { throw new ConfigurationException( "'keys' can only have values 'ALL' or 'NONE', but was '" + value + "'"); }//from w w w. j a va2 s .c o m } else if (entry.getKey().equals("rows_per_partition")) { if (!(value.equals("ALL") || value.equals("NONE") || StringUtils.isNumeric(value))) { throw new ConfigurationException( "'rows_per_partition' can only have values 'ALL', 'NONE' or be numeric, but was '" + value + "'."); } } else throw new ConfigurationException( "Only supported CachingOptions parameters are 'keys' and 'rows_per_partition', but was '" + entry.getKey() + "'"); } }
From source file:org.apache.cassandra.schema.CachingParams.java
private static int rowsPerPartitionFromString(String value) { if (value.equalsIgnoreCase(ALL)) return Integer.MAX_VALUE; if (value.equalsIgnoreCase(NONE)) return 0; if (StringUtils.isNumeric(value)) return Integer.parseInt(value); throw new ConfigurationException(format( "Invalid value '%s' for caching sub-option '%s':" + " only '%s', '%s', and integer values are allowed", value, Option.ROWS_PER_PARTITION, ALL, NONE)); }
From source file:org.apache.cassandra.schema.CompactionParams.java
public void validate() { try {// www. java 2 s . c om Map<?, ?> unknownOptions = (Map) klass.getMethod("validateOptions", Map.class).invoke(null, options); if (!unknownOptions.isEmpty()) { throw new ConfigurationException(format("Properties specified %s are not understood by %s", unknownOptions.keySet(), klass.getSimpleName())); } } catch (NoSuchMethodException e) { logger.warn("Compaction strategy {} does not have a static validateOptions method. Validation ignored", klass.getName()); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof ConfigurationException) throw (ConfigurationException) e.getTargetException(); Throwable cause = e.getCause() == null ? e : e.getCause(); throw new ConfigurationException(format("%s.validateOptions() threw an error: %s %s", klass.getName(), cause.getClass().getName(), cause.getMessage()), e); } catch (IllegalAccessException e) { throw new ConfigurationException("Cannot access method validateOptions in " + klass.getName(), e); } String minThreshold = options.get(Option.MIN_THRESHOLD.toString()); if (minThreshold != null && !StringUtils.isNumeric(minThreshold)) { throw new ConfigurationException( format("Invalid value %s for '%s' compaction sub-option - must be an integer", minThreshold, Option.MIN_THRESHOLD)); } String maxThreshold = options.get(Option.MAX_THRESHOLD.toString()); if (maxThreshold != null && !StringUtils.isNumeric(maxThreshold)) { throw new ConfigurationException( format("Invalid value %s for '%s' compaction sub-option - must be an integer", maxThreshold, Option.MAX_THRESHOLD)); } if (minCompactionThreshold() <= 0 || maxCompactionThreshold() <= 0) { throw new ConfigurationException( "Disabling compaction by setting compaction thresholds to 0 has been removed," + " set the compaction option 'enabled' to false instead."); } if (minCompactionThreshold() <= 1) { throw new ConfigurationException( format("Min compaction threshold cannot be less than 2 (got %d)", minCompactionThreshold())); } if (minCompactionThreshold() > maxCompactionThreshold()) { throw new ConfigurationException(format( "Min compaction threshold (got %d) cannot be greater than max compaction threshold (got %d)", minCompactionThreshold(), maxCompactionThreshold())); } }
From source file:org.apache.flink.api.java.typeutils.TupleTypeInfoBase.java
@Override public void getKey(String fieldExpression, int offset, List<FlatFieldDescriptor> result) { // handle 'select all' if (fieldExpression.equals(ExpressionKeys.SELECT_ALL_CHAR) || fieldExpression.equals(ExpressionKeys.SELECT_ALL_CHAR_SCALA)) { int keyPosition = 0; for (TypeInformation<?> type : types) { if (type instanceof AtomicType) { result.add(new FlatFieldDescriptor(offset + keyPosition, type)); } else if (type instanceof CompositeType) { CompositeType<?> cType = (CompositeType<?>) type; cType.getKey(String.valueOf(ExpressionKeys.SELECT_ALL_CHAR), offset + keyPosition, result); keyPosition += cType.getTotalFields() - 1; } else { throw new RuntimeException("Unexpected key type: " + type); }/* w ww .j a v a 2 s . c o m*/ keyPosition++; } return; } // check input if (fieldExpression.length() < 2) { throw new IllegalArgumentException( "The field expression '" + fieldExpression + "' is incorrect. The length must be at least 2"); } if (fieldExpression.charAt(0) != 'f') { throw new IllegalArgumentException("The field expression '" + fieldExpression + "' is incorrect for a Tuple type. It has to start with an 'f'"); } // get first component of nested expression int dotPos = fieldExpression.indexOf('.'); String nestedSplitFirst = fieldExpression; if (dotPos != -1) { Preconditions.checkArgument(dotPos != fieldExpression.length() - 1, "The field expression can never end with a dot."); nestedSplitFirst = fieldExpression.substring(0, dotPos); } String fieldNumStr = nestedSplitFirst.substring(1, nestedSplitFirst.length()); if (!StringUtils.isNumeric(fieldNumStr)) { throw new IllegalArgumentException("The field expression '" + fieldExpression + "' is incorrect. Field number '" + fieldNumStr + " is not numeric"); } int pos = -1; try { pos = Integer.valueOf(fieldNumStr); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("The field expression '" + fieldExpression + "' is incorrect. Field number '" + fieldNumStr + " is not numeric", nfe); } if (pos < 0) { throw new IllegalArgumentException("Negative position is not possible"); } // pass down the remainder (after the dot) of the fieldExpression to the type at that position. if (dotPos != -1) { // we need to go deeper String rem = fieldExpression.substring(dotPos + 1); if (!(types[pos] instanceof CompositeType<?>)) { throw new RuntimeException("Element at position " + pos + " is not a composite type. There are no nested types to select"); } CompositeType<?> cType = (CompositeType<?>) types[pos]; // count nested fields before "pos" for (int i = 0; i < pos; i++) { offset += types[i].getTotalFields(); } cType.getKey(rem, offset, result); return; } if (pos >= types.length) { throw new IllegalArgumentException("The specified tuple position does not exist"); } // count nested fields before "pos". for (int i = 0; i < pos; i++) { offset += types[i].getTotalFields() - 1; // this adds only something to offset if its a composite type. } if (types[pos] instanceof CompositeType) { throw new IllegalArgumentException("The specified field '" + fieldExpression + "' is refering to a composite type.\n" + "Either select all elements in this type with the '" + ExpressionKeys.SELECT_ALL_CHAR + "' operator or specify a field in the sub-type"); } result.add(new FlatFieldDescriptor(offset + pos, types[pos])); }