Example usage for java.lang String compareToIgnoreCase

List of usage examples for java.lang String compareToIgnoreCase

Introduction

In this page you can find the example usage for java.lang String compareToIgnoreCase.

Prototype

public int compareToIgnoreCase(String str) 

Source Link

Document

Compares two strings lexicographically, ignoring case differences.

Usage

From source file:org.ebayopensource.turmeric.repository.wso2.assets.WSDLManager.java

/**
 * Finds all WSDL artifacts on the registry.
 * /*from   ww  w  .j a v  a2  s.c o m*/
 * @return all WSDL artifacts on the registry.
 * @throws GovernanceException
 *            if the operation failed.
 */
public Wsdl[] getAllWsdls() throws GovernanceException {
    List<String> wsdlPaths = Arrays
            .asList(GovernanceUtils.getResultPaths(registry, GovernanceConstants.WSDL_MEDIA_TYPE));
    Collections.sort(wsdlPaths, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            // First order by name
            int result = RegistryUtils.getResourceName(o1)
                    .compareToIgnoreCase(RegistryUtils.getResourceName(o2));
            if (result != 0) {
                return result;
            }
            // Then order by namespace
            return o1.compareToIgnoreCase(o2);
        }
    });
    List<Wsdl> wsdls = new ArrayList<Wsdl>();
    for (String wsdlPath : wsdlPaths) {
        GovernanceArtifact artifact = GovernanceUtils.retrieveGovernanceArtifactByPath(registry, wsdlPath);
        wsdls.add((Wsdl) artifact);
    }
    return wsdls.toArray(new Wsdl[wsdls.size()]);
}

From source file:com.spd.ukraine.lucenewebsearch1.web.IndexingController.java

private Object returnSubListOfSortedList() {
    List<WebPage> sortedList;
    if (sortingOrder.equals(SORTING_ALPHABETICALLY)) {
        if (foundSearchResultsSorted.isEmpty()) {
            foundSearchResultsSorted = new ArrayList<>(foundSearchResults);
            Collections.sort(foundSearchResultsSorted, (o1, o2) -> {
                String title1 = o1.getTitle().replace(HIGHLIGHT_OPEN, "");
                String title2 = o2.getTitle().replace(HIGHLIGHT_OPEN, "");
                return title1.compareToIgnoreCase(title2);
            });// w  w  w .  ja  v a2 s  .  co  m
        }
        sortedList = foundSearchResultsSorted;
        //            System.out.println("sortedList '" + sortedList.get(0).getTitle() 
        //                + "', '" + sortedList.get(1).getTitle());
    } else {
        sortedList = foundSearchResults;
    }
    return sortedList.subList(lastPageResultIndex - RESULTS_PER_PAGE,
            Math.min(lastPageResultIndex, sortedList.size()));
}

From source file:org.nuxeo.runtime.osgi.OSGiRuntimeService.java

