Example usage for java.util Calendar after

List of usage examples for java.util Calendar after

Introduction

In this page you can find the example usage for java.util Calendar after.

Prototype

public boolean after(Object when) 

Source Link

Document

Returns whether this Calendar represents a time after the time represented by the specified Object.

Usage

From source file:com.square.adherent.noyau.service.implementations.AdherentServiceImpl.java

@Override
public InfosOptionsAdherentDto getInfosOptionsAdherent(Long uidPersonne) {
    if (uidPersonne == null) {
        throw new TechnicalException(
                messageSourceUtil.get(MessageKeyUtil.ERROR_GET_INFOS_ESPACE_ADHERENT_UID_PERSONNE_NULL));
    }/*  w w w.  j a  v  a2  s. c om*/
    final List<Option> optionsAdherent = optionDao.getOptionsAdherent(uidPersonne);
    // On rcupre les coordonnes de l'adhrent  partir de Square.
    final CoordonneesDto coordonneesAdherent = personneService.rechercherCoordonneesParIdPersonne(uidPersonne);
    // On vrifie que l'adhrent possde des coordonnes et un email.
    if (coordonneesAdherent == null) {
        throw new TechnicalException(
                messageSourceUtil.get(MessageKeyUtil.ERROR_ENVOYER_MOT_DE_PASSE_COORDONNEES_PERSONNE_NULL,
                        new String[] { uidPersonne.toString() }));
    }

    // Mapping automatique des infos
    final InfosOptionsAdherentDto infosOptionsAdherentDto = new InfosOptionsAdherentDto();
    // On dtermine la date de dernire modification des options
    Calendar dateDerniereModificationOptions = null;
    for (Option option : optionsAdherent) {
        final Calendar dateModificationOption = option.getDateModification();
        if (dateDerniereModificationOptions == null
                || dateModificationOption.after(dateDerniereModificationOptions)) {
            dateDerniereModificationOptions = dateModificationOption;
        }
    }
    infosOptionsAdherentDto.setDateModificationOptions(dateDerniereModificationOptions);
    final List<OptionAdherentDto> listeOptions = mapperDozerBean.mapList(optionsAdherent,
            OptionAdherentDto.class);
    infosOptionsAdherentDto.setListeOptions(listeOptions);
    return infosOptionsAdherentDto;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.exams.RoomSearchDA.java

public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    DynaValidatorForm roomSearchForm = (DynaValidatorForm) form;

    // date//ww w. j a  va2  s.  co  m
    Calendar searchDate = Calendar.getInstance();
    Integer day = new Integer((String) roomSearchForm.get("day"));
    Integer month = new Integer((String) roomSearchForm.get("month"));
    Integer year = new Integer((String) roomSearchForm.get("year"));
    request.setAttribute("day", day.toString());
    request.setAttribute("month", month.toString());
    request.setAttribute("year", year.toString());
    searchDate.set(Calendar.YEAR, year.intValue());
    searchDate.set(Calendar.MONTH, month.intValue() - 1);
    searchDate.set(Calendar.DAY_OF_MONTH, day.intValue());
    if (searchDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        ActionError actionError = new ActionError("error.sunday");
        ActionErrors actionErrors = new ActionErrors();
        actionErrors.add("error.sunday", actionError);
        saveErrors(request, actionErrors);
        return prepare(mapping, form, request, response);
    }

    // exam start time
    Calendar searchStartTime = Calendar.getInstance();
    Integer startHour = new Integer((String) roomSearchForm.get("beginningHour"));
    Integer startMinute = new Integer((String) roomSearchForm.get("beginningMinute"));
    request.setAttribute("beginningHour", startHour.toString());
    request.setAttribute("beginningMinute", startMinute.toString());
    searchStartTime.set(Calendar.HOUR_OF_DAY, startHour.intValue());
    searchStartTime.set(Calendar.MINUTE, startMinute.intValue());
    searchStartTime.set(Calendar.SECOND, 0);

    // exam end time
    Calendar searchEndTime = Calendar.getInstance();
    Integer endHour = new Integer((String) roomSearchForm.get("endHour"));
    Integer endMinute = new Integer((String) roomSearchForm.get("endMinute"));
    request.setAttribute("endHour", endHour.toString());
    request.setAttribute("endMinute", endMinute.toString());
    searchEndTime.set(Calendar.HOUR_OF_DAY, endHour.intValue());
    searchEndTime.set(Calendar.MINUTE, endMinute.intValue());
    searchEndTime.set(Calendar.SECOND, 0);

    if (searchStartTime.after(searchEndTime)) {
        ActionError actionError = new ActionError("error.timeSwitched");
        ActionErrors actionErrors = new ActionErrors();
        actionErrors.add("error.timeSwitched", actionError);
        saveErrors(request, actionErrors);
        return prepare(mapping, form, request, response);
    }

    int dayOfWeekInt = searchDate.get(Calendar.DAY_OF_WEEK);
    DiaSemana dayOfWeek = new DiaSemana(dayOfWeekInt);

    List<InfoRoom> availableInfoRoom = null;
    availableInfoRoom = SpaceUtils.allocatableSpace(YearMonthDay.fromCalendarFields(searchDate),
            YearMonthDay.fromCalendarFields(searchDate), HourMinuteSecond.fromCalendarFields(searchStartTime),
            HourMinuteSecond.fromCalendarFields(searchEndTime), dayOfWeek, null, null, false);
    String sdate = roomSearchForm.get("day") + "/" + roomSearchForm.get("month") + "/"
            + roomSearchForm.get("year");
    String startTime = roomSearchForm.get("beginningHour") + ":" + roomSearchForm.get("beginningMinute");
    String endTime = roomSearchForm.get("endHour") + ":" + roomSearchForm.get("endMinute");
    request.setAttribute(PresentationConstants.DATE, sdate);
    request.setAttribute(PresentationConstants.START_TIME, startTime);
    request.setAttribute(PresentationConstants.END_TIME, endTime);

    Integer exam = null;
    Integer normal = null;
    List<InfoRoom> newAvailableInfoRoom = new ArrayList<InfoRoom>();
    if (availableInfoRoom != null && !availableInfoRoom.isEmpty()) {
        try {
            exam = new Integer((String) roomSearchForm.get("exam"));
        } catch (NumberFormatException ex) {
            // the user didn't speciefy a exam minimum capacity
        }
        try {
            normal = new Integer((String) roomSearchForm.get("normal"));
        } catch (NumberFormatException ex) {
            // the user didn't speciefy a normal minimum capacity
        }
        if (normal != null || exam != null) {
            Iterator<InfoRoom> iter = availableInfoRoom.iterator();
            while (iter.hasNext()) {
                InfoRoom elem = iter.next();
                if (!((normal != null && elem.getCapacidadeNormal().intValue() < normal.intValue())
                        || (exam != null && elem.getCapacidadeExame().intValue() < exam.intValue()))) {
                    newAvailableInfoRoom.add(elem);
                }
            }
        } else {
            newAvailableInfoRoom = availableInfoRoom;
        }
    }
    if (newAvailableInfoRoom != null && !newAvailableInfoRoom.isEmpty()) {
        Collections.sort(newAvailableInfoRoom, new BeanComparator("nome"));
        String[] availableRoomId = new String[newAvailableInfoRoom.size()];
        Iterator<InfoRoom> iter = newAvailableInfoRoom.iterator();
        int i = 0;
        while (iter.hasNext()) {
            InfoRoom elem = iter.next();
            availableRoomId[i] = elem.getExternalId().toString();
        }
        request.setAttribute(PresentationConstants.AVAILABLE_ROOMS_ID, availableRoomId);

    }

    request.setAttribute(PresentationConstants.AVAILABLE_ROOMS, newAvailableInfoRoom);
    return mapping.findForward("showRooms");
}

