List of usage examples for java.util Date compareTo
public int compareTo(Date anotherDate)
From source file:com.neusoft.mid.clwapi.service.msg.MsgServiceImpl.java
/** * ???/*from w ww. j a v a2s. co m*/ * * @param token * ?. * @param eTag * * @return ???. */ @Override public Object getMsgMold(String token, String eTag) { // ?? boolean checkEtag = true; // ?ID String usrId = context.getHttpHeaders().getHeaderString(UserInfoKey.USR_ID); String plaETag = context.getHttpHeaders().getHeaderString(UserInfoKey.RULE_ETAG); logger.info("????"); logger.info("?ETag:" + eTag); logger.info("??ETag:" + plaETag); // ? Date dateTer = null; // ?? Date datePla = null; // ? if (eTag == null) { logger.error("If-None-Match"); throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST); } if (!eTag.equals(HttpConstant.TIME_ZERO)) { try { dateTer = BeanUtil.checkTimeForm(eTag, HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.error("??" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } } else { // ??? checkEtag = false; } // ?? List<MsgMoldInfo> list = msgMapper.getMsgMoldInfoWithUsr(usrId); // ??? if (list == null || list.size() == 0) { logger.info("???"); return Response.notModified().build(); } else { // ?? String e = list.get(0).getEditT(); // ? if (!StringUtils.equals(e, plaETag)) { logger.info("?"); // ??ETag upUserETag(token, usrId, e); plaETag = e; } } // ?? try { datePla = BeanUtil.checkTimeForm(plaETag, HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.error("???" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR); } // ??NO_CONTENT if ((list == null || list.size() == 0) && !plaETag.equals(HttpConstant.ZERO)) { logger.info("??"); return Response.noContent().build(); } else if (checkEtag && dateTer.compareTo(datePla) == 0) { // ?? logger.info("???"); return Response.notModified().build(); } else if (checkEtag && dateTer.compareTo(datePla) > 0) { logger.error("???"); throw new ApplicationException(ErrorConstant.ERROR10103, Response.Status.BAD_REQUEST); } // ? List<MsgMoldInfo> temp = new ArrayList<MsgMoldInfo>(); // ???? Iterator<MsgMoldInfo> it = list.iterator(); while (it.hasNext()) { MsgMoldInfo iMsgMoldInfo = it.next(); // ?? if (iMsgMoldInfo.getDel().equals(HttpConstant.MSGMOLD_DEL_FALSE)) { temp.add(iMsgMoldInfo); } } FindMsgMoldResp iFindMsgMoldResp = new FindMsgMoldResp(); iFindMsgMoldResp.setEtag(plaETag); iFindMsgMoldResp.setList(temp); return JacksonUtils.toJsonRuntimeException(iFindMsgMoldResp); }
From source file:com.virtusa.akura.reporting.validator.LateComersValidator.java
/** * Validates the user input for criteria. * * @param object - Populated object of AttendeesWrapperTemplate to validate * @param errors - contain errors related to fields. *//*from w w w . j a va 2 s . c o m*/ public void validate(Object object, Errors errors) { Date dateFrom = null; AttendeesWrapperTemplate attendeesWrapperTemplate = (AttendeesWrapperTemplate) object; if (attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getTimeInFrom().equals(VARIABLE_ZERO) || attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getTimeInTo().equals(VARIABLE_ZERO) || attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getDateFrom().equals(STRING_NULL) || attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getDateTo().equals(STRING_NULL)) { errors.rejectValue(TEACHER_LATE_ATTENDIES_TEMPLATE_TIME_IN_FROM, ERROR_MSG_MANDATORY_FIELD_REQUIRED); } Pattern datePattern = Pattern.compile(DATE_PATTERN); Matcher dateFromPatternMatcher = datePattern .matcher(attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getDateFrom()); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_YYYY_MM_DD); if (!attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getDateFrom().equals(STRING_NULL)) { if (!dateFromPatternMatcher.find()) { errors.rejectValue(DATE_FROM, ERROR_MSG_DATE_FIELD_INVALID); dateFrom = null; } else { try { dateFrom = sdf.parse(attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getDateFrom()); } catch (ParseException e) { e.printStackTrace(); } } } Matcher dateToPatternMatcher = datePattern .matcher(attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getDateTo()); if (!attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getDateTo().equals(STRING_NULL)) { if (!dateToPatternMatcher.find()) { errors.rejectValue(DATE_TO, ERROR_MSG_DATE_FIELD_INVALID); dateTo = null; } else { try { dateTo = sdf.parse(attendeesWrapperTemplate.getTeacherLateAttendiesTemplate().getDateTo()); } catch (ParseException e) { e.printStackTrace(); } } } else { dateTo = null; } if ((dateFrom != null) && (dateTo != null)) { if (dateFrom.after(new Date())) { errors.rejectValue(DATE_FROM, ERROR_FIELD_DATE_FIELD_INCORRECT_FUTURE_FROM); } if (dateTo.after(new Date())) { errors.rejectValue(DATE_TO, ERROR_FIELD_DATE_FIELD_INCORRECT_FUTURE_TO); } } if ((dateFrom != null) && (dateTo != null)) { if (dateFrom.compareTo(dateTo) > 0) { errors.rejectValue(DATE_TO, ERROR_MSG_DATE_FIELD_INCORRECT); } } }
From source file:com.virtusa.akura.reporting.validator.StudentWiseAttendanceValidator.java
/** * Validates the user input for criteria. * * @param object - Populated object of StudentWiseAttendanceTemplate to validate * @param errors - contain errors related to fields. *//*from ww w . j a v a 2s. c om*/ public void validate(Object object, Errors errors) { Date dateFrom = null; StudentWiseAttendanceTemplate studentWiseAttendanceTemplate = (StudentWiseAttendanceTemplate) object; if (studentWiseAttendanceTemplate.getStudentID().equals(VAR_STRING) || studentWiseAttendanceTemplate.getDateFrom().equals(STRING_NULL) || studentWiseAttendanceTemplate.getDateTo().equals(STRING_NULL)) { errors.rejectValue(STUDENT_ID, ERROR_MSG_MANDATORY_FIELD_REQUIRED); } String validatorPattern = ValidatorExpressionUtil.getValidatorPattern("REFORTING.STUDENTWISE.VALIDATOR"); Pattern studentIDPattern = Pattern.compile(validatorPattern); Matcher studentIDMatcher = studentIDPattern.matcher(studentWiseAttendanceTemplate.getStudentID()); if (!studentWiseAttendanceTemplate.getStudentID().equals(STRING_NULL) && !studentIDMatcher.find()) { errors.rejectValue(STUDENT_ID, ERROR_MSG_ADMISSION_FIELD_INVALID); } Pattern datePattern = Pattern.compile(DATE_PATTERN); Matcher dateFromPatternMatcher = datePattern.matcher(studentWiseAttendanceTemplate.getDateFrom()); SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD); if (!studentWiseAttendanceTemplate.getDateFrom().equals(STRING_NULL)) { if (!dateFromPatternMatcher.find()) { errors.rejectValue(DATE_FROM, ERROR_MSG_DATE_FIELD_INVALID); dateFrom = null; } else { try { dateFrom = sdf.parse(studentWiseAttendanceTemplate.getDateFrom()); } catch (ParseException e) { e.printStackTrace(); } } } Matcher dateToPatternMatcher = datePattern.matcher(studentWiseAttendanceTemplate.getDateTo()); if (!studentWiseAttendanceTemplate.getDateTo().equals(STRING_NULL)) { if (!dateToPatternMatcher.find()) { errors.rejectValue(DATE_TO, ERROR_MSG_DATE_FIELD_INVALID); dateTo = null; } else { try { dateTo = sdf.parse(studentWiseAttendanceTemplate.getDateTo()); } catch (ParseException e) { e.printStackTrace(); } } } else { dateTo = null; } if ((dateFrom != null) && (dateTo != null)) { if (dateFrom.after(new Date())) { errors.rejectValue(DATE_FROM, ERROR_FIELD_DATE_FIELD_INCORRECT_FUTURE_FROM); } if (dateTo.after(new Date())) { errors.rejectValue(DATE_TO, ERROR_FIELD_DATE_FIELD_INCORRECT_FUTURE_TO); } } if ((dateFrom != null) && (dateTo != null)) { if (dateFrom.compareTo(dateTo) > 0) { errors.rejectValue(DATE_TO, ERROR_MSG_DATE_FIELD_INCORRECT); } } }
From source file:com.virtusa.akura.reporting.validator.TeacherWiseAttendanceValidator.java
/** * Validates the user input for criteria. * * @param object - Populated object of TeacherWiseAttendanceTemplate to validate * @param errors - contain errors related to fields. *//*from w ww .j a v a 2 s . c o m*/ public void validate(Object object, Errors errors) { Date dateFrom = null; TeacherWiseAttendanceTemplate teacherWiseAttendanceTemplate = (TeacherWiseAttendanceTemplate) object; if (teacherWiseAttendanceTemplate.getTeacherNo().trim().equals(STRING_NULL) || teacherWiseAttendanceTemplate.getDateFrom().trim().equals(STRING_NULL) || teacherWiseAttendanceTemplate.getDateTo().trim().equals(STRING_NULL)) { errors.rejectValue(TEACHER_NO, ERROR_MSG_MANDATORY_FIELD_REQUIRED); } String validatorPattern = ValidatorExpressionUtil.getValidatorPattern("REFORTING.STAFFWISE.VALIDATOR"); Pattern idPattern = Pattern.compile(validatorPattern); Matcher idMatcher = idPattern.matcher(teacherWiseAttendanceTemplate.getTeacherNo()); if (!teacherWiseAttendanceTemplate.getTeacherNo().equals(STRING_NULL) && !idMatcher.find()) { errors.rejectValue(TEACHER_NO, ERROR_MSG_TEACHER_FIELD_INVALID); } Pattern datePattern = Pattern.compile(PATTERN_DATE); Matcher dateFromPatternMatcher = datePattern.matcher(teacherWiseAttendanceTemplate.getDateFrom()); SimpleDateFormat sdf = new SimpleDateFormat(YEAR_MONTH_DAY); if (!teacherWiseAttendanceTemplate.getDateFrom().equals(STRING_NULL)) { if (!dateFromPatternMatcher.find()) { errors.rejectValue(ATT_DATE_FROM, ERROR_MSG_DATE_FIELD_INVALID); dateFrom = null; } else { try { dateFrom = sdf.parse(teacherWiseAttendanceTemplate.getDateFrom()); } catch (ParseException e) { e.printStackTrace(); } } } Matcher dateToPatternMatcher = datePattern.matcher(teacherWiseAttendanceTemplate.getDateTo()); if (!teacherWiseAttendanceTemplate.getDateTo().equals(STRING_NULL)) { if (!dateToPatternMatcher.find()) { errors.rejectValue(ATT_DATE_TO, ERROR_MSG_DATE_FIELD_INVALID); dateTo = null; } else { try { dateTo = sdf.parse(teacherWiseAttendanceTemplate.getDateTo()); } catch (ParseException e) { e.printStackTrace(); } } } else { dateTo = null; } if ((dateFrom != null) && (dateTo != null)) { if (dateFrom.after(new Date())) { errors.rejectValue(ATT_DATE_FROM, ERROR_FIELD_DATE_FIELD_INCORRECT_FUTURE_FROM); } if (dateTo.after(new Date())) { errors.rejectValue(ATT_DATE_TO, ERROR_FIELD_DATE_FIELD_INCORRECT_FUTURE_TO); } } if ((dateFrom != null) && (dateTo != null)) { if (dateFrom.compareTo(dateTo) > 0) { errors.rejectValue(ATT_DATE_TO, ERROR_MSG_DATE_FIELD_INCORRECT); } } }
From source file:com.virtusa.akura.reporting.validator.TeacherWisePresentAndAbsentDaysValidator.java
/** * Validates the user input for criteria. * * @param object - Populated object of TeacherWiseAttendanceTemplate to validate * @param errors - contain errors related to fields. *//*from www .j a v a 2s. c o m*/ public void validate(Object object, Errors errors) { Date dateFrom = null; TeacherWisePresentAbsentTemplate teacherWisePresentAbsentTemplate = (TeacherWisePresentAbsentTemplate) object; if (teacherWisePresentAbsentTemplate.getTeacherRegNo().trim().equals("") || teacherWisePresentAbsentTemplate.getTeacherRegNo().equals("0") || teacherWisePresentAbsentTemplate.getDateFrom().trim().equals("") || teacherWisePresentAbsentTemplate.getDateTo().trim().equals("")) { errors.rejectValue(FIELD_NAME, REQUIRED_FIELD_ERROR); } Pattern regNoPattern = Pattern.compile(REGEX_REGNO_PATTERN); Matcher regNoPatternMatcher = regNoPattern.matcher(teacherWisePresentAbsentTemplate.getTeacherRegNo()); if (!teacherWisePresentAbsentTemplate.getTeacherRegNo().equals("") && !regNoPatternMatcher.find()) { errors.rejectValue(FIELD_NAME, INVALID_FIELD_ERROR); } Pattern datePattern = Pattern.compile(REGEX_DATE_PATTERN); Matcher dateFromPatternMatcher = datePattern.matcher(teacherWisePresentAbsentTemplate.getDateFrom()); if (!teacherWisePresentAbsentTemplate.getDateFrom().equals("")) { if (!dateFromPatternMatcher.find()) { errors.rejectValue(DATE_FROM_FIELD, INAVLID_DATE_ERROR); dateFrom = null; } else { try { dateFrom = DateUtil.getParseDate(teacherWisePresentAbsentTemplate.getDateFrom()); } catch (AkuraAppException e) { LOG.error("Error while parsing the date" + "-->" + e.toString()); } } } Matcher dateToPatternMatcher = datePattern.matcher(teacherWisePresentAbsentTemplate.getDateTo()); if (!teacherWisePresentAbsentTemplate.getDateTo().equals("")) { if (!dateToPatternMatcher.find()) { errors.rejectValue(DATE_TO_FIELD, INAVLID_DATE_ERROR); dateTo = null; } else { try { dateTo = DateUtil.getParseDate(teacherWisePresentAbsentTemplate.getDateTo()); } catch (AkuraAppException e) { LOG.error("Error while parsing the date" + "-->" + e.toString()); } } } else { dateTo = null; } if ((dateFrom != null) && (dateTo != null)) { if (dateFrom.after(new Date())) { errors.rejectValue(DATE_FROM_FIELD, ERROR_FIELD_DATE_FIELD_INCORRECT_FUTURE_FROM); } if (dateTo.after(new Date())) { errors.rejectValue(DATE_TO_FIELD, ERROR_FIELD_DATE_FIELD_INCORRECT_FUTURE_TO); } } if ((dateFrom != null) && (dateTo != null)) { if (dateFrom.compareTo(dateTo) > 0) { errors.rejectValue(DATE_TO_FIELD, INCORRECT_DATE_ERROR); } } }
From source file:skoa.helpers.Graficos.java
/**Funcion que pasa fecha-valor de la linea a introducir en el fichero de referencia**/ private void incluirDatos(String datos) { String fecha = "", valor = ""; int i = datos.indexOf("\t"); fecha = datos.substring(0, i);//ww w. j av a 2 s. com valor = datos.substring(i + 1); SimpleDateFormat formatoDelTexto = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date d = null; try { d = formatoDelTexto.parse(fecha); } catch (ParseException e1) { e1.printStackTrace(); } File archivo = new File(ruta + "unificado.txt"); FileReader fr = null; BufferedReader linea = null; String line; String ficheroTemporal = ruta + "diferenciaAplicada.txt"; try { BufferedWriter bw = new BufferedWriter(new FileWriter(ficheroTemporal, true)); //true, para guardar al final del fichero fr = new FileReader(archivo); linea = new BufferedReader(fr); //Se crea para leer las lineas String L; Boolean salir = false; int r = 0; while ((line = linea.readLine()) != null) { //Lectura del fichero L = ""; if (salir) L = line;//break; else { String fechaR = ""; int j = line.indexOf("\t"); fechaR = line.substring(0, j); Date dR = null; dR = formatoDelTexto.parse(fechaR); r = d.compareTo(dR); if (r == 0) { L = line + "\t" + valor; //fechas iguales, aade el valor del otro fichero. salir = true; } else if (r < 0) { L = fecha + "\t" + valor + "\n" + line; salir = true; } else if (r > 0) L = line; //si la fecha es mayor, se trata en la siguiente iteracion, si la hay. } bw.write(L + "\n"); } //Fin while if (r > 0) { //Ultima linea, si es mayor, no se escribio en el bucle. L = fecha + "\t" + valor; bw.write(L + "\n"); } bw.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (null != fr) fr.close(); //Se cierra si todo va bien. archivo.delete(); File archivo2 = new File(ruta + "diferenciaAplicada.txt"); File f = new File(ruta + "unificado.txt"); archivo2.renameTo(f); } catch (Exception e2) { //Sino salta una excepcion. e2.printStackTrace(); } } }
From source file:org.apache.nifi.web.api.dto.DtoFactory.java
/** * Creates a BulletinBoardDTO for the specified bulletins. * * @param bulletins bulletins/* w w w .j av a2s . c o m*/ * @return dto */ public BulletinBoardDTO createBulletinBoardDto(final List<BulletinDTO> bulletins) { // sort the bulletins Collections.sort(bulletins, new Comparator<BulletinDTO>() { @Override public int compare(BulletinDTO bulletin1, BulletinDTO bulletin2) { if (bulletin1 == null && bulletin2 == null) { return 0; } else if (bulletin1 == null) { return 1; } else if (bulletin2 == null) { return -1; } final Date timestamp1 = bulletin1.getTimestamp(); final Date timestamp2 = bulletin2.getTimestamp(); if (timestamp1 == null && timestamp2 == null) { return 0; } else if (timestamp1 == null) { return 1; } else if (timestamp2 == null) { return -1; } else { return timestamp1.compareTo(timestamp2); } } }); // create the bulletin board final BulletinBoardDTO bulletinBoard = new BulletinBoardDTO(); bulletinBoard.setBulletins(bulletins); bulletinBoard.setGenerated(new Date()); return bulletinBoard; }
From source file:Implement.Service.ProviderServiceImpl.java
@Override public String getSales(String data, int providerID) throws ParseException { int packageID; Date fromDate;//from w w w . ja va 2 s . c o m Date toDate; Calendar calendar = Calendar.getInstance(); DateFormat MMddyyyyFormat = new SimpleDateFormat("MM/dd/yyyy"); DateFormat ddMMyyyyFormat = new SimpleDateFormat("dd/MM/yyyy"); ddMMyyyyFormat.setLenient(false); if (data == null) { packageID = 0; calendar.set(Calendar.DAY_OF_MONTH, 1); fromDate = calendar.getTime(); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); toDate = calendar.getTime(); } else { JsonObject jsonObject = gson.fromJson(data, JsonObject.class); String fromDateStr = jsonObject.get("fromDate").getAsString(); String toDateStr = jsonObject.get("toDate").getAsString(); packageID = jsonObject.get("packageID").getAsInt(); fromDate = MMddyyyyFormat.parse(fromDateStr); toDate = MMddyyyyFormat.parse(toDateStr); } List<BookingDTO> bookings = bookingDAO.getSales(packageID, providerID); List<Sale> sales = new ArrayList<Sale>(); Date toDay = new Date(); DateFormat MMddyyyyHHmmssFormat = new SimpleDateFormat("MM/dd/yyyy HH:ss:mm"); MMddyyyyFormat.setLenient(false); for (BookingDTO booking : bookings) { String bookingDateStr = booking.getBookingDate().substring(0, 10); Date bookingDate = MMddyyyyFormat.parse(bookingDateStr); if (bookingDate.compareTo(fromDate) >= 0 && bookingDate.compareTo(toDate) <= 0) { int tripperID = booking.getTripperID(); String tripperName = booking.getTripperFirstName() + " " + booking.getTripperLastName(); int mainPackageID = booking.getPackageID(); String packageName = booking.getPackageName(); int status; String paidDateStr = booking.getPaid(); if (paidDateStr != null && !paidDateStr.equals("none")) { status = 1; } else { status = 4; } double revenue = (booking.getAdultPrice() * booking.getNumberOfAdults() + booking.getChildPrice() * booking.getNumberOfChilds()) * (100 - booking.getYouTripperPercentage() - booking.getProfitPercentage()) / 100; Sale sale = new Sale(bookingDateStr, tripperID, tripperName, mainPackageID, packageName, status, revenue); sales.add(sale); } } return gson.toJson(sales); }
From source file:org.jahia.ajax.gwt.content.server.JahiaContentManagementServiceImpl.java
private void sortVersions(List<GWTJahiaNodeVersion> versions) { final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); Collections.sort(versions, new Comparator<GWTJahiaNodeVersion>() { @Override//from w ww.java 2 s. c o m public int compare(GWTJahiaNodeVersion o1, GWTJahiaNodeVersion o2) { String[] strings1 = VERSION_AT_PATTERN.split(o1.getLabel()); String[] strings2 = VERSION_AT_PATTERN.split(o2.getLabel()); if (strings1.length == 2 && strings2.length == 2) { try { Date dateV2 = simpleDateFormat.parse(strings2[1]); o2.setDate(dateV2); Date dateV1 = simpleDateFormat.parse(strings1[1]); o1.setDate(dateV1); return dateV2.compareTo(dateV1); } catch (ParseException e) { return o1.getLabel().compareTo(o2.getLabel()); } } else { return o1.getLabel().compareTo(o2.getLabel()); } } }); }
From source file:org.nuclos.server.ruleengine.RuleInterface.java
/** * checks if dateFrom is before dateUntil or if one of them is null * @param dateFrom//from w w w . java 2 s .c om * @param dateUntil * @return true if dateFrom is before dateUntil or one of them is null */ public boolean isPeriodValid(Date dateFrom, Date dateUntil) { return dateFrom == null || dateUntil == null || dateFrom.compareTo(dateUntil) <= 0; }