Example usage for java.util List listIterator

List of usage examples for java.util List listIterator

Introduction

In this page you can find the example usage for java.util List listIterator.

Prototype

ListIterator<E> listIterator();

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence).

Usage

From source file:org.apache.fop.layoutmgr.inline.TextLayoutManager.java

/** {@inheritDoc} */
public boolean applyChanges(final List oldList, int depth) {

    // make sure the LM appears unfinished in between this call
    // and the next call to getChangedKnuthElements()
    setFinished(false);/*from  ww w.  ja v  a2s .  c om*/

    if (oldList.isEmpty()) {
        return false;
    }

    // Find the first and last positions in oldList that point to an AreaInfo
    // (i.e. getLeafPos() != -1)
    LeafPosition startPos = null;
    LeafPosition endPos = null;
    ListIterator oldListIter;
    for (oldListIter = oldList.listIterator(); oldListIter.hasNext();) {
        Position pos = ((KnuthElement) oldListIter.next()).getPosition();
        startPos = (LeafPosition) pos.getPosition(depth);
        if (startPos != null && startPos.getLeafPos() != -1) {
            break;
        }
    }
    for (oldListIter = oldList.listIterator(oldList.size()); oldListIter.hasPrevious();) {
        Position pos = ((KnuthElement) oldListIter.previous()).getPosition();
        endPos = (LeafPosition) pos.getPosition(depth);
        if (endPos != null && endPos.getLeafPos() != -1) {
            break;
        }
    }

    // set start/end index, taking into account any offset due to
    // changes applied to previous paragraphs
    returnedIndices[0] = (startPos != null ? startPos.getLeafPos() : -1) + changeOffset;
    returnedIndices[1] = (endPos != null ? endPos.getLeafPos() : -1) + changeOffset;

    int areaInfosAdded = 0;
    int areaInfosRemoved = 0;

    if (!changeList.isEmpty()) {
        int oldIndex = -1;
        int changeIndex;
        PendingChange currChange;
        ListIterator changeListIterator = changeList.listIterator();
        while (changeListIterator.hasNext()) {
            currChange = (PendingChange) changeListIterator.next();
            if (currChange.index == oldIndex) {
                areaInfosAdded++;
                changeIndex = currChange.index + areaInfosAdded - areaInfosRemoved;
            } else {
                areaInfosRemoved++;
                areaInfosAdded++;
                oldIndex = currChange.index;
                changeIndex = currChange.index + areaInfosAdded - areaInfosRemoved;
                removeAreaInfo(changeIndex);
            }
            addAreaInfo(changeIndex, currChange.areaInfo);
        }
        changeList.clear();
    }

    // increase the end index for getChangedKnuthElements()
    returnedIndices[1] += (areaInfosAdded - areaInfosRemoved);
    // increase offset to use for subsequent paragraphs
    changeOffset += (areaInfosAdded - areaInfosRemoved);

    return hasChanged;
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Creates the last video list.//from   w w  w .j a  va2s .c  om
 *
 * @param start the start
 * @param ende the ende
 * @param facilityId the facility id
 * @param tree the tree
 */
public void createLastVideoList(int start, int ende, int facilityId, String tree) {
    List<Video> vlist = this.getLatestVideos(start, ende, facilityId, tree);
    //refresh the whole video list in the table
    JdbcTemplate jq = new JdbcTemplate(this.getDataSource());
    jq.update("DELETE FROM lastvideolist");
    ListIterator<Video> vIt = vlist.listIterator();
    while (vIt.hasNext()) {
        Video v = vIt.next();
        //save videos in table
        jq.update("INSERT INTO lastvideolist (videoId) VALUES(?)", new Object[] { v.getId() });
    }
}

From source file:ffx.potential.MolecularAssembly.java

/**
 * <p>//w w w  . ja v  a  2  s .  co m
 * sceneGraphChange</p>
 *
 * @param newShapes a {@link java.util.List} object.
 */
public void sceneGraphChange(List<BranchGroup> newShapes) {
    if (newShapes == null) {
        newShapes = myNewShapes;
    }

    if (newShapes.isEmpty()) {
        return;
    }

    boolean reCompile = false;
    // Check for nodes (new and/or recycled) being added to this
    // MolecularAssembly
    for (ListIterator<BranchGroup> li = newShapes.listIterator(); li.hasNext();) {
        BranchGroup group = li.next();
        li.remove();
        // This is code for cycling between two MolecularAssemblies
        if (group.getUserData() != null) {
            logger.info(group.toString() + " " + group.getUserData());
            /*
             * Object userData = group.getUserData(); if (userData!=this) {
             * // The appearance has already been set during a recursive
             * call to setView, // although we need to turn back on
             * Pickablility. TransformGroup tg = (TransformGroup)
             * group.getChild(0); Shape3D shape = (Shape3D) tg.getChild(0);
             * shape.setPickable(true); group.setUserData(this); if
             * (!reCompile) { if (childNodes.isLive()) {
             * childNodes.detach(); } reCompile = true; }
             * childNodes.moveTo(group);
             */
        } else {
            // This is a new group since it has no userData.
            // We can not query for the identity of its parent later, so
            // we will store it as a userData reference.
            group.setUserData(this);
            if (!reCompile) {
                if (childNodes.isLive()) {
                    childNodes.detach();
                }

                reCompile = true;
            }

            childNodes.addChild(group);
        }

    }
    if (reCompile) {
        childNodes.compile();
        base.addChild(childNodes);
    }

}

From source file:com.rr.missouri.ui.surveys.surveyController.java

/**
 * The '/startSurvey' GET request will build out the survey and display the first page of the survey.
 *
 * @param i The encrypted client id/*from   w w w  .ja  v a 2 s  .c  o m*/
 * @param v The encrypted decryption key
 * @param s The id of the selected survey
 *
 * @param session
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/startSurvey", method = RequestMethod.POST)
public ModelAndView startSurvey(@RequestParam(value = "s", required = false) String s,
        @RequestParam(value = "i", required = false) String i,
        @RequestParam(value = "v", required = false) String v,
        @RequestParam(value = "selectedEntities", required = false) List<Integer> selectedEntities,
        HttpSession session) throws Exception {

    ModelAndView mav = new ModelAndView();
    mav.setViewName("/takeSurvey");
    mav.addObject("surveys", surveys);

    //Set the survey answer array to get ready to hold data
    if (session.getAttribute("questionAnswers") != null) {
        session.removeAttribute("questionAnswers");
    }
    session.setAttribute("questionAnswers", new ArrayList<surveyQuestionAnswers>());

    if (session.getAttribute("selectedContentCriterias") != null) {
        session.removeAttribute("selectedContentCriterias");
    }
    session.setAttribute("selectedContentCriterias", new ArrayList<surveyContentCriteria>());

    if (session.getAttribute("districtList") != null) {
        session.removeAttribute("districtList");
    }
    session.setAttribute("districtList", new ArrayList<district>());

    if (session.getAttribute("seenPages") != null) {
        session.removeAttribute("seenPages");
    }
    session.setAttribute("seenPages", new ArrayList<Integer>());

    int clientId = 0;
    int surveyId = 0;

    /* Get the submitted surveys for the selected survey type */
    if (!"".equals(i) && i != null && !"".equals(v) && v != null) {
        /* Decrypt the url */
        decryptObject decrypt = new decryptObject();

        Object obj = decrypt.decryptObject(i, v);

        String[] result = obj.toString().split((","));

        surveyId = Integer.parseInt(result[0].substring(4));

    } else {
        surveyId = Integer.parseInt(s);
    }

    if (surveyId > 0) {

        surveys surveyDetails = surveyManager.getSurveyDetails(surveyId);

        /* Make sure the survey is part of this program and active */
        if (surveyDetails.getProgramId() != programId || surveyDetails.getStatus() == false) {

            /* Redirect back to the survey list page */
        } /* Set up the survey */ else {
            survey survey = new survey();
            survey.setClientId(clientId);
            survey.setSurveyId(surveyId);
            survey.setSurveyTitle(surveyDetails.getTitle());
            survey.setPrevButton(surveyDetails.getPrevButtonText());
            survey.setNextButton(surveyDetails.getNextButtonText());
            survey.setSaveButton(surveyDetails.getDoneButtonText());
            survey.setSubmittedSurveyId(0);

            encryptObject encrypt = new encryptObject();
            Map<String, String> map;

            map = new HashMap<String, String>();
            map.put("id", Integer.toString(surveyId));
            map.put("topSecret", topSecret);

            String[] encrypted = encrypt.encryptObject(map);

            survey.setEncryptedId(encrypted[0]);
            survey.setEncryptedSecret(encrypted[1]);

            /* Get the pages */
            List<SurveyPages> surveyPages = surveyManager.getSurveyPages(surveyId, false, 0, 0, 0);
            SurveyPages currentPage = surveyManager.getSurveyPage(surveyId, true, 1, clientId, 0, 0, 0, 0);
            survey.setPageTitle(currentPage.getPageTitle());
            survey.setPageDesc(currentPage.getPageDesc());
            survey.setSurveyPageQuestions(currentPage.getSurveyQuestions());
            survey.setTotalPages(surveyPages.size());
            survey.setPageId(currentPage.getId());
            survey.setLastPageId(surveyPages.get(surveyPages.size() - 1).getId());

            mav.addObject("survey", survey);
            mav.addObject("surveyPages", surveyPages);
        }
    } else {
        /* Redirect back to the survey list page */

    }

    User userDetails = (User) session.getAttribute("userDetails");

    /* Get a list of available schools for the selected districts */
    if (selectedEntities != null && !selectedEntities.isEmpty() && !"".equals(selectedEntities)) {

        encryptObject encrypt = new encryptObject();
        Map<String, String> map;

        List<district> districtList = (List<district>) session.getAttribute("districtList");

        for (Integer entity : selectedEntities) {

            List<school> schoolList = new ArrayList<school>();

            district district = new district();
            district.setDistrictId(entity);

            programHierarchyDetails districtDetails = hierarchymanager.getProgramHierarchyItemDetails(entity);
            district.setDistrictName(districtDetails.getName());

            Integer userId = 0;
            if (userDetails.getRoleId() == 3) {
                userId = userDetails.getId();
            }

            List schools = hierarchymanager.getProgramOrgHierarchyItems(programId, 3, entity, userId);

            if (!schools.isEmpty() && schools.size() > 0) {

                for (ListIterator iter = schools.listIterator(); iter.hasNext();) {

                    Object[] row = (Object[]) iter.next();

                    school school = new school();
                    school.setSchoolId(Integer.parseInt(row[0].toString()));
                    school.setSchoolName(row[1].toString());

                    //Encrypt the use id to pass in the url
                    map = new HashMap<String, String>();
                    map.put("id", Integer.toString(Integer.parseInt(row[0].toString())));
                    map.put("topSecret", topSecret);

                    String[] encrypted = encrypt.encryptObject(map);

                    school.setEncryptedId(encrypted[0]);
                    school.setEncryptedSecret(encrypted[1]);

                    schoolList.add(school);

                }

                district.setSchoolList(schoolList);

            }

            districtList.add(district);

        }

        mav.addObject("selDistricts", districtList);

    }

    mav.addObject("selSurvey", surveyId);

    mav.addObject("selectedEntities", selectedEntities.toString().replace("[", "").replace("]", ""));
    mav.addObject("currentPage", 1);
    mav.addObject("currPageNum", 1);

    mav.addObject("qNum", 0);
    mav.addObject("disabled", false);

    return mav;
}

From source file:com.rr.moheals.ui.surveys.surveyController.java

/**
 * The '/startSurvey' GET request will build out the survey and display the first page of the survey.
 *
 * @param i The encrypted client id//from  www  . ja  v  a 2s.c o  m
 * @param v The encrypted decryption key
 * @param s The id of the selected survey
 *
 * @param session
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/startSurvey", method = RequestMethod.POST)
public ModelAndView startSurvey(@RequestParam(value = "s", required = false) String s,
        @RequestParam(value = "i", required = false) String i,
        @RequestParam(value = "v", required = false) String v,
        @RequestParam(value = "selectedEntities", required = false) List<Integer> selectedEntities,
        HttpSession session) throws Exception {

    ModelAndView mav = new ModelAndView();
    mav.setViewName("/takeSurvey");
    mav.addObject("surveys", surveys);

    //Set the survey answer array to get ready to hold data
    if (session.getAttribute("questionAnswers") != null) {
        session.removeAttribute("questionAnswers");
    }
    session.setAttribute("questionAnswers", new ArrayList<surveyQuestionAnswers>());

    if (session.getAttribute("selectedContentCriterias") != null) {
        session.removeAttribute("selectedContentCriterias");
    }
    session.setAttribute("selectedContentCriterias", new ArrayList<surveyContentCriteria>());

    if (session.getAttribute("countyList") != null) {
        session.removeAttribute("countyList");
    }
    session.setAttribute("countyList", new ArrayList<county>());

    if (session.getAttribute("seenPages") != null) {
        session.removeAttribute("seenPages");
    }
    session.setAttribute("seenPages", new ArrayList<Integer>());

    int clientId = 0;
    int surveyId = 0;

    /* Get the submitted surveys for the selected survey type */
    if (!"".equals(i) && i != null && !"".equals(v) && v != null) {
        /* Decrypt the url */
        decryptObject decrypt = new decryptObject();

        Object obj = decrypt.decryptObject(i, v);

        String[] result = obj.toString().split((","));

        surveyId = Integer.parseInt(result[0].substring(4));

    } else {
        surveyId = Integer.parseInt(s);
    }

    if (surveyId > 0) {

        surveys surveyDetails = surveyManager.getSurveyDetails(surveyId);

        /* Make sure the survey is part of this program and active */
        if (surveyDetails.getProgramId() != programId || surveyDetails.getStatus() == false) {

            /* Redirect back to the survey list page */
        } /* Set up the survey */ else {
            survey survey = new survey();
            survey.setClientId(clientId);
            survey.setSurveyId(surveyId);
            survey.setSurveyTitle(surveyDetails.getTitle());
            survey.setPrevButton(surveyDetails.getPrevButtonText());
            survey.setNextButton(surveyDetails.getNextButtonText());
            survey.setSaveButton(surveyDetails.getDoneButtonText());
            survey.setSubmittedSurveyId(0);

            encryptObject encrypt = new encryptObject();
            Map<String, String> map;

            map = new HashMap<String, String>();
            map.put("id", Integer.toString(surveyId));
            map.put("topSecret", topSecret);

            String[] encrypted = encrypt.encryptObject(map);

            survey.setEncryptedId(encrypted[0]);
            survey.setEncryptedSecret(encrypted[1]);

            /* Get the pages */
            List<SurveyPages> surveyPages = surveyManager.getSurveyPages(surveyId, false, 0, 0, 0);
            SurveyPages currentPage = surveyManager.getSurveyPage(surveyId, true, 1, clientId, 0, 0, 0, 0);
            survey.setPageTitle(currentPage.getPageTitle());
            survey.setPageDesc(currentPage.getPageDesc());
            survey.setSurveyPageQuestions(currentPage.getSurveyQuestions());
            survey.setTotalPages(surveyPages.size());
            survey.setPageId(currentPage.getId());
            survey.setLastPageId(surveyPages.get(surveyPages.size() - 1).getId());

            mav.addObject("survey", survey);
            mav.addObject("surveyPages", surveyPages);
        }
    } else {
        /* Redirect back to the survey list page */

    }

    User userDetails = (User) session.getAttribute("userDetails");

    /* Get a list of available health departments for the selected districts */
    if (selectedEntities != null && !selectedEntities.isEmpty() && !"".equals(selectedEntities)) {

        encryptObject encrypt = new encryptObject();
        Map<String, String> map;

        List<county> countyList = (List<county>) session.getAttribute("countyList");

        for (Integer entity : selectedEntities) {

            List<healthDepartment> healthDepartmentList = new ArrayList<healthDepartment>();

            county county = new county();
            county.setCountyId(entity);

            programHierarchyDetails countyDetails = hierarchymanager.getProgramHierarchyItemDetails(entity);
            county.setCountyName(countyDetails.getName());

            Integer userId = 0;
            if (userDetails.getRoleId() == 3) {
                userId = userDetails.getId();
            }

            List healthDepartments = hierarchymanager.getProgramOrgHierarchyItems(programId, 2, entity, userId);

            if (!healthDepartments.isEmpty() && healthDepartments.size() > 0) {

                for (ListIterator iter = healthDepartments.listIterator(); iter.hasNext();) {

                    Object[] row = (Object[]) iter.next();

                    healthDepartment healthDepartment = new healthDepartment();
                    healthDepartment.setHealthDepartmentId(Integer.parseInt(row[0].toString()));
                    healthDepartment.setHealthDepartmentName(row[1].toString());

                    //Encrypt the use id to pass in the url
                    map = new HashMap<String, String>();
                    map.put("id", Integer.toString(Integer.parseInt(row[0].toString())));
                    map.put("topSecret", topSecret);

                    String[] encrypted = encrypt.encryptObject(map);

                    healthDepartment.setEncryptedId(encrypted[0]);
                    healthDepartment.setEncryptedSecret(encrypted[1]);

                    healthDepartmentList.add(healthDepartment);

                }

                county.setHealthDepartmentList(healthDepartmentList);

            }

            countyList.add(county);

        }

        mav.addObject("selCounties", countyList);

    }

    mav.addObject("selSurvey", surveyId);

    mav.addObject("selectedEntities", selectedEntities.toString().replace("[", "").replace("]", ""));
    mav.addObject("currentPage", 1);
    mav.addObject("currPageNum", 1);

    mav.addObject("qNum", 0);
    mav.addObject("disabled", false);

    return mav;
}