From source file:org.nuxeo.ecm.platform.rendition.service.TestRenditionService.java

@Test
public void shouldPreventAdminFromReusingOthersNonVersionedStoredRendition() throws Exception {
    DocumentModel folder = createFolderWithChildren();
    String renditionName = ZIP_TREE_EXPORT_RENDITION_DEFINITION;
    Rendition totoRendition;/* w w  w . j  av a 2 s  .c  o  m*/

    // get rendition as non-admin user 'toto'
    NuxeoPrincipal totoPrincipal = Framework.getService(UserManager.class).getPrincipal("toto");
    try (CoreSession userSession = coreFeature.openCoreSession(totoPrincipal)) {
        folder = userSession.getDocument(folder.getRef());
        totoRendition = renditionService.getRendition(folder, renditionName, true);
        assertTrue(totoRendition.isStored());
    }

    nextTransaction();
    eventService.waitForAsyncCompletion();

    coreFeature.getStorageConfiguration().maybeSleepToNextSecond();

    // now get rendition as admin user 'Administrator'
    folder = session.getDocument(folder.getRef());
    Rendition rendition = renditionService.getRendition(folder, renditionName, true);
    assertTrue(rendition.isStored());
    assertTrue(rendition.isCompleted());

    // verify Administrator's rendition is different from user's rendition, is larger than user's rendition,
    // and was created later
    assertNotEquals(rendition.getHostDocument().getRef(), totoRendition.getHostDocument().getRef());
    long adminZipEntryCount = countZipEntries(new ZipInputStream(rendition.getBlob().getStream()));
    long totoZipEntryCount = countZipEntries(new ZipInputStream(totoRendition.getBlob().getStream()));
    assertTrue(
            String.format("Admin rendition entry count %s should be greater than user rendition entry count %s",
                    adminZipEntryCount, totoZipEntryCount),
            adminZipEntryCount > totoZipEntryCount);
    Calendar adminModificationDate = rendition.getModificationDate();
    Calendar totoModificationDate = totoRendition.getModificationDate();
    assertTrue(
            String.format("Admin rendition modif date %s should be after user rendition modif date %s",
                    adminModificationDate.toInstant(), totoModificationDate.toInstant()),
            adminModificationDate.after(totoModificationDate));
}

