Example usage for java.util ArrayList isEmpty

List of usage examples for java.util ArrayList isEmpty

Introduction

In this page you can find the example usage for java.util ArrayList isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:Controladores.controladorProjeto.java

@RequestMapping(value = "salvar-projeto-restrito", produces = "text/html; charset=UTF-8")
@ResponseBody// ww w .  ja  va2s  . c o m
public String salvarProjeto(Projeto projeto, BindingResult result, HttpSession sessao,
        HttpServletRequest request, String operacao) {

    try {
        HashMap<String, String> erros = new HashMap<String, String>();
        ArrayList<Tag> funcProjeto = funcionariosProjeto(sessao);

        if (projeto.getNome().trim().length() == 0) {
            erros.put("erroNomeProjeto", "Informe o nome do projeto");
        }
        if (projeto.getDescricao().trim().length() == 0) {
            erros.put("erroDescricaoProjeto", "Informe a descrio do projeto");
        }
        if (funcProjeto.isEmpty()) {
            erros.put("erroFuncionariosProjeto", "Selecione ao menos um funcionrio para o projeto");
        }

        int projetoId = 0;

        if (erros.isEmpty()) {
            if (operacao.equalsIgnoreCase("I")) {
                projeto.setDtcriacao(new Date());
            } else {
                projeto.setDtalteracao(new Date());
            }

            Funcionario f = (Funcionario) sessao.getAttribute("funcionario");
            projeto.setUsercriador(f);

            projetoId = ProjetoDAO.salvarProjeto(projeto, funcProjeto, operacao);
        }

        Gson gson = new Gson();
        JsonObject myObj = new JsonObject();

        if (operacao.equalsIgnoreCase("I")) {
            myObj.addProperty("projetoId", projetoId);
        }

        myObj.addProperty("sucesso", erros.isEmpty());
        JsonElement objetoErrosEmJson = gson.toJsonTree(erros);
        myObj.add("erros", objetoErrosEmJson);

        return myObj.toString();
    } catch (Exception erro) {
        return null;
    }
}

From source file:asteroidtracker.AsteroidTrackerSpeechlet.java

/**
 * Prepares the speech to reply to the user. Obtain events from NeoWs for the date specified
 * by the user (or for today's date, if no date is specified), and return those events in both
 * speech and SimpleCard format./* w  w  w  .j a va  2 s. com*/
 * 
 * @param intent
 *            the intent object which contains the date slot
 * @param session
 *            the session object
 * @return SpeechletResponse object with voice/card response to return to the user
 */
private SpeechletResponse handleFirstEventRequest(Intent intent, Session session) {
    Calendar calendar = getCalendar(intent);
    String speechOutput;

    if (calendar == null) {
        speechOutput = "Invalid date, please try again. For example, you could say give me events for today, or give events for July fourth, 2015.";

        // Create the plain text output
        SsmlOutputSpeech outputSpeech = new SsmlOutputSpeech();
        outputSpeech.setSsml(buildSpeechOutputMarkup(speechOutput));

        return SpeechletResponse.newTellResponse(outputSpeech);
    }

    Date datetime = calendar.getTime();

    String month = MONTH_NAMES[calendar.get(Calendar.MONTH)];
    String date = Integer.toString(calendar.get(Calendar.DATE));
    String year = Integer.toString(calendar.get(Calendar.YEAR));

    String speechPrefixContent = "<p>For " + month + " " + date + ", " + year + "</p> ";
    String cardPrefixContent = "For " + month + " " + date + ", " + year + ", ";
    String cardTitle = "Asteroids on " + month + " " + date + ", " + year + ", ";

    ArrayList<String> events = getAsteroidInfo(new SimpleDateFormat("yyyy-MM-dd").format(datetime));

    if (events.isEmpty()) {
        speechOutput = "There is a problem connecting to the NASA A.P.I at this time."
                + " Please try again later.";

        // Create the plain text output
        SsmlOutputSpeech outputSpeech = new SsmlOutputSpeech();
        outputSpeech.setSsml(buildSpeechOutputMarkup(speechOutput));

        return SpeechletResponse.newTellResponse(outputSpeech);
    }

    else {
        StringBuilder speechOutputBuilder = new StringBuilder();
        speechOutputBuilder.append(speechPrefixContent);
        StringBuilder cardOutputBuilder = new StringBuilder();
        cardOutputBuilder.append(cardPrefixContent);

        for (int i = 0; i < PAGINATION_SIZE; i++) {
            if (events.size() > i) {
                speechOutputBuilder.append("<p>");
                speechOutputBuilder.append(events.get(i));
                speechOutputBuilder.append("</p> ");
                cardOutputBuilder.append(events.get(i));
                cardOutputBuilder.append("\n");
            }
        }

        speechOutputBuilder.append(" Want more asteroid information?");
        cardOutputBuilder.append(" Want more asteroid information?");
        speechOutput = speechOutputBuilder.toString();

        // Create the Simple card content.
        SimpleCard card = new SimpleCard();
        card.setTitle(cardTitle);
        card.setContent(cardOutputBuilder.toString());

        // After reading the first event, set the count to 1 and add the events
        // to the session attributes
        session.setAttribute(SESSION_INDEX, PAGINATION_SIZE);
        session.setAttribute(SESSION_TEXT, events);

        SpeechletResponse response = newAskResponse(buildSpeechOutputMarkup(speechOutput), true,
                INFORMATION_TEXT, false);
        response.setCard(card);
        return response;
    }
}

