List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:com.adobe.acs.commons.wcm.impl.FileImporter.java
@Override @SuppressWarnings("squid:S3776") public void importData(String schemeValue, String dataSource, Resource target) { if (scheme.equals(schemeValue)) { final File file = new File(dataSource); if (file.exists()) { Calendar fileLastMod = Calendar.getInstance(); fileLastMod.setTimeInMillis(file.lastModified()); String fileName = file.getName(); String mimeType = mimeTypeService.getMimeType(fileName); final Node targetParent; final String targetName; Node node = target.adaptTo(Node.class); if (node != null) { try (FileInputStream stream = new FileInputStream(file)) { if (node.isNodeType(JcrConstants.NT_FILE)) { // assume that we are intending to replace this file targetParent = node.getParent(); targetName = node.getName(); Calendar nodeLastMod = JcrUtils.getLastModified(node); if (!nodeLastMod.before(fileLastMod)) { log.info("File '{}' does not have a newer timestamp than '{}'. Skipping import.", dataSource, target); return; }/* w ww . ja v a 2 s.com*/ } else { // assume that we are creating a new file under the current node targetParent = node; targetName = fileName; if (targetParent.hasNode(targetName)) { Node targetNode = targetParent.getNode(targetName); Calendar nodeLastMod = JcrUtils.getLastModified(targetNode); if (!nodeLastMod.before(fileLastMod)) { log.info( "File '{}' does not have a newer timestamp than '{}'. Skipping import.", dataSource, targetNode.getPath()); return; } } } JcrUtils.putFile(targetParent, targetName, mimeType, stream); node.getSession().save(); } catch (RepositoryException e) { throw new ImportException( "Unable to import from file '" + dataSource + "' to '" + target.getPath() + "'", e); } catch (IOException e) { throw new ImportException("Unexpected IOException while importing", e); } } else { log.warn("Target '{}' is not a JCR node. Skipping import from '{}'.", target.getPath(), dataSource); } } else { log.warn("File at '{}' does not exist. Skipping import.", dataSource); } } else { log.warn("Unrecognized scheme '{}' passed to importData()", schemeValue); } }
From source file:com.mgmtp.jfunk.common.random.MathRandom.java
private Calendar createCalendar(final long millis) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(millis); return DateUtils.truncate(cal, Calendar.DATE); }
From source file:org.spring.data.gemfire.app.beans.Person.java
protected Calendar getCalendar(final long timeInMillis) { Calendar calendar = Calendar.getInstance(); calendar.clear();/*from w w w . j a v a 2s.c om*/ calendar.setTimeInMillis(timeInMillis); return calendar; }
From source file:com.adobe.acs.commons.wcm.impl.FileImporterTest.java
@Test public void testImportToFile() throws Exception { Calendar earliest = Calendar.getInstance(); earliest.setTimeInMillis(0L); Node file = JcrUtils.putFile(folder, "test.txt", "x-text/test", new ByteArrayInputStream("".getBytes()), earliest);//from ww w . j a va 2 s . c o m session.save(); Resource resource = mock(Resource.class); when(resource.adaptTo(Node.class)).thenReturn(file); importer.importData("file", testFile.getAbsolutePath(), resource); assertFalse(session.hasPendingChanges()); assertFalse(folder.hasNode(testFile.getName())); assertEquals("text/plain", JcrUtils.getStringProperty(file, "jcr:content/jcr:mimeType", "")); }
From source file:com.rsltc.profiledata.main.MainActivity.java
private static void processDataSet(DataSet dataSet, InfoType type) { Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName()); Calendar calendar = Calendar.getInstance(); User user = new User(); for (DataPoint dp : dataSet.getDataPoints()) { if (type == InfoType.BPM) { Float min = null, max = null, avg = null; Log.i(TAG, "Data point:"); Log.i(TAG, "\tType: " + dp.getDataType().getName()); calendar.setTimeInMillis(dp.getStartTime(TimeUnit.MILLISECONDS)); Log.i(TAG, "\tStart: " + calendar.getTime()); calendar.setTimeInMillis(dp.getEndTime(TimeUnit.MILLISECONDS)); Log.i(TAG, "\tStop: " + calendar.getTime()); Log.i(TAG, "Timezone: " + calendar.getTimeZone().getDisplayName()); for (Field field : dp.getDataType().getFields()) { Log.i(TAG, "\tField: " + field.getName() + " Value: " + dp.getValue(field)); if (field.equals(Field.FIELD_AVERAGE)) { avg = dp.getValue(field).asFloat(); } else if (field.equals(Field.FIELD_MIN)) { min = dp.getValue(field).asFloat(); } else if (field.equals(Field.FIELD_MAX)) { max = dp.getValue(field).asFloat(); } else { Log.e(TAG, "Unsupported field found"); }/* w w w . j a v a2s .c om*/ } boolean valid = true; if (min != null && max != null && avg != null) { if (!HealthStatValidityChecker.checkIfNormal(avg, type)) { avg = (max + min) / 2; valid = HealthStatValidityChecker.checkIfNormal(avg, type); } } else { valid = false; } DailyHeartRate dailyHeartRate = new DailyHeartRate(avg != null ? avg : -1, max != null ? max : -1, min != null ? min : -1, valid, DateUtils.dateToDateRelated(calendar)); } else if (type == InfoType.USER_STATS) { Log.e(TAG, dp.toString()); Log.i(TAG, "Data point:"); Log.i(TAG, "\tType: " + dp.getDataType().getName()); DataType datatype = dp.getDataType(); calendar.setTimeInMillis(dp.getStartTime(TimeUnit.MILLISECONDS)); String dayOfMeasurement = DateUtils.dateToDateRelated(calendar); if (datatype.equals(DataType.TYPE_HEIGHT)) { Log.e(TAG, "I have height"); user.setHeight(dp.getValue(dp.getDataType().getFields().get(0)).asFloat()); } else { Log.e(TAG, "I have weight"); user.setWeight(MathUtil.round(dp.getValue(dp.getDataType().getFields().get(0)).asFloat(), 3)); } Log.i(TAG, "\tStart: " + calendar.getTime()); calendar.setTimeInMillis(dp.getEndTime(TimeUnit.MILLISECONDS)); Log.i(TAG, "\tStop: " + calendar.getTime()); for (Field field : dp.getDataType().getFields()) { Log.i(TAG, field.getName() + " " + dp.getValue(field)); } } } if (type == InfoType.USER_STATS) { //persist the user Log.i(TAG, user.toString()); } }
From source file:net.audumla.astronomy.algorithims.AstronomicalTest.java
@Test public void testWrapperMethodsMelbourne() throws Exception { TimeZone.setDefault(TimeZone.getTimeZone("Australia/Melbourne")); CelestialObject sun = CelestialObject.SUN; Calendar c = Calendar.getInstance(TimeZone.getDefault()); c.setTimeInMillis(0); c.set(Calendar.YEAR, 2009);// w w w . ja va2 s .c o m c.set(Calendar.MONTH, Calendar.AUGUST); c.set(Calendar.DAY_OF_MONTH, 8); Date date = c.getTime(); Geolocation.Location location = new Geolocation.Location(-37.70461920, 145.1030275, 0.0); TransitDetails details = sun.getTransitDetails(date, location, Sun.CIVIL); logger.debug("Melbourne"); logger.debug("Date : " + date); logger.debug("Julian : " + new JulianDate(date).julian()); logger.debug("Sunrise : Algorithms: " + details.getRiseTime() + " : " + details.getRiseTime().getTime()); logger.debug("Sunset : Algorithms: " + details.getSetTime() + " : " + details.getSetTime().getTime()); Assert.assertEquals(details.getRiseTime().getTime(), 1249677914422l, 1000); Assert.assertEquals(details.getSetTime().getTime(), 1249718740422l, 1000); }
From source file:com.c123.billbuddy.client.PaymentFeeder.java
@Transactional public void createPayment() { Random random = new Random(); int userId = (int) (userCount * random.nextDouble()); user = gigaSpace.readById(User.class, new Integer(userId)); int merchantId = (int) (merchantCount * random.nextDouble()); merchant = gigaSpace.readById(Merchant.class, new Integer(merchantId)); if (user != null && merchant != null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); Date date = calendar.getTime(); Double paymentAmount = Double.valueOf(Math.random() * 100); paymentAmount = Math.round(paymentAmount * 100.0) / 100.0; // Check If user valid and have credit limit if (user.getStatus() != AccountStatus.ACTIVE) { log.info("User: " + user.getName() + " status is " + user.getStatus()); } else if (user.getBalance() - paymentAmount < user.getCreditLimit()) { log.info("User: " + user.getName() + " doesn't have credit."); Double addUserBalance = Double.valueOf(Math.random() * 1000); addUserBalance = Math.round(addUserBalance * 100.0) / 100.0; log.info("Add " + addUserBalance + " to user balance"); user.setBalance(user.getBalance() + addUserBalance); gigaSpace.write(user);//w w w . j av a 2 s.c o m } else { // Withdraw payment amount from user account updateUserBalance(user, paymentAmount); // Deposit payment amount to merchant account updateMerchantReceipts(merchant, paymentAmount); // Create a Payment POJO and set it up. Payment payment = new Payment(); payment.setPayingAccountId(user.getUserAccountId()); payment.setReceivingMerchantId(merchant.getMerchantAccountId()); payment.setDescription(merchant.getCategory().name()); payment.setCreatedDate(date); payment.setPaymentAmount(Double.valueOf(Math.random() * 100)); payment.setPaymentAmount(Math.round(paymentAmount * 100.0) / 100.0); payment.setStatus(TransactionStatus.NEW); // Write the payment object gigaSpace.write(payment); log.info("TransactionWriterTask wrote new transaction between user: " + user.getName() + " and merchant: " + merchant.getName()); } } }
From source file:com.ubipass.middleware.web.action.LicenceMgtAction.java
/** * Action of display licence management page. * //from w ww. ja v a 2 s .com * @param mapping * ActionMapping * @param form * ActionForm * @param request * HttpServletRequest * @param response * HttpServletResponse * @return ActionForward forward to Struts page * @throws Exception * @see org.apache.struts.action.Action */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { request.getSession().setAttribute("page", "0,2"); File file = new File(this.getServlet().getServletContext().getRealPath("/" + LICENCE_FILE)); FileInputStream is; String userName = ""; String licenceKey = ""; String ExperDate = "0000-00-00"; try { is = new FileInputStream(file); Properties properties = new Properties(); properties.load(is); userName = properties.getProperty("userName"); licenceKey = properties.getProperty("licenceKey"); ExperDate = getDate(userName, licenceKey); Calendar cal = Calendar.getInstance(); try { cal.setTimeInMillis(Long.parseLong(ExperDate)); ExperDate = String.valueOf(cal.get(Calendar.YEAR)) + "-" + strReformat(cal.get(Calendar.MONTH) + 1) + "-" + strReformat(cal.get(Calendar.DATE)); } catch (Exception e) { ExperDate = "0000-00-00"; } request.setAttribute("userName", userName); request.setAttribute("ExperDate", ExperDate); request.setAttribute("licenceKey", licenceKey); is.close(); return mapping.findForward("Successful"); } catch (Exception e) { request.setAttribute("error", "error"); request.setAttribute("userName", userName); request.setAttribute("ExperDate", ExperDate); request.setAttribute("licenceKey", licenceKey); return mapping.findForward("Successful"); } }
From source file:net.audumla.astronomy.algorithims.AstronomicalTest.java
@Test public void testWrapperMethodsMexico() throws Exception { TimeZone.setDefault(TimeZone.getTimeZone("America/Mexico_City")); CelestialObject sun = new Sun(); Calendar c = Calendar.getInstance(TimeZone.getDefault()); c.setTimeInMillis(0); c.set(Calendar.YEAR, 2009);// w w w .j av a 2 s .co m c.set(Calendar.MONTH, Calendar.AUGUST); c.set(Calendar.DAY_OF_MONTH, 8); Date date = c.getTime(); Geolocation.Location location = new Geolocation.Location(); location.setLatitude(19.4328, Geolocation.Direction.NORTH); location.setLongitude(99.1333, Geolocation.Direction.WEST); TransitDetails details = sun.getTransitDetails(date, location, Sun.CIVIL); logger.debug("Mexico"); logger.debug("Date : " + date); logger.debug("Julian : " + new JulianDate(date).julian()); logger.debug("Sunrise : Algorithms: " + details.getRiseTime() + " : " + details.getRiseTime().getTime()); logger.debug("Sunset : Algorithms: " + details.getSetTime() + " : " + details.getSetTime().getTime()); Assert.assertEquals(details.getRiseTime().getTime(), 1249732325341l, 1000); Assert.assertEquals(details.getSetTime().getTime(), 1249781509341l, 1000); }
From source file:net.audumla.astronomy.algorithims.AstronomicalTest.java
@Test public void testWrapperMethodsRome() throws Exception { TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); CelestialObject sun = new Sun(); Calendar c = Calendar.getInstance(TimeZone.getDefault()); c.setTimeInMillis(0); c.set(Calendar.YEAR, 2009);/*from w ww. ja v a 2 s. com*/ c.set(Calendar.MONTH, Calendar.AUGUST); c.set(Calendar.DAY_OF_MONTH, 8); Date date = c.getTime(); Geolocation.Location location = new Geolocation.Location(); location.setLatitude(41.9000, Geolocation.Direction.NORTH); location.setLongitude(12.5000, Geolocation.Direction.EAST); TransitDetails details = sun.getTransitDetails(date, location, Sun.CIVIL); logger.debug("Rome"); logger.debug("Date : " + date); logger.debug("Julian : " + new JulianDate(date).julian()); logger.debug("Sunrise : Algorithms: " + details.getRiseTime() + " : " + details.getRiseTime().getTime()); logger.debug("Sunset : Algorithms: " + details.getSetTime() + " : " + details.getSetTime().getTime()); Assert.assertEquals(details.getRiseTime().getTime(), 1249702797298l, 1000); Assert.assertEquals(details.getSetTime().getTime(), 1249757426299l, 1000); }