From source file:com.rr.missouri.ui.surveys.surveyController.java

/**
 * The '/editSurvey' GET request will build out the survey and display the first page of the survey.
 *
 * @param i The encrypted survey id// w w  w  . ja  va 2s.  co  m
 * @param v The encrypted decryption key
 *
 * @param session
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "/editSurvey", "/viewSurvey" }, method = RequestMethod.GET)
public ModelAndView editSurvey(@RequestParam String i, @RequestParam String v, HttpSession session,
        HttpServletRequest request) throws Exception {

    ModelAndView mav = new ModelAndView();
    mav.setViewName("/takeSurvey");
    mav.addObject("surveys", surveys);

    //Set the survey answer array to get ready to hold data
    if (session.getAttribute("questionAnswers") != null) {
        session.removeAttribute("questionAnswers");
    }
    session.setAttribute("questionAnswers", new ArrayList<surveyQuestionAnswers>());

    if (session.getAttribute("selectedContentCriterias") != null) {
        session.removeAttribute("selectedContentCriterias");
    }
    session.setAttribute("selectedContentCriterias", new ArrayList<surveyContentCriteria>());

    if (session.getAttribute("districtList") != null) {
        session.removeAttribute("districtList");
    }
    session.setAttribute("districtList", new ArrayList<district>());

    if (session.getAttribute("seenPages") != null) {
        session.removeAttribute("seenPages");
    }
    session.setAttribute("seenPages", new ArrayList<Integer>());

    int clientId = 0;

    /* Decrypt the url */
    decryptObject decrypt = new decryptObject();

    Object obj = decrypt.decryptObject(i, v);

    String[] result = obj.toString().split((","));

    int submittedSurveyId = Integer.parseInt(result[0].substring(4));

    /* Get the survey details */
    submittedSurveys submittedSurveyDetails = surveyManager.getSubmittedSurvey(submittedSurveyId);

    surveys surveyDetails = surveyManager.getSurveyDetails(submittedSurveyDetails.getSurveyId());

    User userDetails = (User) session.getAttribute("userDetails");

    survey survey = new survey();
    survey.setClientId(clientId);
    survey.setSurveyId(submittedSurveyDetails.getSurveyId());
    survey.setSurveyTitle(surveyDetails.getTitle());
    survey.setPrevButton(surveyDetails.getPrevButtonText());
    survey.setNextButton(surveyDetails.getNextButtonText());
    survey.setSaveButton(surveyDetails.getDoneButtonText());
    survey.setSubmittedSurveyId(submittedSurveyId);
    survey.setEntityIds(surveyManager.getSubmittedSurveyEntities(submittedSurveyId, userDetails));

    encryptObject encrypt = new encryptObject();
    Map<String, String> map;

    //Encrypt the use id to pass in the url
    map = new HashMap<String, String>();
    map.put("id", Integer.toString(submittedSurveyDetails.getSurveyId()));
    map.put("topSecret", topSecret);

    String[] encrypted = encrypt.encryptObject(map);

    survey.setEncryptedId(encrypted[0]);
    survey.setEncryptedSecret(encrypted[1]);

    /* Get the pages */
    List<SurveyPages> surveyPages = surveyManager.getSurveyPages(submittedSurveyDetails.getSurveyId(), false, 0,
            0, 0);
    SurveyPages currentPage = surveyManager.getSurveyPage(submittedSurveyDetails.getSurveyId(), true, 1,
            clientId, 0, 0, submittedSurveyId, 0);
    survey.setPageTitle(currentPage.getPageTitle());
    survey.setPageDesc(currentPage.getPageDesc());
    survey.setSurveyPageQuestions(currentPage.getSurveyQuestions());
    survey.setTotalPages(surveyPages.size());
    survey.setLastPageId(surveyPages.get(surveyPages.size() - 1).getId());
    survey.setPageId(currentPage.getId());

    /* Need to update any date functions */
    if (survey.getSurveyPageQuestions() != null && survey.getSurveyPageQuestions().size() > 0) {
        for (SurveyQuestions question : survey.getSurveyPageQuestions()) {
            if (question.getAnswerTypeId() == 6) {
                if (question.getQuestionValue().length() > 0
                        && !question.getQuestionValue().contains("^^^^^")) {
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                    SimpleDateFormat df2 = new SimpleDateFormat("M/dd/yy");
                    SimpleDateFormat df3 = new SimpleDateFormat("M/dd/yyyy");
                    SimpleDateFormat df4 = new SimpleDateFormat("M/d/yy");
                    SimpleDateFormat df5 = new SimpleDateFormat("M/d/yyyy");
                    SimpleDateFormat df6 = new SimpleDateFormat("MM/d/yyyy");
                    SimpleDateFormat df7 = new SimpleDateFormat("MM/d/yy");
                    SimpleDateFormat df8 = new SimpleDateFormat("MM/dd/yyyy");
                    SimpleDateFormat df9 = new SimpleDateFormat("MM/dd/yy");

                    Date formattedDate;
                    try {
                        formattedDate = df.parse(question.getQuestionValue());
                    } catch (Exception ex) {
                        try {
                            formattedDate = df2.parse(question.getQuestionValue());
                        } catch (Exception ex2) {
                            try {
                                formattedDate = df3.parse(question.getQuestionValue());
                            } catch (Exception ex3) {
                                try {
                                    formattedDate = df4.parse(question.getQuestionValue());
                                } catch (Exception ex4) {
                                    try {
                                        formattedDate = df5.parse(question.getQuestionValue());
                                    } catch (Exception ex5) {
                                        try {
                                            formattedDate = df6.parse(question.getQuestionValue());
                                        } catch (Exception ex6) {
                                            try {
                                                formattedDate = df7.parse(question.getQuestionValue());
                                            } catch (Exception ex7) {
                                                try {
                                                    formattedDate = df8.parse(question.getQuestionValue());
                                                } catch (Exception ex8) {
                                                    formattedDate = df9.parse(question.getQuestionValue());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (question.getDateFormatType() == 2) { //dd/mm/yyyy
                        df.applyPattern("dd/MM/yyyy");
                    } else { //mm/dd/yyyy
                        df.applyPattern("MM/dd/yyyy");
                    }
                    String formattedDateasString = df.format(formattedDate);
                    question.setQuestionValue(formattedDateasString);
                }
            }
        }
    }

    mav.addObject("survey", survey);
    mav.addObject("surveyPages", surveyPages);

    List<Integer> selectedEntities = surveyManager.getSurveyEntities(submittedSurveyId);

    /* Get a list of available schools for the selected districts */
    if (selectedEntities != null && !selectedEntities.isEmpty() && !"".equals(selectedEntities)) {

        List<district> districtList = (List<district>) session.getAttribute("districtList");

        for (Integer entityId : selectedEntities) {

            List<school> schoolList = new ArrayList<school>();

            district district = new district();
            district.setDistrictId(entityId);

            programHierarchyDetails districtDetails = hierarchymanager.getProgramHierarchyItemDetails(entityId);
            district.setDistrictName(districtDetails.getName());

            Integer userId = 0;
            if (userDetails.getRoleId() == 3) {
                userId = userDetails.getId();
            }

            List schools = hierarchymanager.getProgramOrgHierarchyItems(programId, 3, entityId, userId);

            if (!schools.isEmpty() && schools.size() > 0) {

                for (ListIterator iter = schools.listIterator(); iter.hasNext();) {

                    Object[] row = (Object[]) iter.next();

                    school school = new school();
                    school.setSchoolId(Integer.parseInt(row[0].toString()));
                    school.setSchoolName(row[1].toString());

                    //Encrypt the use id to pass in the url
                    map = new HashMap<String, String>();
                    map.put("id", Integer.toString(Integer.parseInt(row[0].toString())));
                    map.put("topSecret", topSecret);

                    String[] encrypted2 = encrypt.encryptObject(map);

                    school.setEncryptedId(encrypted2[0]);
                    school.setEncryptedSecret(encrypted2[1]);

                    schoolList.add(school);

                }

                district.setSchoolList(schoolList);

            }

            districtList.add(district);

        }

        mav.addObject("selDistricts", districtList);

    }

    mav.addObject("selSurvey", submittedSurveyDetails.getSurveyId());
    mav.addObject("selectedEntities", selectedEntities.toString().replace("[", "").replace("]", ""));

    mav.addObject("qNum", 0);
    mav.addObject("currPageNum", 1);

    boolean disabled = false;
    if ("/surveys/viewSurvey".equals(request.getServletPath())) {
        disabled = true;
    }

    mav.addObject("disabled", disabled);

    return mav;
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Gets the first lacture fromlectureseries id.
 *
 * @param lectureseriesId the lectureseries id
 * @return the first lacture fromlectureseries id
 *//*from  ww w.  j a  va2 s . co m*/
public Video getFirstVideoFromlectureseriesId(Integer lectureseriesId) throws NoSuchElementException {
    JdbcTemplate select = new JdbcTemplate(this.getDataSource());
    @SuppressWarnings("rawtypes")
    List vidL = select.queryForList(
            "SELECT id FROM video WHERE (generationDate=(SELECT MIN(generationDate) FROM video WHERE lectureseriesId=? AND openAccess=1) AND lectureseriesId=? AND openAccess=1) ORDER BY id ASC LIMIT 1",
            new Object[] { lectureseriesId, lectureseriesId });
    ListOrderedMap lid = (ListOrderedMap) vidL.listIterator().next();
    Integer id = (Integer) lid.get("id");
    Video vid = this.getByIdNP(id).iterator().next();
    return vid;
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Gets the latest lacture fromlectureseries id.
 *
 * @param lectureseriesId the lectureseries id
 * @return the latest lacture fromlectureseries id
 *//*ww  w. j ava 2s .co m*/
public Video getLatestVideoFromlectureseriesId(Integer lectureseriesId) throws NoSuchElementException {
    JdbcTemplate select = new JdbcTemplate(this.getDataSource());
    @SuppressWarnings("rawtypes")
    List vidL = select.queryForList(
            "SELECT id FROM video WHERE (generationDate=(SELECT MAX(generationDate) FROM video WHERE lectureseriesId=? AND openAccess=1) AND lectureseriesId=? AND openAccess=1) ORDER BY id ASC LIMIT 1",
            new Object[] { lectureseriesId, lectureseriesId });
    ListOrderedMap lid = (ListOrderedMap) vidL.listIterator().next();
    Integer id = (Integer) lid.get("id");
    Video vid = this.getByIdNP(id).iterator().next();
    return vid;
}

From source file:com.rr.moheals.ui.surveys.surveyController.java

/**
 * The '/editSurvey' GET request will build out the survey and display the first page of the survey.
 *
 * @param i The encrypted survey id//from  w ww  .  j a va2s .co  m
 * @param v The encrypted decryption key
 *
 * @param session
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "/editSurvey", "/viewSurvey" }, method = RequestMethod.GET)
public ModelAndView editSurvey(@RequestParam String i, @RequestParam String v, HttpSession session,
        HttpServletRequest request) throws Exception {

    ModelAndView mav = new ModelAndView();
    mav.setViewName("/takeSurvey");
    mav.addObject("surveys", surveys);

    //Set the survey answer array to get ready to hold data
    if (session.getAttribute("questionAnswers") != null) {
        session.removeAttribute("questionAnswers");
    }
    session.setAttribute("questionAnswers", new ArrayList<surveyQuestionAnswers>());

    if (session.getAttribute("selectedContentCriterias") != null) {
        session.removeAttribute("selectedContentCriterias");
    }
    session.setAttribute("selectedContentCriterias", new ArrayList<surveyContentCriteria>());

    if (session.getAttribute("countyList") != null) {
        session.removeAttribute("countyList");
    }
    session.setAttribute("countyList", new ArrayList<county>());

    if (session.getAttribute("seenPages") != null) {
        session.removeAttribute("seenPages");
    }
    session.setAttribute("seenPages", new ArrayList<Integer>());

    int clientId = 0;

    /* Decrypt the url */
    decryptObject decrypt = new decryptObject();

    Object obj = decrypt.decryptObject(i, v);

    String[] result = obj.toString().split((","));

    int submittedSurveyId = Integer.parseInt(result[0].substring(4));

    /* Get the survey details */
    submittedSurveys submittedSurveyDetails = surveyManager.getSubmittedSurvey(submittedSurveyId);

    surveys surveyDetails = surveyManager.getSurveyDetails(submittedSurveyDetails.getSurveyId());

    User userDetails = (User) session.getAttribute("userDetails");

    survey survey = new survey();
    survey.setClientId(clientId);
    survey.setSurveyId(submittedSurveyDetails.getSurveyId());
    survey.setSurveyTitle(surveyDetails.getTitle());
    survey.setPrevButton(surveyDetails.getPrevButtonText());
    survey.setNextButton(surveyDetails.getNextButtonText());
    survey.setSaveButton(surveyDetails.getDoneButtonText());
    survey.setSubmittedSurveyId(submittedSurveyId);
    survey.setEntityIds(surveyManager.getSubmittedSurveyEntities(submittedSurveyId, userDetails));

    encryptObject encrypt = new encryptObject();
    Map<String, String> map;

    //Encrypt the use id to pass in the url
    map = new HashMap<String, String>();
    map.put("id", Integer.toString(submittedSurveyDetails.getSurveyId()));
    map.put("topSecret", topSecret);

    String[] encrypted = encrypt.encryptObject(map);

    survey.setEncryptedId(encrypted[0]);
    survey.setEncryptedSecret(encrypted[1]);

    /* Get the pages */
    List<SurveyPages> surveyPages = surveyManager.getSurveyPages(submittedSurveyDetails.getSurveyId(), false, 0,
            0, 0);
    SurveyPages currentPage = surveyManager.getSurveyPage(submittedSurveyDetails.getSurveyId(), true, 1,
            clientId, 0, 0, submittedSurveyId, 0);
    survey.setPageTitle(currentPage.getPageTitle());
    survey.setPageDesc(currentPage.getPageDesc());
    survey.setSurveyPageQuestions(currentPage.getSurveyQuestions());
    survey.setTotalPages(surveyPages.size());
    survey.setLastPageId(surveyPages.get(surveyPages.size() - 1).getId());
    survey.setPageId(currentPage.getId());

    /* Need to update any date functions */
    if (survey.getSurveyPageQuestions() != null && survey.getSurveyPageQuestions().size() > 0) {
        for (SurveyQuestions question : survey.getSurveyPageQuestions()) {

            if (question.getAnswerTypeId() == 6) {
                if (question.getQuestionValue().length() > 0) {
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                    SimpleDateFormat df2 = new SimpleDateFormat("M/dd/yy");
                    SimpleDateFormat df3 = new SimpleDateFormat("M/dd/yyyy");
                    SimpleDateFormat df4 = new SimpleDateFormat("M/d/yy");
                    SimpleDateFormat df5 = new SimpleDateFormat("M/d/yyyy");
                    SimpleDateFormat df6 = new SimpleDateFormat("MM/d/yyyy");
                    SimpleDateFormat df7 = new SimpleDateFormat("MM/d/yy");
                    SimpleDateFormat df8 = new SimpleDateFormat("MM/dd/yyyy");
                    SimpleDateFormat df9 = new SimpleDateFormat("MM/dd/yy");

                    Date formattedDate;
                    try {
                        formattedDate = df.parse(question.getQuestionValue());
                    } catch (Exception ex) {
                        try {
                            formattedDate = df2.parse(question.getQuestionValue());
                        } catch (Exception ex2) {
                            try {
                                formattedDate = df3.parse(question.getQuestionValue());
                            } catch (Exception ex3) {
                                try {
                                    formattedDate = df4.parse(question.getQuestionValue());
                                } catch (Exception ex4) {
                                    try {
                                        formattedDate = df5.parse(question.getQuestionValue());
                                    } catch (Exception ex5) {
                                        try {
                                            formattedDate = df6.parse(question.getQuestionValue());
                                        } catch (Exception ex6) {
                                            try {
                                                formattedDate = df7.parse(question.getQuestionValue());
                                            } catch (Exception ex7) {
                                                try {
                                                    formattedDate = df8.parse(question.getQuestionValue());
                                                } catch (Exception ex8) {
                                                    formattedDate = df9.parse(question.getQuestionValue());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (question.getDateFormatType() == 2) { //dd/mm/yyyy
                        df.applyPattern("dd/MM/yyyy");
                    } else { //mm/dd/yyyy
                        df.applyPattern("MM/dd/yyyy");
                    }
                    String formattedDateasString = df.format(formattedDate);
                    question.setQuestionValue(formattedDateasString);
                }
            }
        }
    }

    mav.addObject("survey", survey);
    mav.addObject("surveyPages", surveyPages);

    List<Integer> selectedEntities = surveyManager.getSurveyEntities(submittedSurveyId);

    /* Get a list of available health Departments for the selected districts */
    if (selectedEntities != null && !selectedEntities.isEmpty() && !"".equals(selectedEntities)) {

        List<county> countyList = (List<county>) session.getAttribute("countyList");

        for (Integer entityId : selectedEntities) {

            List<healthDepartment> healthDepartmentList = new ArrayList<healthDepartment>();

            county county = new county();
            county.setCountyId(entityId);

            programHierarchyDetails districtDetails = hierarchymanager.getProgramHierarchyItemDetails(entityId);
            county.setCountyName(districtDetails.getName());

            Integer userId = 0;
            if (userDetails.getRoleId() == 3) {
                userId = userDetails.getId();
            }

            List healthDepartments = hierarchymanager.getProgramOrgHierarchyItems(programId, 2, entityId,
                    userId);

            if (!healthDepartments.isEmpty() && healthDepartments.size() > 0) {

                for (ListIterator iter = healthDepartments.listIterator(); iter.hasNext();) {

                    Object[] row = (Object[]) iter.next();

                    healthDepartment healthDepartment = new healthDepartment();
                    healthDepartment.setHealthDepartmentId(Integer.parseInt(row[0].toString()));
                    healthDepartment.setHealthDepartmentName(row[1].toString());

                    //Encrypt the use id to pass in the url
                    map = new HashMap<String, String>();
                    map.put("id", Integer.toString(Integer.parseInt(row[0].toString())));
                    map.put("topSecret", topSecret);

                    String[] encrypted2 = encrypt.encryptObject(map);

                    healthDepartment.setEncryptedId(encrypted2[0]);
                    healthDepartment.setEncryptedSecret(encrypted2[1]);

                    healthDepartmentList.add(healthDepartment);

                }

                county.setHealthDepartmentList(healthDepartmentList);

            }

            countyList.add(county);

        }

        mav.addObject("selCounties", countyList);

    }

    mav.addObject("selSurvey", submittedSurveyDetails.getSurveyId());
    mav.addObject("selectedEntities", selectedEntities.toString().replace("[", "").replace("]", ""));

    mav.addObject("qNum", 0);
    mav.addObject("currPageNum", 1);

    boolean disabled = false;
    if ("/surveys/viewSurvey".equals(request.getServletPath())) {
        disabled = true;
    }

    mav.addObject("disabled", disabled);

    return mav;
}

From source file:com.net2plan.libraries.GraphUtils.java

/** Returns the total cost for a given a list of paths.
 * /*from   ww w .jav a  2s .c om*/
 * @param pathList List of paths, where each path is represented by its sequence of traversed links
 * @param linkCostMap Cost per link array
 * @return Cost per path */
public static List<Double> convertPathList2PathCost(List<List<Link>> pathList, DoubleMatrix1D linkCostMap) {
    List<Double> pathCost = new LinkedList<Double>();

    ListIterator<List<Link>> it = pathList.listIterator();
    while (it.hasNext()) {
        List<Link> path = it.next();
        pathCost.add(convertPath2PathCost(path, linkCostMap));
    }

    return pathCost;
}