From source file:net.sourceforge.fenixedu.dataTransferObject.inquiries.StudentInquiryBean.java

private void fillTeachersInquiriesWithTeachers(final ExecutionCourse executionCourse,
        final Set<ShiftType> shiftTypes, StudentInquiryTemplate studentTeacherInquiryTemplate) {
    Map<Person, Map<ShiftType, StudentTeacherInquiryBean>> teachersShifts = new HashMap<Person, Map<ShiftType, StudentTeacherInquiryBean>>();
    Map<ShiftType, Double> allTeachingServicesShiftType = null;
    Set<ShiftType> nonAssociatedTeachersShiftTypes = null;
    for (final Professorship professorship : executionCourse.getProfessorshipsSet()) {

        final Person person = professorship.getPerson();
        if (!teachersShifts.containsKey(person)) {
            teachersShifts.put(person, new HashMap<ShiftType, StudentTeacherInquiryBean>());
        }/*w  w w. j ava 2s .c om*/

        final Map<ShiftType, StudentTeacherInquiryBean> teacherShift = teachersShifts.get(person);
        final AffiliatedTeacherDTO teacherDTO = new AffiliatedTeacherDTO(person);

        //       Teacher teacher = person.getTeacher();
        //       boolean mandatoryTeachingService = false;
        //       if (teacher != null && teacher.isTeacherProfessorCategory(executionCourse.getExecutionPeriod())) {
        //      mandatoryTeachingService = true;
        //       }

        Map<ShiftType, Double> shiftTypesPercentageMap = new HashMap<ShiftType, Double>();
        for (DegreeTeachingService degreeTeachingService : professorship.getDegreeTeachingServicesSet()) {
            for (ShiftType shiftType : degreeTeachingService.getShift().getTypes()) {
                Double percentage = shiftTypesPercentageMap.get(shiftType);
                if (percentage == null) {
                    percentage = degreeTeachingService.getPercentage();
                } else {
                    percentage += degreeTeachingService.getPercentage();
                }
                shiftTypesPercentageMap.put(shiftType, percentage);
            }
        }
        for (NonRegularTeachingService nonRegularTeachingService : professorship
                .getNonRegularTeachingServicesSet()) {
            for (ShiftType shiftType : nonRegularTeachingService.getShift().getTypes()) {
                Double percentage = shiftTypesPercentageMap.get(shiftType);
                if (percentage == null) {
                    percentage = nonRegularTeachingService.getPercentage();
                } else {
                    percentage += nonRegularTeachingService.getPercentage();
                }
                shiftTypesPercentageMap.put(shiftType, percentage);
            }
        }

        for (ShiftType shiftType : shiftTypesPercentageMap.keySet()) {
            Double percentage = shiftTypesPercentageMap.get(shiftType);
            if (percentage >= 20) {
                if (!teacherShift.containsKey(shiftType)) {
                    teacherShift.put(shiftType, new StudentTeacherInquiryBean(teacherDTO, executionCourse,
                            shiftType, studentTeacherInquiryTemplate));
                }
            }
        }

        if (shiftTypesPercentageMap.isEmpty() /* && !mandatoryTeachingService */) {
            if (allTeachingServicesShiftType == null) {
                allTeachingServicesShiftType = getAllDegreeTeachingServices(executionCourse);
            }
            if (nonAssociatedTeachersShiftTypes == null) {
                nonAssociatedTeachersShiftTypes = getNonAssociatedTeachersShiftTypes(executionCourse);
            }
            for (final ShiftType shiftType : shiftTypes) {
                Double shiftTypePercentage = allTeachingServicesShiftType.get(shiftType);
                if (shiftTypePercentage == null || shiftTypePercentage < 100.0
                        || nonAssociatedTeachersShiftTypes.contains(shiftType)) {
                    teacherShift.put(shiftType, new StudentTeacherInquiryBean(teacherDTO, executionCourse,
                            shiftType, studentTeacherInquiryTemplate));
                }
            }
        }
    }
    for (Entry<Person, Map<ShiftType, StudentTeacherInquiryBean>> entry : teachersShifts.entrySet()) {
        ArrayList<StudentTeacherInquiryBean> studentTeachers = new ArrayList<StudentTeacherInquiryBean>(
                entry.getValue().values());
        Collections.sort(studentTeachers, new BeanComparator("shiftType"));
        if (!studentTeachers.isEmpty()) {
            getTeachersInquiries().put(new AffiliatedTeacherDTO(entry.getKey()), studentTeachers);
        }
    }
}