protected void loadConfig() throws IOException {
    Environment env = Environment.getDefault();
    if (env != null) {
        log.debug("Configuration: host application: " + env.getHostApplicationName());
    } else {//from w  ww .ja va 2 s  . co m
        log.warn("Configuration: no host application");
        return;
    }

    File blacklistFile = new File(env.getConfig(), "blacklist");
    if (blacklistFile.isFile()) {
        List<String> lines = FileUtils.readLines(blacklistFile);
        Set<String> blacklist = new HashSet<>();
        for (String line : lines) {
            line = line.trim();
            if (line.length() > 0) {
                blacklist.add(line);
            }
        }
        manager.setBlacklist(new HashSet<>(lines));
    }

    if (loadConfigurationFromProvider()) {
        return;
    }

    String configDir = bundleContext.getProperty(PROP_CONFIG_DIR);
    if (configDir != null && configDir.contains(":/")) { // an url of a config file
        log.debug("Configuration: " + configDir);
        URL url = new URL(configDir);
        log.debug("Configuration:   loading properties url: " + configDir);
        loadProperties(url);
        return;
    }

    // TODO: in JBoss there is a deployer that will deploy nuxeo
    // configuration files ..
    boolean isNotJBoss4 = !isJBoss4(env);

    File dir = env.getConfig();
    // File dir = new File(configDir);
    String[] names = dir.list();
    if (names != null) {
        Arrays.sort(names, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareToIgnoreCase(o2);
            }
        });
        printDeploymentOrderInfo(names);
        for (String name : names) {
            if (name.endsWith("-config.xml") || name.endsWith("-bundle.xml")) {
                // TODO because of some dep bugs (regarding the deployment of demo-ds.xml), we cannot let the
                // runtime deploy config dir at beginning...
                // until fixing this we deploy config dir from NuxeoDeployer
                if (isNotJBoss4) {
                    File file = new File(dir, name);
                    log.debug("Configuration: deploy config component: " + name);
                    try {
                        context.deploy(file.toURI().toURL());
                    } catch (IOException e) {
                        throw new IllegalArgumentException("Cannot load config from " + file, e);
                    }
                }
            } else if (name.endsWith(".config") || name.endsWith(".ini") || name.endsWith(".properties")) {
                File file = new File(dir, name);
                log.debug("Configuration: loading properties: " + name);
                loadProperties(file);
            } else {
                log.debug("Configuration: ignoring: " + name);
            }
        }
    } else if (dir.isFile()) { // a file - load it
        log.debug("Configuration: loading properties: " + dir);
        loadProperties(dir);
    } else {
        log.debug("Configuration: no configuration file found");
    }

    loadDefaultConfig();
}

From source file:org.pepstock.jem.ant.tasks.utilities.sort.DefaultComparator.java

@Override
public int compare(String o1, String o2) {
    // in case of empty strings
    if (o1.length() == 0) {
        return o2.length();
    }/*from w  ww . ja  va 2s.  c o  m*/
    if (o2.length() == 0) {
        return -1;
    }
    // checks if comparators collection is empty
    // if yes uses the default string comparator 
    if (!comparators.isEmpty()) {
        //Scans all comparator using the comparators in sequence  
        for (SingleComparator c : comparators) {
            // FIRST STRING
            // if the comparator has length, use length 
            // gets the string needed to compare following what command wants
            String partO1 = getRowPart(o1, c);
            // SECOND STRING
            // if the comparator has length, use length 
            // gets the string needed to compare following what command wants
            String partO2 = getRowPart(o2, c);
            // compares the strings creates using command 
            int compareResult = partO1.compareToIgnoreCase(partO2);
            // 2 strings are equals (comparator returns 0)
            // go to next comparator
            if (compareResult != 0) {
                // strings not equal, so changes the result basing
                // what the command wants.
                // if wants ascending, return result of comparing, otherwise
                // it changes to opposite result
                compareResult = (c.getMode().equalsIgnoreCase(SingleComparator.ASC)) ? compareResult * 1
                        : compareResult * -1;
                return compareResult;
            }
        }
        return 0;
    } else {
        return o1.compareToIgnoreCase(o2);
    }
}

From source file:org.sakaiproject.assignment2.tool.producers.ViewSubmissionsProducer.java

