List of usage examples for org.apache.commons.lang StringUtils isNumeric
public static boolean isNumeric(String str)
Checks if the String contains only unicode digits.
From source file:com.github.projectflink.testPlan.KryoTest.java
public static void main(String[] args) throws Exception { // set up the execution environment final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); // get input data DataSet<String> text = env.readTextFile(args[0]); boolean kryoMode = false; if (args[1].equals("kryo")) { kryoMode = true;/*w w w .j a v a2s .co m*/ DataSet<KryoType> ds = text.map(new MapFunction<String, KryoType>() { @Override public KryoType map(String s) throws Exception { KryoType kt = new KryoType(); kt.elements = new ArrayList<Object>(); String[] splits = s.split(" "); for (String split : splits) { if (split == null || split.length() == 0) continue; if (StringUtils.isNumeric(split)) { try { kt.elements.add(Integer.valueOf(split)); } catch (Throwable t) { kt.elements.add(Integer.valueOf(0)); } } else { kt.elements.add(split); } } return kt; } }); DataSet<Tuple2<Object, Integer>> ds1 = ds.rebalance() .map(new MapFunction<KryoType, Tuple2<Object, Integer>>() { @Override public Tuple2<Object, Integer> map(KryoType valueType) throws Exception { return new Tuple2<Object, Integer>(valueType.elements.iterator().next(), valueType.elements.size()); } }); ds1.output(new DiscardingOutputFormat<Tuple2<Object, Integer>>()); } else { DataSet<ValueType> ds = text.map(new MapFunction<String, ValueType>() { @Override public ValueType map(String s) throws Exception { ValueType vt = new ValueType(); vt.elements = new ArrayList<Object>(); String[] splits = s.split(" "); for (String split : splits) { if (split == null || split.length() == 0) continue; if (StringUtils.isNumeric(split)) { try { vt.elements.add(Integer.valueOf(split)); } catch (Throwable t) { vt.elements.add(Integer.valueOf(0)); } } else { vt.elements.add(split); } } return vt; } }); DataSet<Tuple2<Object, Integer>> ds1 = ds.rebalance() .map(new MapFunction<ValueType, Tuple2<Object, Integer>>() { @Override public Tuple2<Object, Integer> map(ValueType valueType) throws Exception { return new Tuple2<Object, Integer>(valueType.elements.iterator().next(), valueType.elements.size()); } }); ds1.output(new DiscardingOutputFormat<Tuple2<Object, Integer>>()); } // execute program env.execute("KryoTest kryoMode=" + kryoMode); }
From source file:com.chigix.autosftp.Application.java
public static void main(String[] args) { Options options = new Options(); options.addOption(Option.builder("P").longOpt("port").hasArg().build()) .addOption(Option.builder("h").longOpt("help").desc("Print this message").build()) .addOption(Option.builder("i").argName("identity_file").hasArg().build()); int port = 22; CommandLine line;//from www. jav a2s . co m try { line = new DefaultParser().parse(options, args); } catch (UnrecognizedOptionException ex) { System.err.println(ex.getMessage()); return; } catch (ParseException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); return; } if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("autosftp /path/to/watch [user@]host2:[file2]", options, true); return; } String givenPort; if (line.hasOption("port") && StringUtils.isNumeric(givenPort = line.getOptionValue("port"))) { port = Integer.valueOf(givenPort); } if (line.getArgs().length < 0) { System.err.println("Please provide a path to watch."); return; } localPath = Paths.get(line.getArgs()[0]); if (line.getArgs().length < 1) { System.err.println("Please provide remote ssh information."); return; } SshAddressParser addressParse; try { addressParse = new SshAddressParser().parse(line.getArgs()[1]); } catch (SshAddressParser.InvalidAddressException ex) { System.err.println(ex.getMessage()); return; } if (addressParse.getDefaultDirectory() != null) { remotePath = Paths.get(addressParse.getDefaultDirectory()); } try { sshSession = new JSch().getSession(addressParse.getUsername(), addressParse.getHost(), port); } catch (JSchException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); return; } try { sshOpen(); } catch (JSchException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); sshClose(); } System.out.println("Remote Default Path: " + remotePath); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { sshClose(); System.out.println("Bye~~~"); } }); try { watchDir(Paths.get(line.getArgs()[0])); } catch (Exception ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.weltraumschaf.registermachine.asm.CharUtils.java
static boolean isNumeric(final char c) { return StringUtils.isNumeric(String.valueOf(c)); }
From source file:com.laex.cg2d.model.util.BooleanUtil.java
/** * To bool.//from w w w . j av a 2 s . co m * * @param value * the value * @return the boolean */ public static Boolean toBool(Object value) { String val = value.toString(); if (StringUtils.isNumeric(val)) { return parseInteger(value); } return Boolean.valueOf(value.toString()); }
From source file:edu.illinois.cs.cogcomp.temporal.normalizer.main.timex2interval.Period.java
public static List<String> normTimexToList(String timex) { String[] list = timex.split("\\-"); int year = 0; int month = 1; int day = 1;//from ww w . j a va 2 s . c o m ArrayList<String> res = new ArrayList<String>(); if (!StringUtils.isNumeric(list[0])) { return null; } String yearStr = list[0]; // This the case where we have century if (yearStr.length() <= 2) { //int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour year = Integer.parseInt(yearStr) * 100; } //decades, 1960s==>196 else if (yearStr.length() == 3) { year = Integer.parseInt(yearStr) * 10; } else if (yearStr.length() == 4) { year = Integer.parseInt(yearStr); } res.add(String.valueOf(year)); if (list.length == 1) { return res; } // either 1994-W12, or 1994-04 res.add(list[1]); return res; }
From source file:com.rackspacecloud.blueflood.utils.DateTimeParser.java
public static DateTime parse(String dateTimeOffsetString) { String stringToParse = dateTimeOffsetString.replace(" ", "").replace(",", "").replace("_", ""); if (StringUtils.isNumeric(stringToParse) && !isLikelyDateTime(stringToParse)) return dateTimeFromTimestamp(stringToParse); DateTime dateTime = tryParseDateTime("HH:mmyyyyMMdd", stringToParse); if (dateTime != null) return dateTime; List<String> splitList = splitDateTimeAndOffset(stringToParse); String offset = splitList.get(1); String dateTimeString = splitList.get(0); DateTimeOffsetParser parser = new DateTimeOffsetParser(dateTimeString, offset); return parser.updateDateTime(new DateTime()); }
From source file:com.aw.swing.mvp.validation.support.PatternRules.java
/** * RM2W6D//from ww w . j a v a2s.c om * * @param pattern * @return */ public static PropertyValidator buildPropertyValidator(String pattern) { // filter requerid PropertyValidator validator = new PropertyValidator(); validator.setRequerid(pattern.startsWith(REQUERID)); int minLength = pattern.indexOf(MINLENGTH); int maxLength = pattern.indexOf(MAXLENGTH); int length = pattern.length(); if (minLength != -1) { if (StringUtils.isNumeric(String.valueOf(pattern.charAt(minLength + 1)))) { StringBuffer min = new StringBuffer(); while (((minLength + 1) < length) && StringUtils.isNumeric(String.valueOf(pattern.charAt(minLength + 1)))) { min.append(pattern.charAt(minLength + 1)); minLength++; } validator.setMinLength(Integer.parseInt(min.toString())); } } if (maxLength != -1) { if (StringUtils.isNumeric(String.valueOf(pattern.charAt(maxLength + 1)))) { StringBuffer max = new StringBuffer(); while (((maxLength + 1) < length) && StringUtils.isNumeric(String.valueOf(pattern.charAt(maxLength + 1)))) { max.append(pattern.charAt(maxLength + 1)); maxLength++; } validator.setMaxLength(Integer.parseInt(max.toString())); } } if (validator.getMaxLength() != -1 && validator.getMaxLength() < validator.getMinLength()) { throw new RuntimeException( "Incorrect asignacion min:" + validator.getMinLength() + " max:" + validator.getMaxLength()); } boolean onlyDigits = pattern.endsWith(DIGITS); boolean onlyLetters = pattern.endsWith(LETTERS); validator.setOnlyDigits(onlyDigits); validator.setOnlyLetters(onlyLetters); return validator; }
From source file:edu.emory.bmi.datacafe.core.DataCafeUtil.java
/** * Wraps the text with double quotes.// w w w .jav a2 s.co m * * @param text the text * @return the wrapped text. */ public static String doublequote(String text) { if (StringUtils.isNumeric(text)) { //checking only for numeric now. todo: all types. return text; } else { return "\"" + text + "\""; } }
From source file:com.jcalvopinam.utils.Utilities.java
/** * If the input parameter is integer, then converts the String input to Integer output else return null * * @param input//from w w w . ja va 2 s . com * @return */ public static Integer isInteger(String input) { Integer output = 0; if (StringUtils.isNumeric(input)) { output = Integer.parseInt(input); } return output; }
From source file:com.zlfun.framework.table.ItemComparator.java
private boolean isNumeric(String var) { if (var == null && var.equals("")) { return false; }/*from www . j a v a 2 s. co m*/ if (var.charAt(0) == '-') { return StringUtils.isNumeric(var.substring(1)); } else { return StringUtils.isNumeric(var); } }