List of usage examples for java.util Date compareTo
public int compareTo(Date anotherDate)
From source file:com.rapidminer.tools.Tools.java
/** Returns true if the date d1 is greater than date d1 or both are equal */ public static boolean isGreaterEqual(Date d1, Date d2) { return isEqual(d1, d2) || d1 != null && d1.compareTo(d2) > 0; }
From source file:com.rapidminer.tools.Tools.java
/** Returns true if the date d1 is less than date d1 or both are equal. */ public static boolean isLessEqual(Date d1, Date d2) { return isEqual(d1, d2) || d1 != null && d1.compareTo(d2) < 0; }
From source file:com.edduarte.protbox.core.registry.PReg.java
private PbxEntry evaluate(PbxEntry entry, File sharedFile, File protFile) throws ProtboxException { try {/*from w w w.j av a2s . c o m*/ if (entry == null) { // is a file or folder that is not represented by an entry on this PReg if (Constants.verbose) { logger.info("is a file or folder that is not represented by an entry on this PReg"); } if (sharedFile == null && protFile != null) { // new file at prot folder -> add to registry and sync to shared if (Constants.verbose) { logger.info("new file at prot folder -> add to registry and sync to shared"); } return add(protFile, FolderOption.PROT); } else if (sharedFile != null && protFile == null) { // new file at shared folder -> add to registry and sync to prot if (Constants.verbose) { logger.info("new file at shared folder -> add to registry and sync to prot"); } return add(sharedFile, FolderOption.SHARED); } else if (sharedFile != null && protFile != null) { // new files at both folders -> add to registry as conflicted copy and sync to shared if (Constants.verbose) { logger.info( "new files at both folders -> add to registry as conflicted copy and sync to shared"); } addConflicted(protFile, FolderOption.PROT); return add(sharedFile, FolderOption.SHARED); } } else if (entry instanceof PbxFile) { // is a file that is already represented by an entry on this PReg PbxFile entry1 = (PbxFile) entry; if ((sharedFile == null || !sharedFile.exists()) && (protFile == null || !protFile.exists())) { // entry was deleted from both folders -> keep entry and do nothing // logger.info("entry was deleted from both folders -> keep entry and do nothing"); } else if ((sharedFile == null || !sharedFile.exists()) && protFile != null) { // file was deleted from shared folder Date protLS = new Date(protFile.lastModified()); Date entryLS = entry1.getLatestSnapshot().getLastModifiedDate(); if (protLS.compareTo(entryLS) < 0) { // prot file is more recent than entry -> sync prot file to shared folder if (Constants.verbose) { logger.info("prot file is more recent than entry -> sync prot file to shared folder"); } SyncModule.toShared(this, entry); } else { // prot file is older than entry -> delete it while retaining data if (Constants.verbose) { logger.info("prot file is older than entry -> delete it while retaining data"); } delete(protFile, FolderOption.PROT); } } else if (sharedFile != null && protFile == null) { // file was deleted from prot folder Date sharedLS = new Date(sharedFile.lastModified()); Date entryLS = entry1.getLatestSnapshot().getLastModifiedDate(); if (sharedLS.compareTo(entryLS) < 0) { // shared file is more recent than entry -> sync shared file to prot folder if (Constants.verbose) { logger.info("shared file is more recent than entry -> sync shared file to prot folder"); } SyncModule.toProt(this, entry); } else { // shared file is older than entry -> delete it while retaining data if (Constants.verbose) { logger.info("shared file is older than entry -> delete it while retaining data"); } delete(sharedFile, FolderOption.SHARED); } } else if (sharedFile != null && protFile != null) { // file exists at both folders Date sharedLS = new Date(sharedFile.lastModified()); Date protLS = new Date(protFile.lastModified()); Date entryLS = entry1.getLatestSnapshot().getLastModifiedDate(); int compareSharedProt = sharedLS.compareTo(protLS); int compareProtEntry = protLS.compareTo(entryLS); int compareSharedEntry = sharedLS.compareTo(entryLS); if (compareSharedProt == 0 && compareProtEntry == 0) { // all last modified dates are equal -> do nothing // logger.info("all last modified dates are equal -> do nothing"); } else if (compareSharedProt != 0) { if (compareProtEntry == 0 && compareSharedEntry != 0) { // shared file was updated -> sync shared to prot if (Constants.verbose) { logger.info("shared file was updated -> sync shared to prot"); } SyncModule.toProt(this, entry); } else if (compareProtEntry != 0 && compareSharedEntry == 0) { // prot file was updated -> sync prot to shared if (Constants.verbose) { logger.info("prot file was updated -> sync prot to shared"); } SyncModule.toShared(this, entry); } else if (compareProtEntry != 0 && compareSharedEntry != 0) { // both files were updated -> conflict if (Constants.verbose) { logger.info("both files were updated -> conflict"); } addConflicted(protFile, FolderOption.PROT); SyncModule.toProt(this, entry); } } } } else if (entry instanceof PbxFolder) { // is a folder that is already represented by an entry on this PReg if ((sharedFile == null || !sharedFile.exists()) && (protFile == null || !protFile.exists())) { // entry was deleted from both folders -> keep entry and do nothing if (Constants.verbose) { logger.info("entry was deleted from both folders -> keep entry and do nothing"); } } else if ((protFile == null || !protFile.exists()) && (sharedFile != null && sharedFile.exists())) { // entry was deleted at prot folder -> delete it from shared folder but keep entry if (Constants.verbose) { logger.info( "entry was deleted at prot folder -> delete it from shared folder but keep entry"); } deleteFilesFromEntry(entry); } else if ((sharedFile == null || !sharedFile.exists()) && (protFile != null && protFile.exists())) { // entry was deleted at shared folder -> assure that it is updated, by syncing from prot to shared if (Constants.verbose) { logger.info( "entry was deleted at shared folder -> assure that it is updated, by syncing from prot to shared"); } SyncModule.toShared(this, entry); } } } catch (NullPointerException ex) { // This catch is here only to avoid crashing due to non-existent / null files ex.printStackTrace(); } return entry; }
From source file:org.sofun.core.kup.KupImpl.java
/** * Returns the Kup's first betable event start date. * //from w w w. j a va 2 s. co m * <p> * * Returns the specified start date of the Kup if no events and / or start * date of events are unknown * * @return a {@link Date} instance. */ private Date getFirstEventStartDate() { Date d = null; for (TournamentSeason season : getBettableTournaments()) { Date startDate = season.getStartDate(); if (d == null) { d = startDate; } else if (startDate != null && startDate.compareTo(d) < 0) { d = season.getStartDate(); } } for (TournamentStage stage : getBettableStages()) { Date startDate = stage.getStartDate(); if (d == null) { d = startDate; } else if (startDate != null && startDate.compareTo(d) < 0) { d = stage.getStartDate(); } } for (TournamentRound round : getBettableRounds()) { Date startDate = round.getStartDate(); if (d == null) { d = startDate; } else if (startDate != null && startDate.compareTo(d) < 0) { d = round.getStartDate(); } } for (TournamentGame game : getBettableGames()) { Date startDate = game.getStartDate(); if (d == null) { d = startDate; } else if (startDate != null && startDate.compareTo(d) < 0) { d = game.getStartDate(); } } if (d == null) { d = getStartDate(); } return d; }
From source file:com.rapidminer.tools.Tools.java
/** * Returns <code>true</code> if the date d1 is greater than date d2. Returns <code>false</code> * if either d1 or d2 are <code>null</code>. *//*from w w w .j a v a 2 s.co m*/ public static boolean isGreater(Date d1, Date d2) { if (d1 == null || d2 == null) { return false; } return d1.compareTo(d2) > 0; }
From source file:com.rapidminer.tools.Tools.java
/** * Returns <code>true</code> if the date d1 is less than date d2. Returns <code>false</code> if * either d1 or d2 are <code>null</code>. *///from w w w .java 2 s . c o m public static boolean isLess(Date d1, Date d2) { if (d1 == null || d2 == null) { return false; } return d1.compareTo(d2) < 0; }
From source file:org.finra.herd.service.impl.StoragePolicySelectorServiceImpl.java
@Override public List<StoragePolicySelection> execute(String sqsQueueName, int maxResult) { // Create a result list. List<StoragePolicySelection> storagePolicySelections = new ArrayList<>(); // Get the current timestamp from the database. Timestamp currentTimestamp = herdDao.getCurrentTimestamp(); // Get the threshold in days since business object data registration update for business object data to be selectable // by a storage policy with DAYS_SINCE_BDATA_PRIMARY_PARTITION_VALUE storage policy rule type. int updatedOnThresholdInDays = herdStringHelper.getConfigurationValueAsInteger( ConfigurationValue.STORAGE_POLICY_PROCESSOR_BDATA_UPDATED_ON_THRESHOLD_DAYS); // Get the maximum number of failed storage policy transition attempts before the relative storage unit gets excluded from // being selected per storage policies by the storage policy selector system job. 0 means the maximum is not set. int maxAllowedTransitionAttempts = herdStringHelper .getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_TRANSITION_MAX_ALLOWED_ATTEMPTS); LOGGER.info("{}={} {}={}", ConfigurationValue.STORAGE_POLICY_PROCESSOR_BDATA_UPDATED_ON_THRESHOLD_DAYS.getKey(), updatedOnThresholdInDays,/*w w w . j av a2s. c o m*/ ConfigurationValue.STORAGE_POLICY_TRANSITION_MAX_ALLOWED_ATTEMPTS.getKey(), maxAllowedTransitionAttempts); // Compute business object data "updated on" threshold timestamp based on // the current database timestamp and the threshold value configured in the system. Timestamp updatedOnThresholdTimestamp = HerdDateUtils.addDays(currentTimestamp, -updatedOnThresholdInDays); // Keep track of all business object data entities selected per storage policies. This is need to avoid a lower priority selection policy // to be executed ahead of a higher priority one. Set<BusinessObjectDataEntity> selectedBusinessObjectDataEntities = new LinkedHashSet<>(); // Separately process all possible storage policy priority levels in order of priorities. This is done to assure that higher priority level storage // policies will be listed earlier in the final result map. for (StoragePolicyPriorityLevel storagePolicyPriorityLevel : STORAGE_POLICY_PRIORITY_LEVELS) { // Until we reach maximum number of results or run out of entities to select, retrieve and process business object data entities mapped to their // corresponding storage policy entities, where the business object data status is supported by the storage policy feature and the business object // data alternate key values match storage policy's filter and transition (not taking into account storage policy rules). int startPosition = 0; while (true) { Map<BusinessObjectDataEntity, StoragePolicyEntity> map = businessObjectDataDao .getBusinessObjectDataEntitiesMatchingStoragePolicies(storagePolicyPriorityLevel, SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, maxAllowedTransitionAttempts, startPosition, maxResult); for (Map.Entry<BusinessObjectDataEntity, StoragePolicyEntity> entry : map.entrySet()) { BusinessObjectDataEntity businessObjectDataEntity = entry.getKey(); // Process this storage policy selection, only if this business object data has not been selected earlier. if (!selectedBusinessObjectDataEntities.contains(businessObjectDataEntity)) { boolean createStoragePolicySelection = false; // Remember that we got this business object data entity as matching to a storage policy. // This is done so we would not try to select this business object data again later by a lower level storage policy. selectedBusinessObjectDataEntities.add(businessObjectDataEntity); // Get the storage policy entity, so we can validate the storage policy rule against this business object data. StoragePolicyEntity storagePolicyEntity = entry.getValue(); // Get a storage policy rule type and value. String storagePolicyRuleType = storagePolicyEntity.getStoragePolicyRuleType().getCode(); Integer storagePolicyRuleValue = storagePolicyEntity.getStoragePolicyRuleValue(); // For DAYS_SINCE_BDATA_REGISTERED storage policy rule type, select business object data based on it's "created on" timestamp. if (StoragePolicyRuleTypeEntity.DAYS_SINCE_BDATA_REGISTERED.equals(storagePolicyRuleType)) { // Compute "created on" threshold timestamp based on the current timestamp and storage policy rule value. Timestamp createdOnThresholdTimestamp = HerdDateUtils.addDays(currentTimestamp, -storagePolicyRuleValue); // Select this business object data if it has "created on" timestamp before or equal to the threshold timestamp. createStoragePolicySelection = (businessObjectDataEntity.getCreatedOn() .compareTo(createdOnThresholdTimestamp) <= 0); } // For DAYS_SINCE_BDATA_PRIMARY_PARTITION_VALUE storage policy rule type, select business object data based on both it's primary // partition value compared against storage policy rule value and "updated on" timestamp being below the threshold. else if (StoragePolicyRuleTypeEntity.DAYS_SINCE_BDATA_PRIMARY_PARTITION_VALUE .equals(storagePolicyRuleType)) { // For this storage policy rule, we ignore this business object data if it was updated earlier than the threshold value of days ago. if (businessObjectDataEntity.getUpdatedOn() .compareTo(updatedOnThresholdTimestamp) <= 0) { // Try to convert business object data primary partition value to a timestamp. // If it is not a date, the storage policy rule is not matching this business object data. Date primaryPartitionValue = businessObjectDataHelper .getDateFromString(businessObjectDataEntity.getPartitionValue()); // For this storage policy rule, we ignore this business data if primary partition value is not a date. if (primaryPartitionValue != null) { // Compute the relative primary partition value threshold date based on the current timestamp and storage policy rule value. Date primaryPartitionValueThreshold = new Date(HerdDateUtils .addDays(currentTimestamp, -storagePolicyRuleValue).getTime()); // Select this business object data if it has it's primary partition value before or equal to the threshold date. createStoragePolicySelection = (primaryPartitionValue .compareTo(primaryPartitionValueThreshold) <= 0); } } } // Fail on an un-supported storage policy rule type. else { throw new IllegalStateException(String .format("Storage policy type \"%s\" is not supported.", storagePolicyRuleType)); } // If this business object data got selected, create a storage policy selection and add it to the result list. if (createStoragePolicySelection) { // Create business object data key and storage policy key per selected entities. BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper .getBusinessObjectDataKey(businessObjectDataEntity); StoragePolicyKey storagePolicyKey = new StoragePolicyKey( storagePolicyEntity.getNamespace().getCode(), storagePolicyEntity.getName()); // Create and add a storage policy selection to the result list. storagePolicySelections.add(new StoragePolicySelection(businessObjectDataKey, storagePolicyKey, storagePolicyEntity.getVersion())); LOGGER.info("Selected business object data for storage policy processing: " + "businessObjectDataKey={} storagePolicyKey={} storagePolicyVersion={}", jsonHelper.objectToJson(businessObjectDataKey), jsonHelper.objectToJson(storagePolicyKey), storagePolicyEntity.getVersion()); // Stop adding storage policy selections to the result list if we reached the maximum results limit. if (storagePolicySelections.size() >= maxResult) { break; } } } } // Stop processing storage policies if we reached the max result limit or there are no more business object data to select. if (storagePolicySelections.size() >= maxResult || map.isEmpty()) { break; } // Increment start position for the next select. startPosition += maxResult; } // Stop processing storage policies if we reached the max result limit. if (storagePolicySelections.size() >= maxResult) { break; } } // Send all storage policy selections to the specified SQS queue. sendStoragePolicySelectionToSqsQueue(sqsQueueName, storagePolicySelections); return storagePolicySelections; }
From source file:com.krawler.esp.servlets.importProjectPlanCSV.java
public String getActualDuration(Date stdate, Date enddate, int[] NonWorkDays, String[] holidays) { int noofdays = 0; java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd"); try {// w ww .j a v a2 s . c o m Calendar c1 = Calendar.getInstance(); while (stdate.compareTo(enddate) < 0) { if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0 && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) { noofdays++; } c1.set(stdate.getYear() + 1900, stdate.getMonth(), stdate.getDate()); c1.add(Calendar.DATE, 1); stdate = sdf1.parse(sdf1.format(c1.getTime())); } if (stdate.compareTo(enddate) == 0) { if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0 && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) { noofdays++; } } } catch (ParseException ex) { Logger.getLogger(importProjectPlanCSV.class.getName()).log(Level.SEVERE, null, ex); } return noofdays + "d"; }
From source file:open.dolphin.infomodel.DocInfoModel.java
/** * ??????/*from w ww .jav a2 s . co m*/ * * @param other * @return */ @Override public int compareTo(Object other) { if (other != null && getClass() == other.getClass()) { Date val1 = getFirstConfirmDate(); Date val2 = ((DocInfoModel) other).getFirstConfirmDate(); int result = (val1 != null && val2 != null) ? val1.compareTo(val2) : 0; if (result == 0) { val1 = getConfirmDate(); val2 = ((DocInfoModel) other).getConfirmDate(); result = (val1 != null && val2 != null) ? val1.compareTo(val2) : 0; } return result; } return -1; }
From source file:org.pentaho.di.core.ResultFileTest.java
@Test public void testGetRow() throws KettleFileException, FileSystemException { File tempDir = new File(new TemporaryFolder().toString()); FileObject tempFile = KettleVFS.createTempFile("prefix", "suffix", tempDir.toString()); Date timeBeforeFile = Calendar.getInstance().getTime(); ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, tempFile, "myOriginParent", "myOrigin"); Date timeAfterFile = Calendar.getInstance().getTime(); assertNotNull(resultFile);//from w ww . j ava 2 s .c o m RowMetaInterface rm = resultFile.getRow().getRowMeta(); assertEquals(7, rm.getValueMetaList().size()); assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(0).getType()); assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(1).getType()); assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(2).getType()); assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(3).getType()); assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(4).getType()); assertEquals(ValueMetaInterface.TYPE_STRING, rm.getValueMeta(5).getType()); assertEquals(ValueMetaInterface.TYPE_DATE, rm.getValueMeta(6).getType()); assertEquals(ResultFile.FILE_TYPE_GENERAL, resultFile.getType()); assertEquals("myOrigin", resultFile.getOrigin()); assertEquals("myOriginParent", resultFile.getOriginParent()); assertTrue("ResultFile timestamp is created in the expected window", timeBeforeFile.compareTo(resultFile.getTimestamp()) <= 0 && timeAfterFile.compareTo(resultFile.getTimestamp()) >= 0); tempFile.delete(); tempDir.delete(); }