Example usage for java.util Collections max

List of usage examples for java.util Collections max

Introduction

In this page you can find the example usage for java.util Collections max.

Prototype

public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) 

Source Link

Document

Returns the maximum element of the given collection, according to the natural ordering of its elements.

Usage

From source file:org.apache.lens.cube.metadata.CubeMetastoreClient.java

public Date getStorageTableStartDate(String storageTable, String factTableName) throws LensException {
    List<Date> startDates = getStorageTimes(storageTable, MetastoreUtil.getStoragetableStartTimesKey());
    startDates.add(getFactTable(factTableName).getStartTime());
    return Collections.max(startDates);
}

From source file:com.pearson.dashboard.util.Util.java

public static void retrieveTestCases(DashboardForm dashboardForm, Configuration configuration,
        String cutoffDate) throws IOException, URISyntaxException {
    RallyRestApi restApi = loginRally(configuration);
    List<TestCase> testCases = new ArrayList<TestCase>();
    QueryFilter queryFilter = new QueryFilter("CreationDate", ">=", cutoffDate)
            .and(new QueryFilter("Type", "=", "Regression"));
    QueryRequest defectRequest = new QueryRequest("testcases");
    defectRequest.setQueryFilter(queryFilter);
    defectRequest.setFetch(//  ww w  .  ja  va 2  s. co  m
            new Fetch("FormattedID", "LastVerdict", "Name", "Description", "LastRun", "LastBuild", "Priority"));
    defectRequest.setProject("/project/" + dashboardForm.getProjectId());
    defectRequest.setScopedDown(true);
    defectRequest.setLimit(10000);
    defectRequest.setOrder("FormattedID desc");
    boolean dataNotReceived = true;
    while (dataNotReceived) {
        try {
            QueryResponse projectDefects = restApi.query(defectRequest);
            JsonArray defectsArray = projectDefects.getResults();
            dataNotReceived = false;

            for (int i = 0; i < defectsArray.size(); i++) {
                TestCase testCase = new TestCase();
                JsonElement elements = defectsArray.get(i);
                JsonObject object = elements.getAsJsonObject();
                testCase.setTestCaseId(object.get("FormattedID").getAsString());
                testCase.setLastVerdict(
                        object.get("LastVerdict") == null || object.get("LastVerdict").isJsonNull() ? ""
                                : object.get("LastVerdict").getAsString());
                testCase.setName(object.get("Name") == null || object.get("Name").isJsonNull() ? ""
                        : object.get("Name").getAsString());
                testCase.setDescription(
                        object.get("Description") == null || object.get("Description").isJsonNull() ? ""
                                : object.get("Description").getAsString());
                testCase.setLastRun(object.get("LastRun") == null || object.get("LastRun").isJsonNull() ? ""
                        : object.get("LastRun").getAsString());
                testCase.setLastBuild(
                        object.get("LastBuild") == null || object.get("LastBuild").isJsonNull() ? ""
                                : object.get("LastBuild").getAsString());
                testCase.setPriority(object.get("Priority") == null || object.get("Priority").isJsonNull() ? ""
                        : object.get("Priority").getAsString());
                testCases.add(testCase);
            }
            dashboardForm.setTestCases(testCases);
            restApi.close();

            List<Priority> priorities = new ArrayList<Priority>();
            Priority priority0 = new Priority();
            priority0.setPriorityName("Pass");
            Priority priority1 = new Priority();
            priority1.setPriorityName("Blocked");
            Priority priority2 = new Priority();
            priority2.setPriorityName("Error");
            Priority priority3 = new Priority();
            priority3.setPriorityName("Fail");
            Priority priority4 = new Priority();
            priority4.setPriorityName("Inconclusive");
            Priority priority5 = new Priority();
            priority5.setPriorityName("NotAttempted");
            if (null != testCases) {
                for (TestCase testCase : testCases) {
                    if (testCase.getLastVerdict().equalsIgnoreCase("Pass")) {
                        priority0.setPriorityCount(priority0.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("Blocked")) {
                        priority1.setPriorityCount(priority1.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("Error")) {
                        priority2.setPriorityCount(priority2.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("Fail")) {
                        priority3.setPriorityCount(priority3.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("Inconclusive")) {
                        priority4.setPriorityCount(priority4.getPriorityCount() + 1);
                    }
                    if (testCase.getLastVerdict().equalsIgnoreCase("")) {
                        priority5.setPriorityCount(priority5.getPriorityCount() + 1);
                    }
                }
            }
            List<Integer> arrayList = new ArrayList<Integer>();
            arrayList.add(priority0.getPriorityCount());
            arrayList.add(priority1.getPriorityCount());
            arrayList.add(priority2.getPriorityCount());
            arrayList.add(priority3.getPriorityCount());
            arrayList.add(priority4.getPriorityCount());
            arrayList.add(priority5.getPriorityCount());
            Integer maximumCount = Collections.max(arrayList);
            if (maximumCount <= 0) {
                priority0.setPxSize("0");
                priority1.setPxSize("0");
                priority2.setPxSize("0");
                priority3.setPxSize("0");
                priority4.setPxSize("0");
                priority5.setPxSize("0");
            } else {
                priority0.setPxSize(Math.round((100 * priority0.getPriorityCount()) / maximumCount) + "");
                priority1.setPxSize(Math.round((100 * priority1.getPriorityCount()) / maximumCount) + "");
                priority2.setPxSize(Math.round((100 * priority2.getPriorityCount()) / maximumCount) + "");
                priority3.setPxSize(Math.round((100 * priority3.getPriorityCount()) / maximumCount) + "");
                priority4.setPxSize(Math.round((100 * priority4.getPriorityCount()) / maximumCount) + "");
                priority5.setPxSize(Math.round((100 * priority5.getPriorityCount()) / maximumCount) + "");
            }
            priorities.add(priority0);
            priorities.add(priority1);
            priorities.add(priority2);
            priorities.add(priority3);
            priorities.add(priority4);
            priorities.add(priority5);

            dashboardForm.setTestCasesCount(testCases.size());
            dashboardForm.setTestCasesPriorities(priorities);
        } catch (HttpHostConnectException connectException) {
            if (restApi != null) {
                restApi.close();
            }
            try {
                restApi = loginRally(configuration);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.eclipse.dataset.Stats.java

public static double[] outlierValuesList(final Dataset a, int nl, int nh) {
    final List<Double> lList = new ArrayList<Double>(nl);
    final List<Double> hList = new ArrayList<Double>(nh);
    //      final List<Double> lList = new LinkedList<Double>();
    //      final List<Double> hList = new LinkedList<Double>();

    double lx = Double.POSITIVE_INFINITY;
    double hx = Double.NEGATIVE_INFINITY;

    IndexIterator it = a.getIterator();/*from  w ww  .j  a  v a  2 s  . co  m*/
    while (it.hasNext()) {
        double x = a.getElementDoubleAbs(it.index);
        if (x < lx) {
            if (lList.size() == nl) {
                lList.remove(lx);
            }
            lList.add(x);
            lx = Collections.max(lList);
        } else if (x == lx) {
            if (lList.size() < nl) {
                lList.add(x);
            }
        }

        if (x > hx) {
            if (hList.size() == nh) {
                hList.remove(hx);
            }
            hList.add(x);
            hx = Collections.min(hList);
        } else if (x == hx) {
            if (hList.size() < nh) {
                hList.add(x);
            }
        }
    }

    nl = lList.size();
    nh = hList.size();

    // Attempt to make values distinct
    if (lx >= hx) {
        Collections.sort(hList);
        for (double h : hList) {
            if (h > hx) {
                hx = h;
                break;
            }
            nh--;
        }
        if (lx >= hx) {
            Collections.sort(lList);
            Collections.reverse(lList);
            for (double l : lList) {
                if (l < lx) {
                    lx = l;
                    break;
                }
                nl--;
            }
        }
    }
    return new double[] { lx, hx, nl, nh };
}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

private void updateMainFrameListSelection(final int track, final int section, final MouseEvent event) {
    CorelyzerApp app = CorelyzerApp.getApp();
    if (app == null) {
        return;//  www  .jav  a 2s. c o m
    }

    if (track >= 0) {
        // Now, we need to traverse app's list model
        // to find match of native id
        // index conversion (native to java list)

        CRDefaultListModel sessionModel = app.getSessionListModel();
        int sessionIndex = -1;
        TrackSceneNode trackNode = null;
        for (int i = 0; i < sessionModel.size(); i++) {
            Session session = (Session) sessionModel.elementAt(i);
            trackNode = session.getTrackSceneNodeWithTrackId(track);

            if (trackNode != null) {
                sessionIndex = i;
            }
        }

        if (sessionIndex < 0) {
            return;
        }

        // Set selected session
        app.getSessionList().setSelectedIndex(sessionIndex);

        // Track
        int ssize;
        boolean found = false;
        CRDefaultListModel tmodel = app.getTrackListModel();
        // tsize = tmodel.getSize();
        TrackSceneNode tt;
        CoreSection cs = null;

        for (int i = 0; i < tmodel.size() && !found; i++) {
            tt = (TrackSceneNode) tmodel.elementAt(i);

            if (track == tt.getId()) {
                selectedTrackIndex = i;
                ssize = tt.getNumCores();

                for (int j = 0; j < ssize; j++) {
                    cs = tt.getCoreSection(j);
                    if (section == cs.getId()) {
                        selectedTrackSectionIndex = j;
                        found = true;
                        break;
                    }
                }
            }
        }

        if (!found || cs == null) {
            return;
        }

        // update ui
        CorelyzerApp.getApp().getTrackList().setSelectedIndex(selectedTrackIndex);
        JList secList = CorelyzerApp.getApp().getSectionList();
        boolean selected = secList.isSelectedIndex(selectedTrackSectionIndex);
        List<Integer> indices = new ArrayList<Integer>();
        indices.addAll(Arrays.asList(ArrayUtils.toObject(secList.getSelectedIndices())));
        if (event.isControlDown() || (event.isMetaDown() && CorelyzerApp.MAC_OS_X)) { // toggle selection
            if (indices.contains(selectedTrackSectionIndex))
                indices.remove(new Integer(selectedTrackSectionIndex));
            else
                indices.add(selectedTrackSectionIndex);

            int[] newSelArray = ArrayUtils.toPrimitive(indices.toArray(new Integer[0]));
            secList.setSelectedIndices(newSelArray);
        } else if (event.isShiftDown()) { // select range
            int[] toSel = null;
            if (indices.size() == 0) {
                toSel = makeRangeArray(0, selectedTrackSectionIndex);
            } else {
                final int minSel = Collections.min(indices);
                final int maxSel = Collections.max(indices);
                if (selectedTrackSectionIndex < minSel) {
                    toSel = makeRangeArray(selectedTrackSectionIndex, minSel);
                } else if (selectedTrackSectionIndex > maxSel) {
                    toSel = makeRangeArray(maxSel, selectedTrackSectionIndex);
                }
            }
            secList.setSelectedIndices(toSel);
        } else if (!(event.isAltDown() && selected)) {
            // don't modify selection if Alt is down and section was already
            // selected...user is presumably trying to move it
            secList.setSelectedIndex(selectedTrackSectionIndex);
        }

        CRDefaultListModel lm = CorelyzerApp.getApp().getSectionListModel();
        String secName = null;
        if (lm != null) {
            Object selSec = lm.getElementAt(selectedTrackSectionIndex);
            if (selSec != null) {
                secName = selSec.toString();
            } else {
                System.out.println("no object at index");
            }
        } else {
            System.out.println("no list model");
        }

        JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0);
        String trackName = CorelyzerApp.getApp().getTrackListModel().getElementAt(selectedTrackIndex)
                .toString();
        title.setText("Track: " + trackName);
        JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1);
        stitle.setText("Section: " + secName);

        // Enable section-based popupMenu options
        this.setEnableSectionBasedPopupMenuOptions(true);

        // 2/5/2012 brg: check Stagger Sections menu item if necessary
        final boolean trackIsStaggered = SceneGraph.trackIsStaggered(selectedTrack);
        AbstractButton ab = (AbstractButton) this.scenePopupMenu.getComponent(14);
        ab.getModel().setSelected(trackIsStaggered);

        // check section and graph lock menu items
        final boolean sectionIsLocked = !SceneGraph.isSectionMovable(selectedTrack, selectedTrackSection);
        ab = (AbstractButton) this.scenePopupMenu.getComponent(7);
        ab.getModel().setSelected(sectionIsLocked);
        final boolean sectionGraphIsLocked = !SceneGraph.isSectionGraphMovable(selectedTrack,
                selectedTrackSection);
        ab = (AbstractButton) this.scenePopupMenu.getComponent(8);
        ab.getModel().setSelected(sectionGraphIsLocked);

        CoreSectionImage csImg = cs.getCoreSectionImage();
        if (csImg != null && csImg.getId() != -1) {
            this.propertyMenuItem.setEnabled(true);
            this.splitMenuItem.setEnabled(true);
        } else {
            this.propertyMenuItem.setEnabled(false);
            this.splitMenuItem.setEnabled(false);
        }

        // System.out.println("---> [in Java DS] Picked Track " + track +
        // " and Track Section " + section);
        // String secname = CorelyzerApp.getApp().getSectionListModel().
        // getElementAt(section).toString();
        // System.out.println("---> [INFO] Section " + secname +
        // " is selected");
    } else {
        JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0);
        title.setText("Track: N/A");
        JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1);
        stitle.setText("Section: N/A");

        // disable section based items
        this.setEnableSectionBasedPopupMenuOptions(false);
    }
}

From source file:org.eclipse.january.dataset.Stats.java

static double[] outlierValuesList(final Dataset a, int nl, int nh) {
    final List<Double> lList = new ArrayList<Double>(nl);
    final List<Double> hList = new ArrayList<Double>(nh);
    //      final List<Double> lList = new LinkedList<Double>();
    //      final List<Double> hList = new LinkedList<Double>();

    double lx = Double.POSITIVE_INFINITY;
    double hx = Double.NEGATIVE_INFINITY;

    IndexIterator it = a.getIterator();/*from w  w  w  .jav  a  2  s .com*/
    while (it.hasNext()) {
        double x = a.getElementDoubleAbs(it.index);
        if (x < lx) {
            if (lList.size() == nl) {
                lList.remove(lx);
            }
            lList.add(x);
            lx = Collections.max(lList);
        } else if (x == lx) {
            if (lList.size() < nl) {
                lList.add(x);
            }
        }

        if (x > hx) {
            if (hList.size() == nh) {
                hList.remove(hx);
            }
            hList.add(x);
            hx = Collections.min(hList);
        } else if (x == hx) {
            if (hList.size() < nh) {
                hList.add(x);
            }
        }
    }

    nl = lList.size();
    nh = hList.size();

    // Attempt to make values distinct
    if (lx >= hx) {
        Collections.sort(hList);
        for (double h : hList) {
            if (h > hx) {
                hx = h;
                break;
            }
            nh--;
        }
        if (lx >= hx) {
            Collections.sort(lList);
            Collections.reverse(lList);
            for (double l : lList) {
                if (l < lx) {
                    lx = l;
                    break;
                }
                nl--;
            }
        }
    }
    return new double[] { lx, hx, nl, nh };
}

From source file:StockForecast.Main.java

private void generateID() throws Exception {
    String selectItem = jComboBox1.getSelectedItem().toString();
    Connect connect = new Connect();
    ResultSet rs = connect.connectSelect("1", "SELECT * FROM ROOT.LOGIN NATURAL JOIN PROFILE");
    ArrayList<String> stringList = new ArrayList<String>();
    while (rs.next()) {
        String usrId = rs.getString("loginid");
        System.out.println(usrId);
        stringList.add(usrId);/*from  www. ja  v a 2s  .  co  m*/
    }
    if (stringList.isEmpty()) {
        if (selectItem.equals("Admin")) {
            jLabel8.setText("ADM100001");
        } else if (selectItem.equals("User")) {
            jLabel8.setText("USR100001");
        } else {
            JOptionPane.showMessageDialog(this, "ERROR");
        }
    } else {
        System.out.println(stringList);
        Iterator<String> itr = stringList.iterator();
        ArrayList<Integer> admin = new ArrayList<Integer>();
        ArrayList<Integer> user = new ArrayList<Integer>();
        while (itr.hasNext()) {
            String iter = itr.next();
            if (iter.contains("ADM")) {
                String[] parts = iter.split("ADM");
                int num = Integer.parseInt(parts[1]);
                admin.add(num);
            } else if (iter.contains("USR")) {
                String[] parts = iter.split("USR");
                int num = Integer.parseInt(parts[1]);
                user.add(num);
            }
        }
        System.out.println("This is Admin: " + admin);
        System.out.println("This is User: " + user);
        if (user.isEmpty() && !admin.isEmpty()) {
            int newNumAdm = Collections.max(admin) + 1;
            String newAdmNum = Integer.toString(newNumAdm);
            if (selectItem.equals("Admin")) {
                jLabel8.setText("ADM" + newAdmNum);
            } else if (selectItem.equals("User")) {
                jLabel8.setText("USR100001");
            } else {
                JOptionPane.showMessageDialog(this, "ERROR");
            }

        } else if (admin.isEmpty() && !user.isEmpty()) {
            int newNumUsr = Collections.max(user) + 1;
            String newUsrNum = Integer.toString(newNumUsr);
            if (selectItem.equals("Admin")) {
                jLabel8.setText("ADM100001");
            } else if (selectItem.equals("User")) {
                jLabel8.setText("USR" + newUsrNum);
            } else {
                JOptionPane.showMessageDialog(this, "ERROR");
            }
        } else {
            int newNumAdm = Collections.max(admin) + 1;
            int newNumUsr = Collections.max(user) + 1;
            String newAdmNum = Integer.toString(newNumAdm);
            String newUsrNum = Integer.toString(newNumUsr);
            if (selectItem.equals("Admin")) {
                jLabel8.setText("ADM" + newAdmNum);
            } else if (selectItem.equals("User")) {
                jLabel8.setText("USR" + newUsrNum);
            } else {
                JOptionPane.showMessageDialog(this, "ERROR");
            }
        }
    }

}

From source file:com.pearson.dashboard.util.Util.java

public static void retrieveTestCasesUsingSets(DashboardForm dashboardForm, Configuration configuration,
        String cutoffDateStr, List<String> testSets) throws IOException, URISyntaxException, ParseException {
    RallyRestApi restApi = loginRally(configuration);
    QueryRequest testSetRequest = new QueryRequest("TestSet");
    testSetRequest.setProject("/project/" + dashboardForm.getProjectId());
    String wsapiVersion = "1.43";
    restApi.setWsapiVersion(wsapiVersion);

    testSetRequest.setFetch(new Fetch(new String[] { "Name", "Priority", "Description", "TestCases",
            "FormattedID", "LastVerdict", "LastBuild", "LastRun" }));
    QueryFilter queryFilter = new QueryFilter("FormattedID", "=", testSets.get(0));
    int q = 1;//  w ww  .  j ava2 s  . com
    while (testSets.size() > q) {
        queryFilter = queryFilter.or(new QueryFilter("FormattedID", "=", testSets.get(q)));
        q++;
    }
    testSetRequest.setQueryFilter(queryFilter);
    boolean dataNotReceived = true;
    while (dataNotReceived) {
        try {
            QueryResponse testSetQueryResponse = restApi.query(testSetRequest);
            dataNotReceived = false;
            List<Priority> priorities = new ArrayList<Priority>();
            Priority priority0 = new Priority();
            priority0.setPriorityName("Pass");
            Priority priority1 = new Priority();
            priority1.setPriorityName("Blocked");
            Priority priority2 = new Priority();
            priority2.setPriorityName("Error");
            Priority priority3 = new Priority();
            priority3.setPriorityName("Fail");
            Priority priority4 = new Priority();
            priority4.setPriorityName("Inconclusive");
            Priority priority5 = new Priority();
            priority5.setPriorityName("NotAttempted");

            int testCasesCount = 0;
            List<TestCase> testCases = new ArrayList<TestCase>();
            for (int i = 0; i < testSetQueryResponse.getResults().size(); i++) {
                JsonObject testSetJsonObject = testSetQueryResponse.getResults().get(i).getAsJsonObject();
                int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonArray().size();
                if (numberOfTestCases > 0) {
                    DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
                    Date cutoffDate = (Date) formatter1.parse(cutoffDateStr);

                    for (int j = 0; j < numberOfTestCases; j++) {
                        JsonObject jsonObject = testSetJsonObject.get("TestCases").getAsJsonArray().get(j)
                                .getAsJsonObject();
                        TestCase testCase = new TestCase();
                        testCase.setTestCaseId(jsonObject.get("FormattedID").getAsString());
                        Date lastVerdictDate = null;
                        if (null != jsonObject.get("LastRun") && !jsonObject.get("LastRun").isJsonNull()) {
                            lastVerdictDate = (Date) formatter1.parse(jsonObject.get("LastRun").getAsString());
                        }
                        String lastVerdict = "";
                        if (!jsonObject.get("LastVerdict").isJsonNull()) {
                            lastVerdict = jsonObject.get("LastVerdict").getAsString();
                        }
                        if (null != lastVerdictDate && lastVerdictDate.compareTo(cutoffDate) >= 0) {
                            if (lastVerdict.equalsIgnoreCase("Pass")) {
                                priority0.setPriorityCount(priority0.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("Blocked")) {
                                priority1.setPriorityCount(priority1.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("Error")) {
                                priority2.setPriorityCount(priority2.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("Fail")) {
                                priority3.setPriorityCount(priority3.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("Inconclusive")) {
                                priority4.setPriorityCount(priority4.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("")) {
                                priority5.setPriorityCount(priority5.getPriorityCount() + 1);
                            }

                        } else {
                            priority5.setPriorityCount(priority5.getPriorityCount() + 1);
                        }
                        testCasesCount++;
                        testCase.setLastVerdict(jsonObject.get("LastVerdict") == null
                                || jsonObject.get("LastVerdict").isJsonNull() ? ""
                                        : jsonObject.get("LastVerdict").getAsString());
                        testCase.setName(
                                jsonObject.get("Name") == null || jsonObject.get("Name").isJsonNull() ? ""
                                        : jsonObject.get("Name").getAsString());
                        testCase.setDescription(jsonObject.get("Description") == null
                                || jsonObject.get("Description").isJsonNull() ? ""
                                        : jsonObject.get("Description").getAsString());
                        testCase.setLastRun(
                                jsonObject.get("LastRun") == null || jsonObject.get("LastRun").isJsonNull() ? ""
                                        : jsonObject.get("LastRun").getAsString());
                        testCase.setLastBuild(
                                jsonObject.get("LastBuild") == null || jsonObject.get("LastBuild").isJsonNull()
                                        ? ""
                                        : jsonObject.get("LastBuild").getAsString());
                        testCase.setPriority(
                                jsonObject.get("Priority") == null || jsonObject.get("Priority").isJsonNull()
                                        ? ""
                                        : jsonObject.get("Priority").getAsString());
                        testCases.add(testCase);
                    }
                }
            }
            dashboardForm.setTestCases(testCases);
            List<Integer> arrayList = new ArrayList<Integer>();
            arrayList.add(priority0.getPriorityCount());
            arrayList.add(priority1.getPriorityCount());
            arrayList.add(priority2.getPriorityCount());
            arrayList.add(priority3.getPriorityCount());
            arrayList.add(priority4.getPriorityCount());
            arrayList.add(priority5.getPriorityCount());
            Integer maximumCount = Collections.max(arrayList);
            if (maximumCount <= 0) {
                priority0.setPxSize("0");
                priority1.setPxSize("0");
                priority2.setPxSize("0");
                priority3.setPxSize("0");
                priority4.setPxSize("0");
                priority5.setPxSize("0");
            } else {
                priority0.setPxSize(Math.round((100 * priority0.getPriorityCount()) / maximumCount) + "");
                priority1.setPxSize(Math.round((100 * priority1.getPriorityCount()) / maximumCount) + "");
                priority2.setPxSize(Math.round((100 * priority2.getPriorityCount()) / maximumCount) + "");
                priority3.setPxSize(Math.round((100 * priority3.getPriorityCount()) / maximumCount) + "");
                priority4.setPxSize(Math.round((100 * priority4.getPriorityCount()) / maximumCount) + "");
                priority5.setPxSize(Math.round((100 * priority5.getPriorityCount()) / maximumCount) + "");
            }
            priorities.add(priority0);
            priorities.add(priority1);
            priorities.add(priority2);
            priorities.add(priority3);
            priorities.add(priority4);
            priorities.add(priority5);

            dashboardForm.setTestCasesCount(testCasesCount);
            dashboardForm.setTestCasesPriorities(priorities);
        } catch (HttpHostConnectException connectException) {
            if (restApi != null) {
                restApi.close();
            }
            try {
                restApi = loginRally(configuration);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.pearson.dashboard.util.Util.java

public static void retrieveTestResults(DashboardForm dashboardForm, Configuration configuration,
        String cutoffDateStr, List<String> testSets) throws IOException, URISyntaxException, ParseException {
    RallyRestApi restApi = loginRally(configuration);
    QueryRequest testCaseResultsRequest = new QueryRequest("TestCaseResult");
    testCaseResultsRequest.setFetch(// w  ww  .  j  av  a 2s.c  o m
            new Fetch("Build", "TestCase", "TestSet", "Verdict", "FormattedID", "Date", "TestCaseCount"));
    if (testSets == null || testSets.isEmpty()) {
        testSets = new ArrayList<String>();
        testSets.add("TS0");
    }
    QueryFilter queryFilter = new QueryFilter("TestSet.FormattedID", "=", testSets.get(0));
    int q = 1;
    while (testSets.size() > q) {
        queryFilter = queryFilter.or(new QueryFilter("TestSet.FormattedID", "=", testSets.get(q)));
        q++;
    }
    testCaseResultsRequest.setLimit(4000);
    testCaseResultsRequest.setQueryFilter(queryFilter);
    boolean dataNotReceived = true;
    while (dataNotReceived) {
        try {
            QueryResponse testCaseResultResponse = restApi.query(testCaseResultsRequest);
            JsonArray array = testCaseResultResponse.getResults();
            int numberTestCaseResults = array.size();
            dataNotReceived = false;
            List<Priority> priorities = new ArrayList<Priority>();
            Priority priority0 = new Priority();
            priority0.setPriorityName("Pass");
            Priority priority1 = new Priority();
            priority1.setPriorityName("Blocked");
            Priority priority2 = new Priority();
            priority2.setPriorityName("Error");
            Priority priority3 = new Priority();
            priority3.setPriorityName("Fail");
            Priority priority4 = new Priority();
            priority4.setPriorityName("Inconclusive");
            Priority priority5 = new Priority();
            priority5.setPriorityName("NotAttempted");
            List<TestCase> testCases = new ArrayList<TestCase>();
            List<TestResult> testResults = new ArrayList<TestResult>();
            if (numberTestCaseResults > 0) {
                for (int i = 0; i < numberTestCaseResults; i++) {
                    TestResult testResult = new TestResult();
                    TestCase testCase = new TestCase();
                    String build = array.get(i).getAsJsonObject().get("Build").getAsString();
                    String verdict = array.get(i).getAsJsonObject().get("Verdict").getAsString();
                    DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
                    String strDate = array.get(i).getAsJsonObject().get("Date").getAsString().substring(0, 10);
                    int hour = Integer.parseInt(
                            array.get(i).getAsJsonObject().get("Date").getAsString().substring(11, 13));
                    int min = Integer.parseInt(
                            array.get(i).getAsJsonObject().get("Date").getAsString().substring(14, 16));
                    Date date = (Date) formatter1.parse(strDate);
                    date.setHours(hour);
                    date.setMinutes(min);
                    JsonObject testSetJsonObj = array.get(i).getAsJsonObject().get("TestSet").getAsJsonObject();
                    JsonObject testCaseJsonObj = array.get(i).getAsJsonObject().get("TestCase")
                            .getAsJsonObject();
                    String testSet = testSetJsonObj.get("FormattedID").getAsString();
                    String testCaseId = testCaseJsonObj.get("FormattedID").getAsString();
                    int resultExists = testResultExists(testSet, testCaseId, date, testResults, testCases);
                    if (resultExists != 0) {
                        testResult.setDate(date);
                        testResult.setStatus(verdict);
                        testResult.setTestCase(testCaseId);
                        testResult.setTestSet(testSet);
                        testResults.add(testResult);
                        testCase.setTestCaseId(testCaseId);
                        testCase.setLastVerdict(verdict);
                        testCase.setName(testSet);
                        testCase.setDescription("");
                        testCase.setLastRun(strDate);
                        testCase.setLastBuild(build);
                        testCase.setPriority("");
                        testCases.add(testCase);
                    }
                }
            }
            for (TestResult result : testResults) {
                String verdict = result.getStatus();
                if (verdict.equalsIgnoreCase("error")) {
                    priority2.setPriorityCount(priority2.getPriorityCount() + 1);
                } else if (verdict.equalsIgnoreCase("pass")) {
                    priority0.setPriorityCount(priority0.getPriorityCount() + 1);
                } else if (verdict.equalsIgnoreCase("fail")) {
                    priority3.setPriorityCount(priority3.getPriorityCount() + 1);
                } else if (verdict.equalsIgnoreCase("inconclusive")) {
                    priority4.setPriorityCount(priority4.getPriorityCount() + 1);
                } else if (verdict.equalsIgnoreCase("blocked")) {
                    priority1.setPriorityCount(priority1.getPriorityCount() + 1);
                }
            }

            dashboardForm.setTestCases(testCases);

            QueryRequest testCaseCountReq = new QueryRequest("TestSet");
            testCaseCountReq.setFetch(new Fetch("FormattedID", "Name", "TestCaseCount"));
            queryFilter = new QueryFilter("FormattedID", "=", testSets.get(0));
            q = 1;
            while (testSets.size() > q) {
                queryFilter = queryFilter.or(new QueryFilter("FormattedID", "=", testSets.get(q)));
                q++;
            }
            testCaseCountReq.setQueryFilter(queryFilter);
            QueryResponse testCaseResponse = restApi.query(testCaseCountReq);
            int testCaseCount = 0;
            for (int i = 0; i < testCaseResponse.getResults().size(); i++) {
                testCaseCount = testCaseCount + testCaseResponse.getResults().get(i).getAsJsonObject()
                        .get("TestCaseCount").getAsInt();
            }

            int unAttempted = testCaseCount - priority0.getPriorityCount() - priority1.getPriorityCount()
                    - priority2.getPriorityCount() - priority3.getPriorityCount()
                    - priority4.getPriorityCount();
            priority5.setPriorityCount(unAttempted);

            List<Integer> arrayList = new ArrayList<Integer>();
            arrayList.add(priority0.getPriorityCount());
            arrayList.add(priority1.getPriorityCount());
            arrayList.add(priority2.getPriorityCount());
            arrayList.add(priority3.getPriorityCount());
            arrayList.add(priority4.getPriorityCount());
            arrayList.add(priority5.getPriorityCount());
            Integer maximumCount = Collections.max(arrayList);
            if (maximumCount <= 0) {
                priority0.setPxSize("0");
                priority1.setPxSize("0");
                priority2.setPxSize("0");
                priority3.setPxSize("0");
                priority4.setPxSize("0");
                priority5.setPxSize("0");
            } else {
                priority0.setPxSize(Math.round((100 * priority0.getPriorityCount()) / maximumCount) + "");
                priority1.setPxSize(Math.round((100 * priority1.getPriorityCount()) / maximumCount) + "");
                priority2.setPxSize(Math.round((100 * priority2.getPriorityCount()) / maximumCount) + "");
                priority3.setPxSize(Math.round((100 * priority3.getPriorityCount()) / maximumCount) + "");
                priority4.setPxSize(Math.round((100 * priority4.getPriorityCount()) / maximumCount) + "");
                priority5.setPxSize(Math.round((100 * priority5.getPriorityCount()) / maximumCount) + "");
            }
            priorities.add(priority0);
            priorities.add(priority1);
            priorities.add(priority2);
            priorities.add(priority3);
            priorities.add(priority4);
            priorities.add(priority5);

            dashboardForm.setTestCasesCount(testCaseCount);
            dashboardForm.setTestCasesPriorities(priorities);
        } catch (HttpHostConnectException connectException) {
            if (restApi != null) {
                restApi.close();
            }
            try {
                restApi = loginRally(configuration);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:msi.gaml.operators.Graphs.java

@operator(value = "strahler", content_type = ITypeProvider.CONTENT_TYPE_AT_INDEX + 1, category = {
        IOperatorCategory.GRAPH, IConcept.EDGE })
@doc(value = "retur for each edge, its strahler number")
public static GamaMap strahlerNumber(final IScope scope, final GamaGraph graph) {
    final GamaMap<Object, Integer> results = GamaMapFactory.create(Types.NO_TYPE, Types.INT);
    if (graph == null || graph.isEmpty(scope)) {
        return results;
    }// www.  j  a v  a  2 s.  c  om
    if (!graph.getConnected() || graph.hasCycle()) {
        throw GamaRuntimeException
                .error("Strahler number can only be computed for Tree (connected graph with no cycle)!", scope);
    }

    List currentEdges = (List) graph.getEdges().stream()
            .filter(a -> graph.outDegreeOf(graph.getEdgeTarget(a)) == 0).collect(Collectors.toList());
    while (!currentEdges.isEmpty()) {
        final List newList = new ArrayList<>();
        for (final Object e : currentEdges) {
            final List previousEdges = inEdgesOf(scope, graph, graph.getEdgeSource(e));
            final List nextEdges = outEdgesOf(scope, graph, graph.getEdgeTarget(e));
            if (nextEdges.isEmpty()) {
                results.put(e, 1);
                newList.addAll(previousEdges);
            } else {
                final boolean notCompleted = nextEdges.stream().anyMatch(a -> !results.containsKey(a));
                if (notCompleted) {
                    newList.add(e);
                } else {
                    final List<Integer> vals = (List<Integer>) nextEdges.stream().map(a -> results.get(a))
                            .collect(Collectors.toList());
                    final Integer maxVal = Collections.max(vals);
                    final int nbIt = Collections.frequency(vals, maxVal);
                    if (nbIt > 1) {
                        results.put(e, maxVal + 1);
                    } else {
                        results.put(e, maxVal);
                    }
                    newList.addAll(previousEdges);
                }
            }
        }
        currentEdges = newList;
    }
    return results;
}