List of usage examples for org.apache.commons.lang.time DateUtils add
private static Date add(Date date, int calendarField, int amount)
From source file:com.clican.pluto.dataprocess.dpl.function.impl.AddDate.java
public Object calculate(Map<String, Object> row) throws CalculationException, PrefixAndSuffixException { Date d = date.getValue(row);//w w w .ja va2 s .co m return DateUtils.add(d, field, add); }
From source file:com.usefullc.platform.common.cache.memcached.MemCacheServiceImpl.java
@Override @SuppressWarnings("deprecation") public void set(String key, Object value, DateUnitEnum dateUnit, Integer expireAmount) { Date d = new Date(); d = DateUtils.add(d, dateUnit.getNum(), expireAmount); String newKey = StrUtils.join(system, key); mcc.set(newKey, value, d);//from w ww . jav a 2s .c o m }
From source file:com.clican.pluto.dataprocess.engine.processes.TimerProcesssorTestCase.java
public void test() throws Exception { taskScheduler.start();// w w w.j ava 2 s . co m TimerProcessor p = new TimerProcessor(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); Date start = DateUtils.add(new Date(), Calendar.SECOND, 3); Date end = DateUtils.add(start, Calendar.SECOND, 3); p.setStartTime(sdf.format(start)); p.setEndTime(sdf.format(end)); p.setCronExpression("* * * * * ?"); p.setConcurrent(true); p.setTaskScheduler(taskScheduler); p.setDataProcessTransaction(dataProcessTransaction); List<DataProcessor> timerProcessors = new ArrayList<DataProcessor>(); final DataProcessor dp = context.mock(DataProcessor.class); timerProcessors.add(dp); p.setTimerProcessors(timerProcessors); final ProcessorContext ctx = new ProcessorContextImpl(); context.checking(new Expectations() { { atLeast(2).of(dp).beforeProcess(ctx); atLeast(2).of(dp).process(ctx); atLeast(2).of(dp).afterProcess(ctx); } }); p.process(ctx); taskScheduler.shutdown(); }
From source file:com.usefullc.platform.common.cache.memcached.MemCacheServiceImpl.java
/** * ?//from w w w. j a v a 2s . co m * * @param key * @param value * @param dateUnit * @param expireAmount */ @Override @SuppressWarnings("deprecation") public void setGlobal(String key, Object value, DateUnitEnum dateUnit, Integer expireAmount) { Date d = new Date(); d = DateUtils.add(d, dateUnit.getNum(), expireAmount); mcc.set(key, value, d); }
From source file:com.clican.pluto.dataprocess.engine.processes.ForProcessorTestCase.java
public void test3() throws Exception { ForProcessor p = new ForProcessor(); p.setIteratorProcessors(this.getIteratorProcessors()); p.setStart("start+1day"); p.setEnd("end+1day"); p.setStep("1day"); ProcessorContext ctx = new ProcessorContextImpl(); ctx.setAttribute("start", new Date()); ctx.setAttribute("end", DateUtils.add(new Date(), Calendar.DAY_OF_MONTH, 10)); p.process(ctx);/*from w w w . ja v a 2 s . c om*/ }
From source file:com.clican.pluto.dataprocess.engine.processes.ForProcessorTestCase.java
public void test4() throws Exception { ForProcessor p = new ForProcessor(); final DataProcessTransaction t = context.mock(DataProcessTransaction.class); p.setDataProcessTransaction(t);/* w w w . j a va 2s .c o m*/ p.setIteratorProcessors(this.getIteratorProcessors()); p.setStart("start-1month"); p.setEnd("end-1month"); p.setStep("1day"); p.setStepCommit(true); final ProcessorContext ctx = new ProcessorContextImpl(); ctx.setAttribute("start", new Date()); ctx.setAttribute("end", DateUtils.add(new Date(), Calendar.DAY_OF_MONTH, 10)); context.checking(new Expectations() { { this.allowing(t).doInCommit((DataProcessor) with(anything()), with(same(ctx))); } }); p.process(ctx); }
From source file:com.usefullc.platform.common.cache.ehcache.EhCacheServiceImpl.java
/** * // ww w . j a v a 2s .com * * @param key * @param value * @param dateUnit * @param expireAmount * @return */ private Element createExpireE(String key, Object value, DateUnitEnum dateUnit, Integer expireAmount) { Element element = new Element(key, value); Date startTime = com.usefullc.platform.common.utils.DateUtils.getNow(); Date endTime = DateUtils.add(startTime, dateUnit.getNum(), expireAmount); Long milliseconds = com.usefullc.platform.common.utils.DateUtils.getCompareAmountMilliseconds(startTime, endTime); int seconds = Long.valueOf(milliseconds / 1000).intValue(); element.setTimeToIdle(seconds); element.setTimeToLive(seconds); return element; }
From source file:com.clican.pluto.dataprocess.engine.processes.ForProcessor.java
public void process(ProcessorContext context) throws DataProcessException { try {/*from w ww . j a va2s . c o m*/ Object startObj = null; Object endObj = null; String startChange = null; String endChange = null; if (StringUtils.isNotEmpty(start)) { if (start.contains("+")) { startObj = PropertyUtils.getNestedProperty(context.getMap(), start.split("\\+")[0].trim()); startChange = start.split("\\+")[1].trim(); } else if (start.contains("-")) { startObj = PropertyUtils.getNestedProperty(context.getMap(), start.split("\\-")[0].trim()); startChange = "-" + start.split("\\-")[1].trim(); } else { startObj = PropertyUtils.getNestedProperty(context.getMap(), start); if (startObj == null) { startObj = start; } } } if (StringUtils.isNotEmpty(end)) { if (end.contains("+")) { endObj = PropertyUtils.getNestedProperty(context.getMap(), end.split("\\+")[0].trim()); endChange = end.split("\\+")[1].trim(); } else if (end.contains("-")) { endObj = PropertyUtils.getNestedProperty(context.getMap(), end.split("\\-")[0].trim()); endChange = "-" + end.split("\\-")[1].trim(); } else { endObj = PropertyUtils.getNestedProperty(context.getMap(), end); if (endObj == null) { endObj = end; } } } if (startObj != null && endObj != null && NumberUtils.isNumber(startObj.toString()) && NumberUtils.isNumber(endObj.toString()) && NumberUtils.isNumber(step)) { int s = Integer.parseInt(startObj.toString()); if (startChange != null) { s = s + Integer.parseInt(startChange); } int e = Integer.parseInt(endObj.toString()); if (endChange != null) { e = e + Integer.parseInt(endChange); } int p = Integer.parseInt(step); for (int i = s; i < e; i = i + p) { if (log.isDebugEnabled()) { log.debug("ProcessorGroup[" + context.getProcessorGroupName() + "],?[" + i + "/" + e + "]" + elementName + "=" + i); } context.setAttribute(elementName, i); for (DataProcessor iteratorProcessor : iteratorProcessors) { if (stepCommit) { dataProcessTransaction.doInCommit(iteratorProcessor, context); } else { doWithoutCommit(iteratorProcessor, context); } } } } else if (startObj instanceof Date && (endObj instanceof Date || endObj == null)) { if (startChange != null) { startObj = DateUtils.add((Date) startObj, this.getField(startChange), this.getChange(startChange)); } int p = Integer.parseInt(step.replaceAll("day", "").replaceAll("month", "").replaceAll("year", "")); int field = -1; if (step.contains("day")) { field = Calendar.DAY_OF_MONTH; } else if (step.contains("month")) { field = Calendar.MONTH; } else if (step.contains("year")) { field = Calendar.YEAR; } else { throw new DataProcessException("?for"); } if (endObj == null) { endObj = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); } else if (endChange != null) { endObj = DateUtils.add((Date) endObj, this.getField(endChange), this.getChange(endChange)); } for (Date i = (Date) startObj; i.compareTo((Date) endObj) < 0; i = DateUtils.add(i, field, p)) { // 1990041519910414?, // ?truncate,???? i = DateUtils.truncate(i, field); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); ProcessorContext subContext; if (this.isCloneContext()) { subContext = context.getCloneContext(); } else { subContext = context; } if (log.isDebugEnabled()) { log.debug("ProcessorGroup[" + context.getProcessorGroupName() + "],?[" + sdf.format(i) + "/" + sdf.format((Date) endObj) + "]" + elementName + "=" + sdf.format(i)); } subContext.setAttribute(elementName, i); for (DataProcessor iteratorProcessor : iteratorProcessors) { if (stepCommit) { dataProcessTransaction.doInCommit(iteratorProcessor, subContext); } else { doWithoutCommit(iteratorProcessor, subContext); } } if (this.propagations != null && this.propagations.size() > 0) { for (String propagation : propagations) { context.setAttribute(propagation, subContext.getAttribute(propagation)); } } } } else { throw new DataProcessException("?for"); } } catch (DataProcessException e) { throw e; } catch (Exception e) { throw new DataProcessException(e); } }
From source file:com.clican.pluto.dataprocess.dpl.function.SingleRowFunctionTestCase.java
private ProcessorContext getContext() throws Exception { // Fund//from w ww .j a va 2 s . c om List<BeanPrice> priceList1 = new ArrayList<BeanPrice>(); List<BeanPrice> priceList2 = new ArrayList<BeanPrice>(); List<Date> dateList = new ArrayList<Date>(); double[] value1 = new double[] { 2, 4, 6, 7, 5, 3, 4, 3, 2, 1 }; double[] value2 = new double[] { 2, 3, 4, 6, 2, 1, 5, 2, 1, 2 }; Date current = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); for (int i = 0; i < 10; i++) { BeanPrice price1 = new BeanPrice(); price1.setId(i); price1.setCode(i + ""); price1.setDate(DateUtils.add(current, Calendar.DAY_OF_MONTH, i - 10)); BeanPrice price2 = new BeanPrice(); price2.setId(i); price2.setDate(DateUtils.add(current, Calendar.DAY_OF_MONTH, i - 10)); price1.setPrice(value1[i]); price2.setPrice(value2[i]); priceList1.add(price1); priceList2.add(price2); dateList.add(DateUtils.add(current, Calendar.DAY_OF_MONTH, i - 10)); } ProcessorContext context = new ProcessorContextImpl(); context.setAttribute("priceList1", priceList1); context.setAttribute("priceList2", priceList2); context.setAttribute("dateList", dateList); return context; }
From source file:com.clican.pluto.dataprocess.dpl.function.MultiRowFunctionTestCase.java
private ProcessorContext getContext() throws Exception { // Fund/*from ww w . j ava 2 s . com*/ List<BeanPrice> priceList1 = new ArrayList<BeanPrice>(); List<BeanPrice> priceList2 = new ArrayList<BeanPrice>(); Date current = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); double[] value1 = new double[] { 2, 4, 6, 7, 5, 3, 4, 3, 2, 1 }; double[] value2 = new double[] { 2, 3, 4, 6, 2, 1, 5, 2, 1, 2 }; for (int i = 0; i < 10; i++) { BeanPrice price1 = new BeanPrice(); price1.setId(i); price1.setCode("01"); price1.setDate(DateUtils.add(current, Calendar.DAY_OF_MONTH, i - 10)); BeanPrice price2 = new BeanPrice(); price2.setId(i); price2.setCode("02"); price2.setDate(DateUtils.add(current, Calendar.DAY_OF_MONTH, i - 10)); price1.setPrice(value1[i]); price2.setPrice(value2[i]); priceList1.add(price1); priceList2.add(price2); } ProcessorContext context = new ProcessorContextImpl(); context.setAttribute("priceList1", priceList1); context.setAttribute("priceList2", priceList2); return context; }