private void makeViewByGroupFilter(UIContainer tofill, ViewSubmissionsViewParams params,
        Assignment2 assignment) {//from ww  w. j av  a  2s. c  om
    List<Group> viewableGroups = permissionLogic.getViewableGroupsForAssignment(null, assignment);
    if (viewableGroups != null && !viewableGroups.isEmpty()) {
        UIForm groupFilterForm = UIForm.make(tofill, "group_filter_form", params);

        // we need to order the groups alphabetically. Group names are unique
        // per site, so let's make a map
        Map<String, String> groupNameToIdMap = new HashMap<String, String>();
        for (Group group : viewableGroups) {
            groupNameToIdMap.put(group.getTitle(), group.getId());
        }

        List<String> orderedGroupNames = new ArrayList<String>(groupNameToIdMap.keySet());
        Collections.sort(orderedGroupNames, new Comparator<String>() {
            public int compare(String groupName1, String groupName2) {
                return groupName1.compareToIgnoreCase(groupName2);
            }
        });

        String selectedValue = "";
        if (params.groupId != null && params.groupId.trim().length() > 0) {
            selectedValue = params.groupId;
        }

        int numItemsInDropDown = viewableGroups.size();
        boolean showAllOption = false;

        // if the assignment is restricted to one group, we won't add the "Show All" option
        if (assignment.getAssignmentGroupSet() == null || assignment.getAssignmentGroupSet().size() != 1) {
            // if there is more than one viewable group or the user has grade all perm, add the 
            // "All Sections/Groups option"
            if (viewableGroups.size() > 1
                    || permissionLogic.isUserAllowedToManageAllSubmissions(null, assignment.getContextId())) {
                showAllOption = true;
                numItemsInDropDown++;
            }
        }

        // Group Ids
        String[] view_filter_values = new String[numItemsInDropDown];
        // Group Names
        String[] view_filter_options = new String[numItemsInDropDown];

        int index = 0;

        // the first entry is "All Sections/Groups"
        if (showAllOption) {
            view_filter_values[index] = "";
            view_filter_options[index] = messageLocator
                    .getMessage("assignment2.assignment_grade.filter.all_sections");
            index++;
        }

        for (String groupName : orderedGroupNames) {
            view_filter_values[index] = groupNameToIdMap.get(groupName);
            view_filter_options[index] = groupName;
            index++;
        }

        UISelect.make(groupFilterForm, "group_filter", view_filter_values, view_filter_options, "groupId",
                selectedValue);
    }
}

From source file:org.openmrs.module.vcttrac.web.controller.VCTClientViewController.java

/**
 * Auto generated method comment/*from  w w  w.j  a v  a2s  .  c om*/
 * 
 * @param request
 * @param mav
 */