From source file:co.carlosandresjimenez.gotit.backend.controller.GotItSvc.java

@RequestMapping(value = FOLLOWING_LIST_PATH, method = RequestMethod.GET)
public @ResponseBody ArrayList<User> getFollowingList(HttpServletRequest request) {
    String userEmail = (String) request.getAttribute("email");

    if (userEmail == null || userEmail.isEmpty()) {
        return null; // RESPONSE_STATUS_AUTH_REQUIRED;
    }//w w  w. j a va  2  s. co  m

    List<Following> followingList = followingRepository.findFollowingUsers(userEmail, Following.APPROVED);
    ArrayList<User> users = Lists.newArrayList();

    for (Following following : followingList)
        users.add(findUser(following.getFollowingUserEmail(), true));

    if (users.isEmpty())
        return null;

    return users;
}

From source file:com.espertech.esper.core.service.EPStatementImpl.java

public void addListenerWithReplay(UpdateListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Null listener reference supplied");
    }/* ww  w.j a v a  2 s  .com*/

    if (isDestroyed()) {
        throw new IllegalStateException("Statement is in destroyed state");
    }

    statementContext.getDefaultAgentInstanceLock().acquireReadLock();
    try {
        // Add listener - listener not receiving events from this statement, as the statement is locked
        statementListenerSet.addListener(listener);
        statementContext.getStatementResultService().setUpdateListeners(statementListenerSet);
        statementLifecycleSvc.dispatchStatementLifecycleEvent(new StatementLifecycleEvent(this,
                StatementLifecycleEvent.LifecycleEventType.LISTENER_ADD, listener));

        Iterator<EventBean> it = iterator();
        if (it == null) {
            try {
                listener.update(null, null);
            } catch (Throwable t) {
                String message = "Unexpected exception invoking listener update method for replay on listener class '"
                        + listener.getClass().getSimpleName() + "' : " + t.getClass().getSimpleName() + " : "
                        + t.getMessage();
                log.error(message, t);
            }
            return;
        }

        ArrayList<EventBean> events = new ArrayList<EventBean>();
        for (; it.hasNext();) {
            events.add(it.next());
        }

        if (events.isEmpty()) {
            try {
                listener.update(null, null);
            } catch (Throwable t) {
                String message = "Unexpected exception invoking listener update method for replay on listener class '"
                        + listener.getClass().getSimpleName() + "' : " + t.getClass().getSimpleName() + " : "
                        + t.getMessage();
                log.error(message, t);
            }
        } else {
            EventBean[] iteratorResult = events.toArray(new EventBean[events.size()]);
            try {
                listener.update(iteratorResult, null);
            } catch (Throwable t) {
                String message = "Unexpected exception invoking listener update method for replay on listener class '"
                        + listener.getClass().getSimpleName() + "' : " + t.getClass().getSimpleName() + " : "
                        + t.getMessage();
                log.error(message, t);
            }
        }
    } finally {
        statementContext.getDefaultAgentInstanceLock().releaseReadLock();
    }
}

From source file:com.zjut.material_wecenter.Client.java

/**
 * publishQuestion ?//from   w w w .j  a  v  a2  s.  c  om
 * @param content 
 * @param detail 
 * @param topics ?
 * @return ?PublishQuestionResult
 */
public Result publishQuestion(String content, String detail, ArrayList<String> topics) {
    Map<String, String> params = new HashMap<>();
    params.put("question_content", content);
    params.put("question_detail", detail);
    // ??
    StringBuilder topic = new StringBuilder();
    if (!topics.isEmpty()) {
        topic.append(topics.get(0));
        for (int i = 1; i < topics.size(); i++)
            topic.append(',').append(topics.get(i));
    }
    params.put("topics", topics.toString());
    String json = doPost(Config.PUSHLISH_QUESTION, params);
    return getResult(json, PublishQuestion.class);
}

From source file:com.dsh105.command.HelpService.java

