List of usage examples for java.util Date equals
public boolean equals(Object obj)
From source file:com.agiletec.plugins.jacms.aps.system.services.content.widget.UserFilterOptionBean.java
private void checkRange(String[] formFieldNames) { if (!this.isAttributeFilter() || null != this.getFormFieldErrors() || null == this.getFormFieldValues() || this.getFormFieldValues().size() < 2) return;//from w w w . j a v a2 s . c om boolean check = false; if (this.getAttribute() instanceof DateAttribute) { Date start = DateConverter.parseDate(this.getFormFieldValues().get(formFieldNames[0]), this.getDateFormat()); Date end = DateConverter.parseDate(this.getFormFieldValues().get(formFieldNames[1]), this.getDateFormat()); check = (!start.equals(end) && start.after(end)); } else if (this.getAttribute() instanceof NumberAttribute) { Integer start = Integer.parseInt(this.getFormFieldValues().get(formFieldNames[0])); Integer end = Integer.parseInt(this.getFormFieldValues().get(formFieldNames[1])); check = (!start.equals(end) && start.intValue() > end.intValue()); } if (check) { this.setFormFieldErrors(new HashMap<String, AttributeFormFieldError>(2)); AttributeFormFieldError error = new AttributeFormFieldError(this.getAttribute().getName(), formFieldNames[1], AttributeFormFieldError.INVALID_RANGE_KEY, null); this.getFormFieldErrors().put(formFieldNames[1], error); } }
From source file:hr.fer.zemris.vhdllab.dao.impl.HistoryDaoTest.java
/** * Insert version, update version and created on can't be updated. *//*from w w w . j a v a 2 s . c om*/ @Test public void userIdTypeAndCreatedOnNotUpdateable() { dao.persist(entity); Integer newInsertVersion = 12; Integer newUpdateVersion = 32; Date newCreatedOn = CREATED_ON; history.setInsertVersion(newInsertVersion); history.setUpdateVersion(newUpdateVersion); history.setCreatedOn(newCreatedOn); dao.merge(entity); closeEntityManager(); // flush cache createEntityManager(); HistoryTable loaded = (HistoryTable) entityManager.createQuery("select e from HistoryTable e") .getSingleResult(); History loadedHistory = loaded.getHistory(); assertFalse(newInsertVersion.equals(loadedHistory.getInsertVersion())); assertFalse(newUpdateVersion.equals(loadedHistory.getUpdateVersion())); assertFalse(newCreatedOn.equals(loadedHistory.getCreatedOn())); }
From source file:com.inmobi.databus.readers.DatabusStreamWaitingReader.java
/** * This method is used to check whether the given minute directory is * completely read or not. It takes the current time stamp and the minute * on which the reader is currently working. It retrieves the partition checkpoint * for that minute if it contains. It compares the current time stamp with * the checkpointed time stamp. If current time stamp is before the * checkpointed time stamp then that minute directory for the current hour is * completely read. If both the time stamps are same then it checks line number. * If line num is -1 means all the files in that minute dir are already read. *///from w w w . j av a2s .com public boolean isRead(Date currentTimeStamp, int minute) { Date checkpointedTimestamp = pChkpoints.get(Integer.valueOf(minute)).timeStamp; if (checkpointedTimestamp == null) { return false; } if (currentTimeStamp.before(checkpointedTimestamp)) { return true; } else if (currentTimeStamp.equals(checkpointedTimestamp)) { return pChkpoints.get(Integer.valueOf(minute)).readFully; } return false; }
From source file:net.phase.wallet.Currency.java
protected static Transaction[] compressTransactions(Transaction[] transactions) { ArrayList<Transaction> txs = new ArrayList<Transaction>(); Date currentDate = new Date(); Transaction currentTransaction = null; for (Transaction transaction : transactions) { if (!currentDate.equals(transaction.date)) { currentTransaction = new Transaction(transaction.date, 0, transaction.from, transaction.to); currentTransaction.addTransaction(transaction); txs.add(currentTransaction); currentDate = transaction.date; } else {//from w w w .j a v a2 s . c o m // same date, just add the data if (currentTransaction != null) { currentTransaction.addTransaction(transaction); } } } Transaction[] result = new Transaction[txs.size()]; txs.toArray(result); return result; }
From source file:net.chaosserver.timelord.swingui.CommonTaskPanel.java
/** * Checks if the date being displayed is equal to the start of the current * time./* w ww . jav a2s .co m*/ * * @return indicates if the date is the start of the current time */ public boolean isToday() { boolean result = false; Date todayDate = DateUtil.trunc(new Date()); if (todayDate.equals(getDateDisplayed())) { result = true; } return result; }
From source file:com.enonic.cms.core.content.ContentVersionEntity.java
public int getState(Date now) { int state;//from ww w . ja va 2 s. c o m if (isApproved() && isMainVersion()) { Date from = content.getAvailableFrom(); Date to = content.getAvailableTo(); if (from == null && to == null) { state = ContentStatus.APPROVED.getKey(); } else if (from == null) { if (now.after(to) || now.equals(to)) { state = ContentVersionEntity.STATE_PUBLISH_EXPIRED; } else { state = ContentStatus.APPROVED.getKey(); } } else if (from.after(now)) { state = ContentVersionEntity.STATE_PUBLISH_WAITING; } else { // from.before(now) == true if (to == null || to.after(now)) { state = ContentVersionEntity.STATE_PUBLISHED; } else { state = ContentVersionEntity.STATE_PUBLISH_EXPIRED; } } } else { state = status; } return state; }
From source file:org.agnitas.service.impl.UserActivityLogServiceImpl.java
private int[] processFile(UserActivityLogForm aForm, int rownums, List<AdminEntry> admins, DateFormat df, Date today, Date fromDate, Date toDate, File currentDayLogFile, int offset, List<Map> result, int rowCount, int totalRows, File currentFile) throws ParseException, IOException { List<Map> intermediateResult = new ArrayList<Map>(); String currentDateString = currentFile.getName().substring(currentDayLogFile.getName().length()); Date currentFileDate = null;/*w w w . j a v a 2 s. c o m*/ if (!StringUtils.isEmpty(currentDateString)) { currentFileDate = df.parse(currentDateString.substring(1)); } if ((currentFileDate == null && (today.equals(fromDate) || today.equals(toDate))) || (currentFileDate != null && ((currentFileDate.after(fromDate) && currentFileDate.before(toDate) || currentFileDate.equals(fromDate) || currentFileDate.equals(toDate))))) { AgnUtils.logger().info("Starting to process log file " + currentFile.getName()); final InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(currentFile)); final BufferedReader in = new BufferedReader(inputStreamReader); while (in.ready()) { final String line = in.readLine(); if (line == null) { break; } try { String[] row = new CsvTokenizer(line, " ", "").toArray(); AgnUtils.logger().info("Successfully parsed log record: '" + line); putLogIntoList(intermediateResult, row, 0); } catch (Exception e) { AgnUtils.logger().error("Failed to parse log record: '" + line); AgnUtils.logger().error("Structure log file error", e); } } } else { AgnUtils.logger().info("Skipping log file " + currentFile.getName()); } if (!intermediateResult.isEmpty()) { for (Map map : intermediateResult) { boolean firstCondition = (StringUtils.isEmpty(aForm.getUsername()) || aForm.getUsername().equals("0")) && checkUsernameByCompanyId(map.get("username") + ":", admins); boolean secondCondition = aForm.getUsername() != null && aForm.getUsername().equals(map.get("username")); if (firstCondition || secondCondition) { if (aForm.getUserActivityLogAction() == UserActivityLogActions.ANY.getIntValue() || actionMachesRequest(map, aForm) || notLoginOrLogout(map, aForm) || loginOrLogout(map, aForm)) { if (rownums > result.size()) { if (rowCount >= offset) { result.add(map); } rowCount++; } totalRows++; } } } } return new int[] { rowCount, totalRows }; }
From source file:org.polymap.rhei.field.DateTimeFormField.java
public IFormField setValue(Object value) { Date date = (Date) value; Calendar cal = Calendar.getInstance(Locale.GERMANY); cal.setTime(date);// w ww .j a v a 2s . com // modify the orig value; otherwise millis may differ as DateTime field // does not support millis cal.set(Calendar.MILLISECOND, 0); date.setTime(cal.getTimeInMillis()); datetime.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE)); datetime.setTime(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND)); // the above calls does not seem to fire events site.fireEvent(DateTimeFormField.this, IFormFieldListener.VALUE_CHANGE, loadedValue == null && date.equals(nullValue) ? null : date); return this; }
From source file:com.emc.ecs.sync.target.S3Target.java
@Override public void filter(SyncObject obj) { try {/*from w ww . j a v a2 s . c om*/ // skip the root of the bucket since it obviously exists if ("".equals(rootKey + obj.getRelativePath())) { log.debug("Target is bucket root; skipping"); return; } // some sync objects lazy-load their metadata (i.e. AtmosSyncObject) // since this may be a timed operation, ensure it loads outside of other timed operations if (!(obj instanceof S3ObjectVersion) || !((S3ObjectVersion) obj).isDeleteMarker()) obj.getMetadata(); // Compute target key String targetKey = getTargetKey(obj); obj.setTargetIdentifier(AwsS3Util.fullPath(bucketName, targetKey)); if (includeVersions) { ListIterator<S3ObjectVersion> sourceVersions = s3Source.versionIterator((S3SyncObject) obj); ListIterator<S3ObjectVersion> targetVersions = versionIterator(obj); boolean newVersions = false, replaceVersions = false; if (force) { replaceVersions = true; } else { // special workaround for bug where objects are listed, but they have no versions if (sourceVersions.hasNext()) { // check count and etag/delete-marker to compare version chain while (sourceVersions.hasNext()) { S3ObjectVersion sourceVersion = sourceVersions.next(); if (targetVersions.hasNext()) { S3ObjectVersion targetVersion = targetVersions.next(); if (sourceVersion.isDeleteMarker()) { if (!targetVersion.isDeleteMarker()) replaceVersions = true; } else { if (targetVersion.isDeleteMarker()) replaceVersions = true; else if (!sourceVersion.getETag().equals(targetVersion.getETag())) replaceVersions = true; // different checksum } } else if (!replaceVersions) { // source has new versions, but existing target versions are ok newVersions = true; sourceVersions.previous(); // back up one putIntermediateVersions(sourceVersions, targetKey); // add any new intermediary versions (current is added below) } } if (targetVersions.hasNext()) replaceVersions = true; // target has more versions if (!newVersions && !replaceVersions) { log.info("Source and target versions are the same. Skipping {}", obj.getRelativePath()); return; } } } // something's off; must delete all versions of the object if (replaceVersions) { log.info( "[{}]: version history differs between source and target; re-placing target version history with that from source.", obj.getRelativePath()); // collect versions in target List<DeleteObjectsRequest.KeyVersion> deleteVersions = new ArrayList<>(); while (targetVersions.hasNext()) targetVersions.next(); // move cursor to end while (targetVersions.hasPrevious()) { // go in reverse order S3ObjectVersion version = targetVersions.previous(); deleteVersions.add(new DeleteObjectsRequest.KeyVersion(targetKey, version.getVersionId())); } // batch delete all versions in target log.debug("[{}]: deleting all versions in target", obj.getRelativePath()); s3.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(deleteVersions)); // replay version history in target while (sourceVersions.hasPrevious()) sourceVersions.previous(); // move cursor to beginning putIntermediateVersions(sourceVersions, targetKey); } } else { // normal sync (no versions) Date sourceLastModified = obj.getMetadata().getModificationTime(); long sourceSize = obj.getMetadata().getContentLength(); // Get target metadata. ObjectMetadata destMeta = null; try { destMeta = s3.getObjectMetadata(bucketName, targetKey); } catch (AmazonS3Exception e) { if (e.getStatusCode() != 404) throw new RuntimeException("Failed to check target key '" + targetKey + "' : " + e, e); } if (!force && obj.getFailureCount() == 0 && destMeta != null) { // Check overwrite Date destLastModified = destMeta.getLastModified(); long destSize = destMeta.getContentLength(); if (destLastModified.equals(sourceLastModified) && sourceSize == destSize) { log.info("Source and target the same. Skipping {}", obj.getRelativePath()); return; } if (destLastModified.after(sourceLastModified)) { log.info("Target newer than source. Skipping {}", obj.getRelativePath()); return; } } } // at this point we know we are going to write the object // Put [current object version] if (obj instanceof S3ObjectVersion && ((S3ObjectVersion) obj).isDeleteMarker()) { // object has version history, but is currently deleted log.debug("[{}]: deleting object in target to replicate delete marker in source.", obj.getRelativePath()); s3.deleteObject(bucketName, targetKey); } else { putObject(obj, targetKey); // if object has new metadata after the stream (i.e. encryption checksum), we must update S3 again if (obj.requiresPostStreamMetadataUpdate()) { log.debug("[{}]: updating metadata after sync as required", obj.getRelativePath()); CopyObjectRequest cReq = new CopyObjectRequest(bucketName, targetKey, bucketName, targetKey); cReq.setNewObjectMetadata(AwsS3Util.s3MetaFromSyncMeta(obj.getMetadata())); s3.copyObject(cReq); } } } catch (Exception e) { throw new RuntimeException("Failed to store object: " + e, e); } }
From source file:net.chaosserver.timelord.data.TimelordTask.java
/** * Checks if the task already has some hours tracked for today. * * @return if there is a task for today/*from w w w. j a v a 2 s .c o m*/ */ public boolean isTodayPresent() { boolean todayPresent = false; List<TimelordTaskDay> taskList = getTaskDayList(); if ((taskList != null) && !taskList.isEmpty()) { Date todayDate = DateUtil.trunc(new Date()); TimelordTaskDay taskDay = (TimelordTaskDay) taskList.get(0); Date taskDayDate = taskDay.getDate(); if (taskDayDate != null) { if (log.isTraceEnabled()) { log.trace("Testing taskDayDate [" + this.getTaskName() + "] [" + taskDayDate.getTime() + "] against today [" + todayDate.getTime() + "]"); } if (taskDayDate.equals(todayDate) || taskDayDate.after(todayDate)) { todayPresent = true; } } else { if (log.isWarnEnabled()) { log.warn("Empty date field. Removing taskDay."); taskList.remove(taskDay); } } } return todayPresent; }