From source file:com.square.adherent.noyau.service.implementations.AdherentServiceImpl.java

/**
 * {@inheritDoc}/*from   w  ww .  j  a  v  a  2s. c om*/
 */
@Override
public InfosEspaceAdherentDto getInfosEspaceAdherent(Long uidPersonne) {
    if (uidPersonne == null) {
        throw new TechnicalException(
                messageSourceUtil.get(MessageKeyUtil.ERROR_GET_INFOS_ESPACE_ADHERENT_UID_PERSONNE_NULL));
    }
    // On rcupre les infos de connexion de l'adhrent
    final EspaceClientInternet connexionAdherent = espaceClientInternetDao
            .getEspaceClientInternetClient(uidPersonne);
    if (connexionAdherent == null) {
        throw new TechnicalException(
                messageSourceUtil.get(MessageKeyUtil.ERROR_GET_INFOS_ESPACE_ADHERENT_UID_PERSONNE_NULL,
                        new String[] { uidPersonne.toString() }));
    }
    final List<Option> optionsAdherent = optionDao.getOptionsAdherent(uidPersonne);
    // On rcupre les coordonnes de l'adhrent  partir de Square.
    final CoordonneesDto coordonneesAdherent = personneService.rechercherCoordonneesParIdPersonne(uidPersonne);
    // On vrifie que l'adhrent possde des coordonnes et un email.
    if (coordonneesAdherent == null) {
        throw new TechnicalException(
                messageSourceUtil.get(MessageKeyUtil.ERROR_ENVOYER_MOT_DE_PASSE_COORDONNEES_PERSONNE_NULL,
                        new String[] { uidPersonne.toString() }));
    }

    // Mapping automatique des infos
    final InfosEspaceAdherentDto infosEspaceAdherentDto = mapperDozerBean.map(connexionAdherent,
            InfosEspaceAdherentDto.class);
    if (!coordonneesAdherent.getEmails().isEmpty()) {
        final EmailDto emailAdherent = coordonneesAdherent.getEmails().get(0);
        // Mapping manuel de l'adresse email de l'adhrent.
        infosEspaceAdherentDto.setEmail(emailAdherent.getAdresse());
    }
    // On dtermine la date de dernire modification des options
    Calendar dateDerniereModificationOptions = null;
    for (Option option : optionsAdherent) {
        final Calendar dateModificationOption = option.getDateModification();
        if (dateDerniereModificationOptions == null
                || dateModificationOption.after(dateDerniereModificationOptions)) {
            dateDerniereModificationOptions = dateModificationOption;
        }
    }
    infosEspaceAdherentDto.setDateModificationOptions(dateDerniereModificationOptions);
    final List<OptionAdherentDto> listeOptions = mapperDozerBean.mapList(optionsAdherent,
            OptionAdherentDto.class);
    infosEspaceAdherentDto.setListeOptions(listeOptions);
    return infosEspaceAdherentDto;
}

