List of usage examples for java.util Calendar compareTo
private int compareTo(long t)
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * ???/*from w ww .j a va 2s.co m*/ * * @param date * 1 * @param otherDate * 2 * @param withUnit * ??Calendar field? * @return 0, 0 ??0 */ public static int compareTime(Date date, Date otherDate, int withUnit) { Calendar dateCal = Calendar.getInstance(); dateCal.setTime(date); Calendar otherDateCal = Calendar.getInstance(); otherDateCal.setTime(otherDate); dateCal.clear(Calendar.YEAR); dateCal.clear(Calendar.MONTH); dateCal.set(Calendar.DATE, 1); otherDateCal.clear(Calendar.YEAR); otherDateCal.clear(Calendar.MONTH); otherDateCal.set(Calendar.DATE, 1); switch (withUnit) { case Calendar.HOUR: dateCal.clear(Calendar.MINUTE); otherDateCal.clear(Calendar.MINUTE); case Calendar.MINUTE: dateCal.clear(Calendar.SECOND); otherDateCal.clear(Calendar.SECOND); case Calendar.SECOND: dateCal.clear(Calendar.MILLISECOND); otherDateCal.clear(Calendar.MILLISECOND); case Calendar.MILLISECOND: break; default: throw new IllegalArgumentException("withUnit ?? " + withUnit + " ????"); } return dateCal.compareTo(otherDateCal); }
From source file:com.aimluck.eip.project.ProjectTaskFormData.java
/** * ????????//from w w w .jav a 2 s .co m * * @param msgList * * @return TRUE ? FALSE */ @Override protected boolean validate(List<String> msgList) { tracker.validate(msgList); task_name.validate(msgList); status.validate(msgList); priority.validate(msgList); progress_rate.validate(msgList); if (!hasChildren) { if (!taskMembers.isEmpty()) { // ?? List<Long> checkMemberId = new ArrayList<Long>(); for (Iterator<ProjectTaskMemberResultData> iter = taskMembers.iterator(); iter.hasNext();) { ProjectTaskMemberResultData data = iter.next(); long id = data.getUserId().getValue(); if (checkMemberId.contains(id)) { msgList.add(getl10n("PROJECT_VALIDATE_TASKMEMBER_DUPLICATE")); break; } checkMemberId.add(id); } } // ?? try { if (start_plan_date.getYear().length() > 0 && end_plan_date.getYear().length() > 0 && !ProjectUtils.isEmptyDate(start_plan_date.getValue().getDate()) && !ProjectUtils.isEmptyDate(end_plan_date.getValue().getDate())) { Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); start.setTime(start_plan_date.getValue().getDate()); end.setTime(end_plan_date.getValue().getDate()); if (start.compareTo(end) > 0) { msgList.add(getl10n("PROJECT_VALIDATE_PLAN_START_DATE")); } } } catch (NumberFormatException e1) { logger.error("ProjectTaskFormData.validate", e1); } catch (ALIllegalDateException e1) { logger.error("ProjectTaskFormData.validate", e1); } // ?? try { if (start_date.getYear().length() > 0 && end_date.getYear().length() > 0 && !ProjectUtils.isEmptyDate(start_date.getValue().getDate()) && !ProjectUtils.isEmptyDate(end_date.getValue().getDate())) { Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); start.setTime(start_date.getValue().getDate()); end.setTime(end_date.getValue().getDate()); if (start.compareTo(end) > 0) { msgList.add(getl10n("PROJECT_VALIDATE_START_DATE")); } } } catch (NumberFormatException e1) { logger.error("ProjectTaskFormData.validate", e1); } catch (ALIllegalDateException e1) { logger.error("ProjectTaskFormData.validate", e1); } try { if (planWorkloadString.equals("")) { plan_workload = new BigDecimal(0); } else { plan_workload = new BigDecimal(planWorkloadString); } if (plan_workload.compareTo(BigDecimal.valueOf(0)) < 0) { msgList.add(getl10n("PROJECT_VALIDATE_PLAN_WORKLOAD")); } else if (plan_workload.precision() - plan_workload.scale() > 5) { msgList.add(getl10n("PROJECT_VALIDATE_PLAN_WORKLOAD_RATIONAL_INTEGER")); } else if (plan_workload.scale() > 3) { msgList.add(getl10n("PROJECT_VALIDATE_PLAN_WORKLOAD_DECIMAL")); } } catch (Exception e) { msgList.add(getl10n("PROJECT_VALIDATE_PLAN_WORKLOAD_INTEGER")); } } boolean isProjectMember = false; if (!taskMembers.isEmpty()) { for (ProjectTaskMemberResultData data : taskMembers) { for (ALEipUser user : projectMembers) { if (data.getUserId().toString().equals(user.getUserId().toString())) { isProjectMember = true; break; } } } } else { isProjectMember = true; } // ???????? if (!isProjectMember) { msgList.add(getl10n("PROJECT_VALIDATE_TASKMEMBER_NOT_EXIST")); } return msgList.isEmpty(); }
From source file:eu.riscoss.rdc.RDCGithub.java
private void parseJsonIssues(JSONAware jv, String entity, Map<String, RiskData> values, int created_at_years) { if (jv instanceof JSONArray) { JSONArray ja = (JSONArray) jv;/*from w w w .java 2s . co m*/ int closedissues = 0; int openissues = 0; int pullrequests = 0; ArrayList<Double> diffList = new ArrayList<Double>();//should be Long, but only Double is supported in the REST data ArrayList<Double> numCommentsList = new ArrayList<Double>();//should be integer for (Object o : ja) { if (o instanceof JSONObject) { JSONObject jo = (JSONObject) o; //System.out.println(" issue state: "+(((JSONObject)jo).get("state"))); if (jo.get("pull_request") != null) { pullrequests++; continue; } String s = ((JSONObject) jo).get("state").toString(); if (s.equals("open")) openissues++; else if (s.equals("closed")) closedissues++; Calendar closedDate = null; Calendar openedDate = null; String openedAt = (String) ((JSONObject) jo).get("created_at"); if (openedAt != null) { openedDate = DatatypeConverter.parseDateTime(openedAt); //System.out.println("open: "+openedDate.getTime()); String closedAt = (String) ((JSONObject) jo).get("closed_at"); if (closedAt != null && !closedAt.equals("")) { closedDate = DatatypeConverter.parseDateTime(closedAt); //System.out.println("parse: opening date: "+openedDate.get(Calendar.YEAR)+" "+openedDate.get(Calendar.MONTH)); Calendar calendar = Calendar.getInstance();//actual calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - created_at_years); if (openedDate.compareTo(calendar) < 0) { break; } long diff = closedDate.getTimeInMillis() - openedDate.getTimeInMillis(); double diffd = diff / 1000 / 60 / 60 / 24; //difference in days. diffList.add(diffd); } } numCommentsList.add(new Double((Long) ((JSONObject) jo).get("comments"))); } } double sum = ja.size(); //assert(sum == openissues + closedissues); //??sure?? System.out.println(openissues + " openissues + " + closedissues + " closedissues = " + sum); RiskData rd = null; if (sum > 0) { rd = new RiskData(GITHUB_PREFIX + "issue-closedratio", entity, new Date(), RiskDataType.NUMBER, closedissues / sum); values.put(rd.getId(), rd); rd = new RiskData(GITHUB_PREFIX + "issue-openratio", entity, new Date(), RiskDataType.NUMBER, openissues / sum); values.put(rd.getId(), rd); } Distribution d = new Distribution(diffList); //days for closing issues rd = new RiskData(GITHUB_PREFIX + "issue-open-close-diff", entity, new Date(), RiskDataType.DISTRIBUTION, new Distribution(diffList)); values.put(rd.getId(), rd); //average days for closing an issue rd = new RiskData(GITHUB_PREFIX + "issue-open-close-diff-avg", entity, new Date(), RiskDataType.NUMBER, d.getAverage()); values.put(rd.getId(), rd); rd = new RiskData(GITHUB_PREFIX + "pull-requests", entity, new Date(), RiskDataType.NUMBER, pullrequests); values.put(rd.getId(), rd); d = new Distribution(numCommentsList); rd = new RiskData(GITHUB_PREFIX + "issue-comments", entity, new Date(), RiskDataType.DISTRIBUTION, d); values.put(rd.getId(), rd); rd = new RiskData(GITHUB_PREFIX + "issue-comments-avg", entity, new Date(), RiskDataType.NUMBER, d.getAverage()); values.put(rd.getId(), rd); } }
From source file:org.apache.oozie.coord.CoordELFunctions.java
private static String coord_currentRange_sync(int start, int end) throws Exception { final XLog LOG = XLog.getLog(CoordELFunctions.class); int datasetFrequency = getDSFrequency();// in minutes TimeUnit dsTimeUnit = getDSTimeUnit(); int[] instCount = new int[1];// used as pass by ref Calendar nominalInstanceCal = getCurrentInstance(getActionCreationtime(), instCount); if (nominalInstanceCal == null) { LOG.warn("If the initial instance of the dataset is later than the nominal time, an empty string is" + " returned. This means that no data is available at the current-instance specified by the user" + " and the user could try modifying his initial-instance to an earlier time."); return ""; } else {//from w w w. j a va 2 s .com Calendar initInstance = getInitialInstanceCal(); // Add in the reverse order - newest instance first. nominalInstanceCal = (Calendar) initInstance.clone(); nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), (instCount[0] + start) * datasetFrequency); List<String> instances = new ArrayList<String>(); for (int i = start; i <= end; i++) { if (nominalInstanceCal.compareTo(initInstance) < 0) { LOG.warn("If the initial instance of the dataset is later than the current-instance specified," + " such as coord:current({0}) in this case, an empty string is returned. This means that" + " no data is available at the current-instance specified by the user and the user could" + " try modifying his initial-instance to an earlier time.", start); } else { instances.add(DateUtils.formatDateOozieTZ(nominalInstanceCal)); } nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), datasetFrequency); } instances = Lists.reverse(instances); return StringUtils.join(instances, CoordELFunctions.INSTANCE_SEPARATOR); } }
From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java
/** * Checks if the selected time lays too far in the past * * @return true if too far in the past, false if not *///w ww .j av a 2s .co m public boolean isSelectionTooFarInPast() { if (this.mPickerDate != null && this.mValidateDateTime != null && this.mPastMinutesLimit != null) { Calendar selectedDate = Calendar.getInstance(); selectedDate.setTime(this.mPickerDate.getTime()); selectedDate.set(Calendar.HOUR_OF_DAY, mTimePicker.getHours()); selectedDate.set(Calendar.MINUTE, mTimePicker.getMinutes()); Calendar pastLimit = Calendar.getInstance(); pastLimit.setTime(this.mValidateDateTime.getTime()); pastLimit.add(Calendar.MINUTE, -this.mPastMinutesLimit); return selectedDate.compareTo(pastLimit) < 0; } return false; }
From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java
/** * This retrieves the leaf nodes and their dates and coordinates. * <P>/*from ww w.j a v a2 s . c om*/ * The tree area needs to be set before this is called. */ private void fetchLeafNodes() { // TODO: sensitive to document changes! /** Blank everything */ Calendar oldD = null, youngD = null; Element oldE = null, youngE = null; fLeafNodes.clear(); Phylogeny phylo = this.getPhylogeny(); Element rootClade = phylo.getRootClade(); DocumentImpl rootDocument = (DocumentImpl) rootClade.getOwnerDocument(); NodeIterator postIter = new PostOrderNodeIteratorImpl(rootDocument, rootClade, NodeFilter.SHOW_ELEMENT, cladeNodeFilter, true); Element cladeElem; while ((cladeElem = (Element) postIter.nextNode()) != null) { if (phylo.isCladeLeaf(cladeElem)) { fLeafNodes.add(cladeElem); /** * Get their dates, keeping track of the oldest and youngest. */ Calendar cal = this.getPhylogeny().getCladeDate(cladeElem); if (cal != null) { fLeafDates.put(cladeElem, cal); if (oldD == null) { oldD = cal; oldE = cladeElem; } else if (oldD.compareTo(cal) > 0) { oldD = cal; oldE = cladeElem; } if (youngD == null) { youngD = cal; youngE = cladeElem; } else if (youngD.compareTo(cal) < 0) { youngD = cal; youngE = cladeElem; } } } } this.fTopLeafDate = youngE; this.fBottomLeafDate = oldE; }
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * ???//from w w w . j a va2 s .c o m * * @param date * 1 * @param otherDate * 2 * @param withUnit * ??Calendar field? * @return 0, 0 ??0 */ public static int compareDate(Date date, Date otherDate, int withUnit) { Calendar dateCal = Calendar.getInstance(); dateCal.setTime(date); Calendar otherDateCal = Calendar.getInstance(); otherDateCal.setTime(otherDate); switch (withUnit) { case Calendar.YEAR: dateCal.clear(Calendar.MONTH); otherDateCal.clear(Calendar.MONTH); case Calendar.MONTH: dateCal.set(Calendar.DATE, 1); otherDateCal.set(Calendar.DATE, 1); case Calendar.DATE: dateCal.set(Calendar.HOUR_OF_DAY, 0); otherDateCal.set(Calendar.HOUR_OF_DAY, 0); case Calendar.HOUR: dateCal.clear(Calendar.MINUTE); otherDateCal.clear(Calendar.MINUTE); case Calendar.MINUTE: dateCal.clear(Calendar.SECOND); otherDateCal.clear(Calendar.SECOND); case Calendar.SECOND: dateCal.clear(Calendar.MILLISECOND); otherDateCal.clear(Calendar.MILLISECOND); case Calendar.MILLISECOND: break; default: throw new IllegalArgumentException("withUnit ?? " + withUnit + " ????"); } return dateCal.compareTo(otherDateCal); }
From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java
/** * Checks if the selected time lays too far in the future * * @return true if too far in the future, false if not *//*from w w w .j a v a2s . c o m*/ public boolean isSelectionTooFarInTheFuture() { if (this.mPickerDate != null && this.mValidateDateTime != null && this.mFutureMinutesLimit != null) { Calendar selectedDate = Calendar.getInstance(); selectedDate.setTime(this.mPickerDate.getTime()); selectedDate.set(Calendar.HOUR_OF_DAY, mTimePicker.getHours()); selectedDate.set(Calendar.MINUTE, mTimePicker.getMinutes()); Calendar futureLimit = Calendar.getInstance(); futureLimit.setTime(this.mValidateDateTime.getTime()); futureLimit.add(Calendar.MINUTE, this.mFutureMinutesLimit); return selectedDate.compareTo(futureLimit) > 0; } return false; }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * Validates message content of redelivered messages against original message. Validate that the redelivery delay * has occurred./*from w ww .ja v a 2s . com*/ * * @param receivedMessages The received message list. * @param originalMessageIndex The index of the origin message in the received message list. * @param redeliveredMessageIndex The index of the redelivered message in the received message list. * @param expectedMessageContent The expected message content. */ private void validateMessageContentAndDelay(List<ImmutablePair<String, Calendar>> receivedMessages, int originalMessageIndex, int redeliveredMessageIndex, String expectedMessageContent) { // Validate message content String messageContent = receivedMessages.get(redeliveredMessageIndex).getLeft(); Assert.assertEquals(messageContent, expectedMessageContent, "Invalid messages received."); // Validate delay Calendar originalMessageCalendar = receivedMessages.get(originalMessageIndex).getRight(); log.info("Original message timestamp for " + messageContent + " : " + originalMessageCalendar.getTimeInMillis()); originalMessageCalendar.add(Calendar.SECOND, 10); log.info("Minimum redelivered timestamp for " + messageContent + " : " + originalMessageCalendar.getTimeInMillis()); Calendar redeliveredMessageCalendar = receivedMessages.get(redeliveredMessageIndex).getRight(); log.info("Timestamp of redelivered for " + messageContent + " message : " + redeliveredMessageCalendar.getTimeInMillis()); Assert.assertTrue(originalMessageCalendar.compareTo(redeliveredMessageCalendar) <= 0, "Message received before the redelivery delay"); }
From source file:org.opensingular.internal.lib.commons.xml.TestMElement.java
License:asdf
@Test public void addDiferentTypesOfElements() { Calendar calendar = ConversorToolkit.getCalendar("01/01/2017"); MElement raiz = MElement.newInstance("raiz"); raiz.addElement("bytesOfString", "valor".getBytes()); raiz.addElement("calendar", calendar); raiz.addElement("date", calendar.getTime()); raiz.addElement("longValue", (long) 123); raiz.addElement("doubles", 123.45); raiz.addElement("simpleString", "valores"); raiz.addElement("outraString", "valor", "val"); raiz.addElement("doublePrecision", 123456.700, 1); GregorianCalendar calendarMElement = raiz.getCalendar("calendar"); Assert.assertEquals(0, calendar.compareTo(calendarMElement)); Date date = raiz.getDate("date"); Assert.assertEquals(0, date.compareTo(calendar.getTime())); long longValue = raiz.getLong("longValue"); Assert.assertEquals(longValue, (long) 123); double doubles = raiz.getDouble("doubles"); Assert.assertEquals(doubles, 123.45, 0); String simpleString = raiz.getValor("simpleString"); Assert.assertEquals(simpleString, "valores"); String outraString = raiz.getValor("outraString"); Assert.assertEquals(outraString, "valor"); double doublePrecision = raiz.getDouble("doublePrecision"); Assert.assertEquals(doublePrecision, 123456.7, 0); raiz.addElement("dateIgnoringDefault", calendar.getTime(), calendar.getTime()); Date dateIgnoringDefault = raiz.getDate("dateIgnoringDefault"); Assert.assertEquals(0, dateIgnoringDefault.compareTo(calendar.getTime())); raiz.addElement("dateUsingDefault", null, calendar.getTime()); Date dateUsingDefault = raiz.getDate("dateUsingDefault"); Assert.assertEquals(0, dateUsingDefault.compareTo(calendar.getTime())); Date dataNull = null;// w ww. j a va2 s. com raiz.addElement("dateUsingDefaultWithAllNull", null, dataNull); Date dateUsingDefaultWithAllNull = raiz.getDate("dateUsingDefaultWithAllNull"); Assert.assertNull(dateUsingDefaultWithAllNull); }