private void prepare(CommandHandler commandHandler) {
    String commandName = commandHandler.getCommandName();
    Matcher commandNameMatcher = VariableMatcher.REGEX_SYNTAX_PATTERN.matcher(commandName);
    while (commandNameMatcher.find()) {
        String openingTag = commandNameMatcher.group(1);
        String closingTag = openingTag.equals("<") ? ">" : "]";
        String name = commandNameMatcher.group(3) == null ? "undefined" : commandNameMatcher.group(3);
        commandName = commandName.replace(commandNameMatcher.group(0), openingTag + name + closingTag);
    }//from www . j a  v  a 2s  . c om
    String permission = StringUtil.combineArray(", ", commandHandler.getCommand().permission()).trim();

    PowerMessage part = new MarkupBuilder().withText(manager.getMessenger().getHighlightColour().toString())
            .withText("/").withText(commandName).withText(manager.getMessenger().getFormatColour().toString())
            .withText(" - ").withText(commandHandler.getCommand().description())
            .withText(permission.isEmpty() ? "" : " (" + permission + ")").build();
    part.group().tooltip(manager.getMessenger().format(
            ChatColor.ITALIC + "{c1}Click to insert {c2}\"" + commandName + "\"{c2} into the chat window."));
    part.suggest("/" + commandName);

    if (commandHandler.getCommand().help().length > 0) {
        ArrayList<String> tooltipLines = new ArrayList<>();
        for (String help : commandHandler.getCommand().help()) {
            tooltipLines.add(new MarkupBuilder()
                    .withText(manager.getMessenger().getHighlightColour() + " "
                            + manager.getMessenger().getFormatColour() + WordUtils.wrap(help, 30, "\n", false))
                    .build().getContent());
        }
        if (!tooltipLines.isEmpty()) {
            part.tooltip(tooltipLines.toArray(StringUtil.EMPTY_STRING_ARRAY));
        }
    }
    paginator.add(part);
}

From source file:megacasting.view.StatistiqueForm.java

private void graphMetierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphMetierButtonActionPerformed
    // TODO add your handling code here:

    // Liste de tous les mtiers
    ArrayList<Metier> metiers = MetierDAO.lister(mainJFrame.cnx);

    final DefaultPieDataset pieDataSet = new DefaultPieDataset();

    // Pour chaque mtier
    for (Metier m : metiers) {
        // On rcupre les offres du mtier
        ArrayList<Offre> offresFinal = OffreDAO.lister(mainJFrame.cnx, m);

        if (!offresFinal.isEmpty()) {
            pieDataSet.setValue(m.getLibelle() + " = " + offresFinal.size(), offresFinal.size());
        }//from w w  w  .  j  a  va  2  s . c  o m
    }

    graphOpen(pieDataSet, "Nombre d'offres par mtiers");
}

From source file:megacasting.view.StatistiqueForm.java

private void graphAnnonceurButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphAnnonceurButtonActionPerformed
    // TODO add your handling code here:

    // Liste de tous les type de contrats
    ArrayList<Annonceur> annconceurs = AnnonceurDAO.lister(mainJFrame.cnx);

    final DefaultPieDataset pieDataSet = new DefaultPieDataset();

    // Pour chaque type de contrat
    for (Annonceur a : annconceurs) {
        // Liste des offres du type de contrat
        ArrayList<Offre> offresFinal = OffreDAO.lister(mainJFrame.cnx, a);

        if (!offresFinal.isEmpty()) {
            pieDataSet.setValue(a.getRaisonSociale() + " = " + offresFinal.size(), offresFinal.size());
        }/*from   w w  w. ja  v a 2  s .c  o m*/
    }

    graphOpen(pieDataSet, "Nombre d'offres par annonceur");
}

From source file:megacasting.view.StatistiqueForm.java

private void graphTcButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphTcButtonActionPerformed
    // TODO add your handling code here:

    // Liste de tous les type de contrats
    ArrayList<TypeContrat> typeContrats = TypeContratDAO.lister(mainJFrame.cnx);

    final DefaultPieDataset pieDataSet = new DefaultPieDataset();

    // Pour chaque type de contrat
    for (TypeContrat tc : typeContrats) {
        // Liste des offres du type de contrat
        ArrayList<Offre> offresFinal = OffreDAO.lister(mainJFrame.cnx, tc);

        if (!offresFinal.isEmpty()) {
            pieDataSet.setValue(tc.getLibelle() + " = " + offresFinal.size(), offresFinal.size());
        }/*  w  w  w.  j  a  va2s  .  c o m*/
    }

    graphOpen(pieDataSet, "Nombre d'offres par type de contrat");
}