List of usage examples for org.apache.commons.lang3.math NumberUtils isNumber
public static boolean isNumber(final String str)
Checks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the 0x
or 0X
qualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g.
From source file:com.efficio.fieldbook.web.nursery.service.impl.ValidationServiceImpl.java
private boolean isValidValue(MeasurementVariable var, String value) { if (var.getDataType() != null && value != null && !"".equals(value.trim()) && var.getDataType().equalsIgnoreCase(DATA_TYPE_NUMERIC)) { return NumberUtils.isNumber(value.trim()); }// www. j av a2 s. c om return true; }
From source file:com.jabyftw.easiercommands.Util.java
/** * Parse location from given string and world * e.g.: "3.321;32;34" on given world will return Location(world, 3.321, 32.0, 34.0) * * @param world location's world (if not mentioned as first argument) * @param string string to be parsed/*from w w w . j ava 2 s . c o m*/ * @return Bukkit's location based on string (null if failed) */ public static Location parseToLocation(@Nullable World world, @NotNull String string) { String[] strings = string.split(";"); double[] position = new double[3]; // Not enough or too much arguments, return null if (strings.length < 3 || strings.length > 4) return null; // If strings have 4 arguments, world must be the first argument if (strings.length == 4) { world = parseToWorld(strings[0]); System.arraycopy(strings, 1, strings, 0, strings.length - 1); } // World is not defined if (world == null) return null; // Parse arguments as numbers, if a non-number is encountered, return null for (int index = 0; index < strings.length; index++) { if (!NumberUtils.isNumber(strings[index])) return null; else position[index] = Double.parseDouble(strings[index]); } // Return location return new Location(world, position[0], position[1], position[2]); }
From source file:gov.nih.nci.caintegrator.domain.application.SegmentDataResultValue.java
/** * @param segmentDataResultValue to compare * @return the comparator code// ww w.ja va 2 s . c o m */ public int compareTo(SegmentDataResultValue segmentDataResultValue) { int i = 0; if (NumberUtils.isNumber(chromosomalLocation.getChromosome())) { i = Ints.compare(NumberUtils.toInt(chromosomalLocation.getChromosome()), NumberUtils.toInt(segmentDataResultValue.getChromosomalLocation().getChromosome())); } else { i = chromosomalLocation.getChromosome() .compareTo(segmentDataResultValue.getChromosomalLocation().getChromosome()); } if (i == 0) { i = Ints.compare(chromosomalLocation.getStartPosition(), segmentDataResultValue.getChromosomalLocation().getStartPosition()); } if (i == 0) { i = Ints.compare(chromosomalLocation.getEndPosition(), segmentDataResultValue.getChromosomalLocation().getEndPosition()); } return i; }
From source file:com.netsteadfast.greenstep.struts2.dispatcher.CustomJFreeChartResult.java
@Override public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { Object newWidth = ActionContext.getContext().getValueStack().findValue("width"); Object newHeight = ActionContext.getContext().getValueStack().findValue("height"); if (NumberUtils.isNumber(String.valueOf(newWidth)) && NumberUtils.isNumber(String.valueOf(newHeight))) { int w = NumberUtils.toInt(String.valueOf(newWidth)); int h = NumberUtils.toInt(String.valueOf(newHeight)); if (w > MAX_WIDTH) { w = MAX_WIDTH;/*w ww. j ava2s.c o m*/ } if (h > MAX_HEIGHT) { h = MAX_HEIGHT; } if (w < MIN_WIDTH) { w = MIN_WIDTH; } if (h < MIN_HEIGHT) { h = MIN_HEIGHT; } super.setWidth(String.valueOf(w)); super.setHeight(String.valueOf(h)); logger.info("reset chart width=" + w + " , heigh=" + h); } super.doExecute(finalLocation, invocation); }
From source file:coding.cowboys.util.ResortWrapper.java
public Double getTotalPrice() { if (!NumberUtils.isNumber(totalPrice)) { System.out.println("We had a problem here need to log it: " + toString()); return 100000000d; }/*from w w w . j av a 2 s . c o m*/ return Double.valueOf(totalPrice); }
From source file:com.kegare.caveworld.util.CaveConfiguration.java
@Override public int compare(String o1, String o2) { int result = CaveUtils.compareWithNull(o1, o2); if (result == 0 && o1 != null && o2 != null) { boolean flag1 = NumberUtils.isNumber(o1); boolean flag2 = NumberUtils.isNumber(o2); result = Boolean.compare(flag1, flag2); if (result == 0) { if (flag1 && flag2) { result = Integer.compare(NumberUtils.toInt(o1), NumberUtils.toInt(o2)); } else if (!flag1 && !flag2) { result = o1.compareTo(o2); }// www.j ava 2s.c o m } } return result; }
From source file:com.twosigma.beaker.fileloader.CsvPlotReader.java
private Object convertToNumber(Object value) { if (value instanceof String && NumberUtils.isNumber((String) value)) { return Float.parseFloat((String) value); } else {//from w w w . ja v a 2s . com return value; } }
From source file:com.money.manager.ex.settings.SyncPreferences.java
public int getSyncInterval() { int defaultSchedule = 30; // time in minutes String setSchedule = get(R.string.pref_sync_interval, Integer.toString(defaultSchedule)); if (!NumberUtils.isNumber(setSchedule)) return defaultSchedule; return Integer.parseInt(setSchedule); }
From source file:comparetopics.CompareTwoGroupTopics.java
public static void compareTwoGroups(String groups1, String groups2, int lineNr1, int lineNr2) { String[] topics1 = groups1.split("\t| "); String[] topics2 = groups2.split("\t| "); // for (String w1 : topics1) { // if (!NumberUtils.isNumber(w1)) { // System.out.println(w1); // } // }/*from w w w. j a v a 2 s . co m*/ // // System.out.println(); // // for (String w2 : topics2) { // if (!NumberUtils.isNumber(w2)) { // System.out.println(w2); // } // } int index = 0; for (String word1 : topics1) { if (!NumberUtils.isNumber(word1)) { for (String word2 : topics2) { if (!NumberUtils.isNumber(word2)) { if (word1.equals(word2)) { ++index; break; } } } } } if (index >= 4) System.out.println( "File1" + lineNr1 + "File2" + lineNr2 + "" + index + "??"); }
From source file:com.mirth.connect.donkey.util.purge.PurgeUtil.java
/** * If the value is numeric, returns original value. If the value is empty, returns an empty * string. Otherwise if the value uses Velocity replacement or is invalid, returns null. For * fields where the value must be numeric but we allow Strings so that Velocity can be used. *///from w ww .j a va 2 s .c o m public static String getNumericValue(String data) { if (data == null) { return null; } String value = null; if (NumberUtils.isNumber(data)) { value = data; } else if (data.isEmpty()) { value = ""; } return value; }