From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java

private synchronized void updateRecursos() {
    if (updateRecursos != null) {
        updateRecursos.cancel(true);//from   w  w w. j  a v  a  2  s.c  om
    }

    updateRecursos = new SwingWorker<String, String>() {

        private String[] recursosEnPeriodos = new String[0];
        private Incidencia[] incidenciasEnPeriodos = new Incidencia[0];

        @Override
        protected String doInBackground() throws Exception {
            cargando.setIcon(LogicConstants.getIcon("anim_calculando"));
            Calendar ini = null;
            Calendar fin = null;
            if (!soloUltimas.isSelected()) {
                ini = getFechaIni();
                fin = getFechaFin();
            }

            if (ini != null && fin != null && ini.after(fin)) {
                return null;
            }

            List<Long> idZonas = new ArrayList<Long>();
            // for (Object o : zona.getSelectedValues()) {
            // if (o instanceof Zona) {
            // idZonas.add(((Zona) o).getId());
            // }
            // }

            long[] zonas = new long[idZonas.size()];
            for (int i = 0; i < zonas.length; i++) {
                zonas[i] = idZonas.get(i);
            }

            recursosEnPeriodos = getRecursosEnPeriodo(Authentication.getUsuario().getNombreUsuario(), ini, fin,
                    zonas);

            incidenciasEnPeriodos = getIncidenciasEnPeriodo(Authentication.getUsuario().getNombreUsuario(), ini,
                    fin, zonas);

            return null;
        }

        @Override
        protected void done() {
            synchronized (recursos) {
                log.trace("Cargamos los recursos");
                ((DefaultListModel) recursos.getModel()).removeAllElements();
                for (String recurso : recursosEnPeriodos) {
                    log.trace("Mostramos en la ventana de consulta " + recurso);
                    ((DefaultListModel) recursos.getModel()).addElement(recurso);
                }
            }
            synchronized (incidencias) {
                ((DefaultListModel) incidencias.getModel()).removeAllElements();
                for (Incidencia i : incidenciasEnPeriodos) {
                    log.trace("Mostramos en la ventana de consulta " + i);
                    ((DefaultListModel) incidencias.getModel()).addElement(i);
                }
            }
            limpiar.setEnabled(true);
            recursos.repaint();
            incidencias.repaint();
            cargando.setIcon(LogicConstants.getIcon("48x48_transparente"));
            cargando.repaint();
            updateRecursos = null;
        }
    };
    updateRecursos.execute();

}

From source file:stg.utils.immutable.Day.java

/**
 * The number of months between this and day parameter
 * //from   w ww.  j a v  a  2 s . c  o m
 * @param b
 *            any date
 * @return the number of days between this and day parameter and b (> 0 if
 *         this day comes after b)
 */
public int monthsBetween(Day b) {
    Calendar gcThisDay = getCalendarInstance(tzone);
    gcThisDay.setTime(this.getUtilDate());
    Calendar gcTarget = getCalendarInstance(tzone);
    gcTarget.setTime(b.getUtilDate());

    int iMonthsBetween = 0;
    if (gcThisDay.after(gcTarget)) {
        while (gcThisDay.after(gcTarget)) {
            gcTarget.add(Calendar.MONTH, 1);
            if (gcThisDay.after(gcTarget))
                iMonthsBetween++;
            if (gcThisDay.equals(gcTarget)) {
                iMonthsBetween++;
                break;
            }
        }
    } else if (gcThisDay.before(gcTarget)) {
        while (gcThisDay.before(gcTarget)) {
            gcThisDay.add(Calendar.MONTH, 1);
            if (gcThisDay.before(gcTarget)) {
                iMonthsBetween++;
            } else if (gcThisDay.equals(gcTarget)) {
                iMonthsBetween++;
                break;
            }
        }
    }

    return (iMonthsBetween);
}

