@Test public void testParse2() { System.out.println("parse"); String units = "days since 1970-01-01 0:0:0"; UnitsParser instance = new UnitsParser(); boolean ret = instance.parse(units); assertTrue(ret); System.out.println(instance); }
public boolean parse(String input) { String[] split = input.split(" "); if(split.length != 4) { if(LOGGER.isInfoEnabled()) LOGGER.info("Could not parse '"+input+"': 4 tokens expected"); return false; } String u = split[0]; try { units = Units.valueOf(u.toLowerCase()); secondsMultiplier = units.getMultiplier(); } catch (Exception e) { if(LOGGER.isInfoEnabled()) LOGGER.info("Unknown time unit '"+u+"': " + e.getMessage()); return false; } if(! "since".equals(split[1])) { if(LOGGER.isInfoEnabled()) LOGGER.info("Missing 'since' keyword"); return false; } String datetime = split[2] + " " + split[3]; try { date = INPUTFORMAT.parse(datetime); } catch (ParseException ex) { if(LOGGER.isInfoEnabled()) LOGGER.info("Can't parse datetime '"+datetime+"': " + ex.getMessage()); return false; } return true; }
UnitsParser { public boolean parse(String input) { String[] split = input.split(" "); if(split.length != 4) { if(LOGGER.isInfoEnabled()) LOGGER.info("Could not parse '"+input+"': 4 tokens expected"); return false; } String u = split[0]; try { units = Units.valueOf(u.toLowerCase()); secondsMultiplier = units.getMultiplier(); } catch (Exception e) { if(LOGGER.isInfoEnabled()) LOGGER.info("Unknown time unit '"+u+"': " + e.getMessage()); return false; } if(! "since".equals(split[1])) { if(LOGGER.isInfoEnabled()) LOGGER.info("Missing 'since' keyword"); return false; } String datetime = split[2] + " " + split[3]; try { date = INPUTFORMAT.parse(datetime); } catch (ParseException ex) { if(LOGGER.isInfoEnabled()) LOGGER.info("Can't parse datetime '"+datetime+"': " + ex.getMessage()); return false; } return true; } }
UnitsParser { public boolean parse(String input) { String[] split = input.split(" "); if(split.length != 4) { if(LOGGER.isInfoEnabled()) LOGGER.info("Could not parse '"+input+"': 4 tokens expected"); return false; } String u = split[0]; try { units = Units.valueOf(u.toLowerCase()); secondsMultiplier = units.getMultiplier(); } catch (Exception e) { if(LOGGER.isInfoEnabled()) LOGGER.info("Unknown time unit '"+u+"': " + e.getMessage()); return false; } if(! "since".equals(split[1])) { if(LOGGER.isInfoEnabled()) LOGGER.info("Missing 'since' keyword"); return false; } String datetime = split[2] + " " + split[3]; try { date = INPUTFORMAT.parse(datetime); } catch (ParseException ex) { if(LOGGER.isInfoEnabled()) LOGGER.info("Can't parse datetime '"+datetime+"': " + ex.getMessage()); return false; } return true; }  }
UnitsParser { public boolean parse(String input) { String[] split = input.split(" "); if(split.length != 4) { if(LOGGER.isInfoEnabled()) LOGGER.info("Could not parse '"+input+"': 4 tokens expected"); return false; } String u = split[0]; try { units = Units.valueOf(u.toLowerCase()); secondsMultiplier = units.getMultiplier(); } catch (Exception e) { if(LOGGER.isInfoEnabled()) LOGGER.info("Unknown time unit '"+u+"': " + e.getMessage()); return false; } if(! "since".equals(split[1])) { if(LOGGER.isInfoEnabled()) LOGGER.info("Missing 'since' keyword"); return false; } String datetime = split[2] + " " + split[3]; try { date = INPUTFORMAT.parse(datetime); } catch (ParseException ex) { if(LOGGER.isInfoEnabled()) LOGGER.info("Can't parse datetime '"+datetime+"': " + ex.getMessage()); return false; } return true; }  boolean parse(String input); long getSecondsMultiplier(); Date getDate(); Units getUnits(); @Override String toString(); }
UnitsParser { public boolean parse(String input) { String[] split = input.split(" "); if(split.length != 4) { if(LOGGER.isInfoEnabled()) LOGGER.info("Could not parse '"+input+"': 4 tokens expected"); return false; } String u = split[0]; try { units = Units.valueOf(u.toLowerCase()); secondsMultiplier = units.getMultiplier(); } catch (Exception e) { if(LOGGER.isInfoEnabled()) LOGGER.info("Unknown time unit '"+u+"': " + e.getMessage()); return false; } if(! "since".equals(split[1])) { if(LOGGER.isInfoEnabled()) LOGGER.info("Missing 'since' keyword"); return false; } String datetime = split[2] + " " + split[3]; try { date = INPUTFORMAT.parse(datetime); } catch (ParseException ex) { if(LOGGER.isInfoEnabled()) LOGGER.info("Can't parse datetime '"+datetime+"': " + ex.getMessage()); return false; } return true; }  boolean parse(String input); long getSecondsMultiplier(); Date getDate(); Units getUnits(); @Override String toString();  }