private void manageListing(HttpServletRequest request, ModelAndView mav, HttpServletResponse response) {
    VCTModuleService service = (VCTModuleService) ServiceContext.getInstance()
            .getService(VCTModuleService.class);
    int pageSize;
    String pageNumber = request.getParameter("page");
    List<VCTClient> clients = new ArrayList<VCTClient>();

    List<Integer> res;

    List<Integer> numberOfPages;

    try {

        if (VCTConfigurationUtil.isConfigured()) {
            pageSize = VCTConfigurationUtil.getNumberOfRecordPerPage();

            if (pageNumber.compareToIgnoreCase("1") == 0 || pageNumber.compareToIgnoreCase("") == 0) {
                res = new ArrayList<Integer>();

                res = service.getVCTClientsWaitingFromHIVTest();
                request.getSession().setAttribute("cl_view_res", res);

                //data collection
                for (int i = 0; i < pageSize; i++) {
                    if (res.size() == 0)
                        break;
                    if (i >= res.size() - 1) {
                        clients.add(service.getClientById(res.get(i)));
                        break;
                    } else
                        clients.add(service.getClientById(res.get(i)));
                }

                //---------paging-------navigation between pages--------
                int n = (res.size() == ((int) (res.size() / pageSize)) * pageSize) ? (res.size() / pageSize)
                        : ((int) (res.size() / pageSize)) + 1;
                numberOfPages = new ArrayList<Integer>();
                for (int i = 1; i <= n; i++) {
                    numberOfPages.add(i);
                }

                request.getSession().setAttribute("cl_view_numberOfPages", numberOfPages);
                //----------------

            } else {
                res = (List<Integer>) request.getSession().getAttribute("cl_view_res");
                numberOfPages = (List<Integer>) request.getSession().getAttribute("cl_view_numberOfPages");
                for (int i = (pageSize * (Integer.parseInt(pageNumber) - 1)); i < pageSize
                        * (Integer.parseInt(pageNumber)); i++) {
                    if (i >= res.size())
                        break;
                    else
                        clients.add(service.getClientById(res.get(i)));
                }
            }

            if (Integer.valueOf(pageNumber).intValue() > 1)
                mav.addObject("prevPage", (Integer.valueOf(pageNumber)) - 1);
            else
                mav.addObject("prevPage", -1);
            if (Integer.valueOf(pageNumber).intValue() < numberOfPages.size())
                mav.addObject("nextPage", (Integer.valueOf(pageNumber)) + 1);
            else
                mav.addObject("nextPage", -1);
            mav.addObject("lastPage", ((numberOfPages.size() >= 1) ? numberOfPages.size() : 1));

            String title = VCTTracUtil.getMessage("vcttrac.clientWaitingForResult", null);
            mav.addObject("title", title);

            //page infos
            Object[] pagerInfos = new Object[3];
            pagerInfos[0] = (res.size() == 0) ? 0 : (pageSize * (Integer.parseInt(pageNumber) - 1)) + 1;
            pagerInfos[1] = (pageSize * (Integer.parseInt(pageNumber)) <= res.size())
                    ? pageSize * (Integer.parseInt(pageNumber))
                    : res.size();
            pagerInfos[2] = res.size();

            ApplicationContext appContext = ContextProvider.getApplicationContext();

            mav.addObject("numberOfPages", numberOfPages);
            mav.addObject("clients", clients);
            mav.addObject("pageSize", pageSize);
            mav.addObject("pageInfos", appContext.getMessage("vcttrac.pagingInfo.showingResults", pagerInfos,
                    Context.getLocale()));

            FileExporter fexp = new FileExporter();

            if (request.getParameter("export") != null
                    && request.getParameter("export").compareToIgnoreCase("csv") == 0) {
                List<VCTClient> clientList = new ArrayList<VCTClient>();
                for (Integer clientId : res) {
                    clientList.add(service.getClientById(clientId));
                }
                fexp.exportToCSVFile(request, response, clientList,
                        "list_of_clients_in_vct_program_" + title + ".csv", title.toUpperCase(), "");
            }

        }
    } catch (Exception e) {
        log.error(">>>>>>>VCT>>Client>>waiting>>for>>HIV>>Test>> " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.wso2.carbon.governance.api.wsdls.WsdlManager.java

/**
 * Finds all WSDL artifacts on the registry.
 * //www . j a  v a2 s.c o m
 * @return all WSDL artifacts on the registry.
 * @throws GovernanceException if the operation failed.
 */
public Wsdl[] getAllWsdls() throws GovernanceException {
    List<String> wsdlPaths = Arrays
            .asList(GovernanceUtils.getResultPaths(registry, GovernanceConstants.WSDL_MEDIA_TYPE));
    Collections.sort(wsdlPaths, new Comparator<String>() {
        public int compare(String o1, String o2) {
            // First order by name
            int result = RegistryUtils.getResourceName(o1)
                    .compareToIgnoreCase(RegistryUtils.getResourceName(o2));
            if (result != 0) {
                return result;
            }
            // Then order by namespace
            return o1.compareToIgnoreCase(o2);
        }
    });
    List<Wsdl> wsdls = new ArrayList<Wsdl>();
    for (String wsdlPath : wsdlPaths) {
        GovernanceArtifact artifact = GovernanceUtils.retrieveGovernanceArtifactByPath(registry, wsdlPath);
        wsdls.add((Wsdl) artifact);
    }
    return wsdls.toArray(new Wsdl[wsdls.size()]);
}

From source file:org.openmrs.module.pmtct.web.view.chart.InfantPieChartView.java

/**
 * @see org.openmrs.module.pmtct.web.view.chart.AbstractChartView#createChart(java.util.Map,
 *      javax.servlet.http.HttpServletRequest)
 *//*from   w  w  w.  j  a  va 2 s  .  c o  m*/
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    UserContext userContext = Context.getUserContext();
    ApplicationContext appContext = ContextProvider.getApplicationContext();
    PMTCTModuleTag tag = new PMTCTModuleTag();

    List<Object> res = new ArrayList<Object>();

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    String title = "", descriptionTitle = "", dateInterval = "";
    Concept concept = null;
    SimpleDateFormat df = Context.getDateFormat();
    Encounter matEnc = null;

    Date today = new Date();
    Date oneYearFromNow = new Date(new Date().getTime() - PMTCTConstants.YEAR_IN_MILLISECONDS);

    String endDate = df.format(today);
    String startDate = df.format(oneYearFromNow);

    dateInterval = "(" + new SimpleDateFormat("dd-MMM-yyyy").format(oneYearFromNow) + " - "
            + new SimpleDateFormat("dd-MMM-yyyy").format(today) + ")";

    if (request.getParameter("type").compareTo("1") == 0) {
        try {
            //            Date myDate = new Date("1/1/" + ((new Date()).getYear() + 1900));
            //            String startDate = df.format(myDate);
            //            Date today=new Date();
            //            Date oneYearFromNow=new Date(new Date().getTime() - PMTCTConstants.YEAR_IN_MILLISECONDS);

            PmtctService pmtct;
            pmtct = Context.getService(PmtctService.class);
            try {
                res = pmtct.getGeneralStatForInfantTests_Charting_IFM(startDate, endDate);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            List<String> infantFeedingMethodOptions = new ArrayList<String>();
            List<Integer> infantFeedingMethodValues = new ArrayList<Integer>();
            Collection<ConceptAnswer> answers = Context.getConceptService()
                    .getConcept(PMTCTConstants.INFANT_FEEDING_METHOD).getAnswers();
            for (ConceptAnswer str : answers) {
                infantFeedingMethodOptions.add(str.getAnswerConcept().getName().getName());
                infantFeedingMethodValues.add(0);
            }
            infantFeedingMethodOptions.add("Others");
            infantFeedingMethodValues.add(0);

            for (Object ob : res) {
                int patientId = (Integer) ((Object[]) ob)[0];

                matEnc = tag.getMaternityEncounterInfo(patientId);

                String infantFeedingMethod = tag.observationValueByConcept(matEnc,
                        PMTCTConstants.INFANT_FEEDING_METHOD);

                int i = 0;
                boolean found = false;
                for (String s : infantFeedingMethodOptions) {
                    if ((s.compareToIgnoreCase(infantFeedingMethod)) == 0) {
                        infantFeedingMethodValues.set(i, infantFeedingMethodValues.get(i) + 1);
                        found = true;
                    }
                    i++;
                }

                if (!found) {
                    infantFeedingMethodValues.set(infantFeedingMethodValues.size() - 1,
                            infantFeedingMethodValues.get(infantFeedingMethodValues.size() - 1) + 1);
                }

            }

            int i = 0;
            for (String s : infantFeedingMethodOptions) {
                if (infantFeedingMethodValues.get(i) > 0) {
                    Float percentage = new Float(100 * infantFeedingMethodValues.get(i) / res.size());
                    pieDataset.setValue(s + " (" + infantFeedingMethodValues.get(i) + " , " + percentage + "%)",
                            percentage);
                }
                i++;
            }

            title = appContext.getMessage("pmtct.menu.infantTest", null, userContext.getLocale());
            concept = Context.getConceptService().getConcept(PMTCTConstants.INFANT_FEEDING_METHOD);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (request.getParameter("type").compareTo("2") == 0) {
        try {
            //            Date myDate2 = new Date("1/1/" + ((new Date()).getYear() + 1900));
            //            String startDate2 = df.format(myDate2);

            //            Date today=new Date();
            //            Date oneYearFromNow=new Date(new Date().getTime() - PMTCTConstants.YEAR_IN_MILLISECONDS);

            //            String endDate2 = df.format(today);
            //            String startDate2 = df.format(oneYearFromNow);

            //            dateInterval = "(" + new SimpleDateFormat("dd-MMM-yyyy").format(oneYearFromNow) + " - " + new SimpleDateFormat("dd-MMM-yyyy").format(today) + ")";

            PmtctService pmtct;
            pmtct = Context.getService(PmtctService.class);
            try {
                res = pmtct.getGeneralStatForInfantTests_Charting_SerAt9Months(startDate, endDate);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            List<String> hivTestResultOptions = new ArrayList<String>();

            List<Integer> ser9m_hivTestResultValues = new ArrayList<Integer>();

            Collection<ConceptAnswer> answers = Context.getConceptService()
                    .getConcept(PMTCTConstants.RESULT_OF_HIV_TEST).getAnswers();
            for (ConceptAnswer str : answers) {
                hivTestResultOptions.add(str.getAnswerConcept().getName().getName());

                ser9m_hivTestResultValues.add(0);
            }
            hivTestResultOptions.add("Others");
            ser9m_hivTestResultValues.add(0);

            for (Object ob : res) {
                int val = 0;
                String temp = "", ser9m_hivTestResult = "";

                temp = "" + ((Object[]) ob)[2];
                val = (temp.compareTo("") == 0) ? 0 : Integer.parseInt(temp);
                if (val > 0)
                    ser9m_hivTestResult = tag.getConceptNameById(temp);

                int i = 0;
                boolean ser9m_found = false;
                for (String s : hivTestResultOptions) {
                    if ((s.compareToIgnoreCase(ser9m_hivTestResult)) == 0) {
                        ser9m_hivTestResultValues.set(i, ser9m_hivTestResultValues.get(i) + 1);
                        ser9m_found = true;
                    }
                    i++;
                }

                if (!ser9m_found) {
                    ser9m_hivTestResultValues.set(ser9m_hivTestResultValues.size() - 1,
                            ser9m_hivTestResultValues.get(ser9m_hivTestResultValues.size() - 1) + 1);
                }
            }

            int i = 0;
            for (String s : hivTestResultOptions) {
                if (ser9m_hivTestResultValues.get(i) > 0) {
                    Float percentage = new Float(100 * ser9m_hivTestResultValues.get(i) / res.size());
                    pieDataset.setValue(s + " (" + ser9m_hivTestResultValues.get(i) + " , " + percentage + "%)",
                            percentage);
                }
                i++;
            }

            title = appContext.getMessage("pmtct.menu.infantTest", null, userContext.getLocale());
            concept = null;
            descriptionTitle = Context.getEncounterService()
                    .getEncounterType(PMTCTConfigurationUtils.getSerology9MonthEncounterTypeId()).getName();
            descriptionTitle += dateInterval;

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (request.getParameter("type").compareTo("3") == 0) {
        try {
            //            Date myDate3 = new Date("1/1/" + ((new Date()).getYear() + 1900));
            //            String startDate3 = df.format(myDate3);

            //            String endDate3 = df.format(today);
            //            String startDate3 = df.format(oneYearFromNow);

            //            dateInterval = "(" + new SimpleDateFormat("dd-MMM-yyyy").format(oneYearFromNow) + " - " + new SimpleDateFormat("dd-MMM-yyyy").format(today) + ")";

            PmtctService pmtct;
            pmtct = Context.getService(PmtctService.class);
            try {
                res = pmtct.getGeneralStatForInfantTests_Charting_SerAt18Months(startDate, endDate);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            List<String> hivTestResultOptions = new ArrayList<String>();

            List<Integer> ser18m_hivTestResultValues = new ArrayList<Integer>();

            Collection<ConceptAnswer> answers = Context.getConceptService()
                    .getConcept(PMTCTConstants.RESULT_OF_HIV_TEST).getAnswers();
            for (ConceptAnswer str : answers) {
                hivTestResultOptions.add(str.getAnswerConcept().getName().getName());

                ser18m_hivTestResultValues.add(0);
            }
            hivTestResultOptions.add("Others");
            ser18m_hivTestResultValues.add(0);

            for (Object ob : res) {
                int val = 0;
                String temp = "", ser18m_hivTestResult = "";

                temp = "" + ((Object[]) ob)[2];
                val = (temp.compareTo("") == 0) ? 0 : Integer.parseInt(temp);
                if (val > 0)
                    ser18m_hivTestResult = tag.getConceptNameById(temp);

                int i = 0;
                boolean ser18m_found = false;
                for (String s : hivTestResultOptions) {
                    if ((s.compareToIgnoreCase(ser18m_hivTestResult)) == 0) {
                        ser18m_hivTestResultValues.set(i, ser18m_hivTestResultValues.get(i) + 1);
                        ser18m_found = true;
                    }
                    i++;
                }

                if (!ser18m_found) {
                    ser18m_hivTestResultValues.set(ser18m_hivTestResultValues.size() - 1,
                            ser18m_hivTestResultValues.get(ser18m_hivTestResultValues.size() - 1) + 1);
                }
            }

            int i = 0;
            for (String s : hivTestResultOptions) {
                if (ser18m_hivTestResultValues.get(i) > 0) {
                    Float percentage = new Float(100 * ser18m_hivTestResultValues.get(i) / res.size());
                    pieDataset.setValue(
                            s + " (" + ser18m_hivTestResultValues.get(i) + " , " + percentage + "%)",
                            percentage);
                }
                i++;
            }

            title = appContext.getMessage("pmtct.menu.infantTest", null, userContext.getLocale());
            concept = null;
            descriptionTitle = Context.getEncounterService()
                    .getEncounterType(PMTCTConfigurationUtils.getSerology18MonthEncounterTypeId()).getName();
            descriptionTitle += dateInterval;

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (request.getParameter("type").compareTo("4") == 0) {
        try {
            PmtctService pmtct;
            pmtct = Context.getService(PmtctService.class);
            try {
                res = pmtct.getGeneralStatForInfantTests_Charting_PCR(startDate, endDate);
            } catch (SQLException ex) {
                ex.printStackTrace();
            }

            List<String> hivTestResultOptions = new ArrayList<String>();

            List<Integer> pcr_hivTestResultValues = new ArrayList<Integer>();

            Collection<ConceptAnswer> answers = Context.getConceptService()
                    .getConcept(PMTCTConstants.RESULT_OF_HIV_TEST).getAnswers();
            for (ConceptAnswer str : answers) {
                hivTestResultOptions.add(str.getAnswerConcept().getName().getName());

                pcr_hivTestResultValues.add(0);
            }
            hivTestResultOptions.add("Others");
            pcr_hivTestResultValues.add(0);

            for (Object ob : res) {
                int val = 0;
                String temp = "", pcr_hivTestResult = "";

                temp = "" + ((Object[]) ob)[2];
                val = (temp.compareTo("") == 0) ? 0 : Integer.parseInt(temp);
                if (val > 0)
                    pcr_hivTestResult = tag.getConceptNameById(temp);

                int i = 0;
                boolean pcr_found = false;
                for (String s : hivTestResultOptions) {
                    if ((s.compareToIgnoreCase(pcr_hivTestResult)) == 0) {
                        pcr_hivTestResultValues.set(i, pcr_hivTestResultValues.get(i) + 1);
                        pcr_found = true;
                    }
                    i++;
                }

                if (!pcr_found) {
                    pcr_hivTestResultValues.set(pcr_hivTestResultValues.size() - 1,
                            pcr_hivTestResultValues.get(pcr_hivTestResultValues.size() - 1) + 1);
                }
            }

            int i = 0;
            for (String s : hivTestResultOptions) {
                if (pcr_hivTestResultValues.get(i) > 0) {
                    Float percentage = new Float(100 * pcr_hivTestResultValues.get(i) / res.size());
                    pieDataset.setValue(s + " (" + pcr_hivTestResultValues.get(i) + " , " + percentage + "%)",
                            percentage);
                }
                i++;
            }

            title = appContext.getMessage("pmtct.menu.infantTest", null, userContext.getLocale());
            concept = null;
            descriptionTitle = Context.getEncounterService()
                    .getEncounterType(PMTCTConfigurationUtils.getPCRTestEncounterTypeId()).getName();
            descriptionTitle += dateInterval;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    JFreeChart chart = ChartFactory.createPieChart(title + " : "
            + ((null != concept) ? concept.getPreferredName(userContext.getLocale()) + dateInterval
                    : descriptionTitle),
            pieDataset, true, true, false);

    return chart;
}

From source file:com.orange.oidc.secproxy_service.Service.java

String sortScope(String scope) {
    // sort scope in alphabetical order
    if (scope != null) {
        scope = scope.toLowerCase(Locale.getDefault());
        // offline_access is mandatory
        if (!scope.contains("offline_access")) {
            // TazTag : disables specific scope
            // scope += " offline_access";
        }/* ww  w .  j  a v a 2  s .c  o  m*/

        String scopes[] = scope.split("\\ ");
        if (scopes != null) {
            Arrays.sort(scopes, new Comparator<String>() {
                @Override
                public int compare(String s1, String s2) {
                    return s1.compareToIgnoreCase(s2);
                }
            });
            scope = null;
            // filter null or empty strings
            for (int i = 0; i < scopes.length; i++) {
                if (scopes[i] != null && scopes[i].length() > 0) {
                    if (scope == null)
                        scope = scopes[i];
                    else
                        scope += (" " + scopes[i]);
                }
            }
        }
    }
    return scope;
}

From source file:org.openecomp.sdc.validation.impl.validators.EcompGuideLineValidator.java

@SuppressWarnings("unchecked")
private void validateNovaServerResourceMetaData(String fileName, String resourceId, Resource resource,
        GlobalValidationContext globalValidationContext) {
    Map<String, Object> novaServerProp = resource.getProperties();
    Object novaServerPropMetadata;
    if (MapUtils.isNotEmpty(novaServerProp)) {
        novaServerPropMetadata = novaServerProp.get("metadata");
        if (novaServerPropMetadata == null) {
            globalValidationContext.addMessage(fileName, ErrorLevel.WARNING,
                    ErrorMessagesFormatBuilder.getErrorWithParameters(
                            Messages.MISSING_NOVA_SERVER_METADATA.getErrorMessage(), resourceId));
        } else if (novaServerPropMetadata instanceof Map) {
            TreeMap<String, Object> propertyMap = new TreeMap(new Comparator<String>() {

                @Override//from w  w  w  .j av a2 s .  c  o  m
                public int compare(String o1, String o2) {
                    return o1.compareToIgnoreCase(o2);
                }

                @Override
                public boolean equals(Object obj) {
                    return false;
                }
            });
            propertyMap.putAll((Map) novaServerPropMetadata);
            if (!propertyMap.containsKey("vf_module_id")) {
                globalValidationContext.addMessage(fileName, ErrorLevel.WARNING,
                        ErrorMessagesFormatBuilder.getErrorWithParameters(
                                Messages.MISSING_NOVA_SERVER_VF_MODULE_ID.getErrorMessage(), resourceId));
            }
            if (!propertyMap.containsKey("vnf_id")) {
                globalValidationContext.addMessage(fileName, ErrorLevel.WARNING,
                        ErrorMessagesFormatBuilder.getErrorWithParameters(
                                Messages.MISSING_NOVA_SERVER_VNF_ID.getErrorMessage(), resourceId));
            }
        }
    }
}