From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java

/**
 * List events./*  w  ww  .  ja va  2 s  . c o  m*/
 * 
 * @param thermostatId
 *            the thermostat id
 * @param algoId
 *            the algo id
 * @param startTime
 *            the start time
 * @return the list
 * @see com.ecofactor.qa.automation.algorithm.service.DataService#listEvents(java.lang.Integer,
 *      int, java.util.Calendar)
 */
@Override
public List<PartitionedThermostatEvent> listEvents(Integer thermostatId, int algoId, Calendar startTime) {

    loadEvents(thermostatId);
    List<PartitionedThermostatEvent> events = new ArrayList<PartitionedThermostatEvent>();
    Calendar startTimeUTC = DateUtil.copyToUTC(startTime);
    Set<Calendar> timeSet = timeEventMap.keySet();
    for (Calendar time : timeSet) {
        PartitionedThermostatEvent event = timeEventMap.get(time);
        if (time.after(startTimeUTC) && event.getAlgorithmId() == algoId) {
            events.add(event);
        }
    }

    return events;
}

From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java

/**
 * List events.//from   w  ww .j  a v a 2  s. c  o m
 * 
 * @param thermostatId
 *            the thermostat id
 * @param algoId
 *            the algo id
 * @param startTime
 *            the start time
 * @param endTime
 *            the end time
 * @return the list
 * @see com.ecofactor.qa.automation.algorithm.service.DataService#listEvents(java.lang.Integer,
 *      int, java.util.Calendar, java.util.Calendar)
 */
@Override
public List<PartitionedThermostatEvent> listEvents(Integer thermostatId, int algoId, Calendar startTime,
        Calendar endTime) {

    loadEvents(thermostatId);
    List<PartitionedThermostatEvent> events = new ArrayList<PartitionedThermostatEvent>();
    Set<Calendar> timeSet = timeEventMap.keySet();
    for (Calendar time : timeSet) {
        PartitionedThermostatEvent event = timeEventMap.get(time);
        if (time.after(startTime) && time.before(endTime) && event.getAlgorithmId() == algoId) {
            events.add(event);
        }
    }

    return events;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DateComparator.java

/**
 * Return <code>true</code> if left operand is strictly after right operand, or if any of the operand is null, <code>false</code> otherwise
 *
 *
 * @param leftOperandValue the <code>Calendar</code> value for the left operand
 * @param rightOperandValue the <code>Calendar</code> value for the right operand
 * @param leastPrecision the least precise precision of the 2 dates
 * @return <code>true</code> if left operand is strictly after right operand, or if any of the operand is null, <code>false</code> otherwise
 *///from  w ww. j ava 2  s. c om
private boolean isGreaterThan(final Calendar leftOperandValue, final Calendar rightOperandValue,
        final String leastPrecision) {
    if (leftOperandValue == null || rightOperandValue == null) {
        return true;
    } else {

        if (PRECISION_YEAR.equals(leastPrecision)) {
            // if the years are equal, or left year > right year then consider it true
            return leftOperandValue.get(Calendar.YEAR) >= rightOperandValue.get(Calendar.YEAR);

        } else if (PRECISION_MONTH.equals(leastPrecision)) {
            // if left year > right year then true; if left year = right year and left month >= right year then true
            return (leftOperandValue.get(Calendar.YEAR) > rightOperandValue.get(Calendar.YEAR))
                    || (leftOperandValue.get(Calendar.YEAR) == rightOperandValue.get(Calendar.YEAR)
                            && leftOperandValue.get(Calendar.MONTH) >= rightOperandValue.get(Calendar.MONTH));

        } else {
            // day precision or unknown precision, use full date
            return leftOperandValue.after(rightOperandValue);
        }
    }
}