List of usage examples for java.util Collections reverse
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void reverse(List<?> list)
This method runs in linear time.
From source file:com.bitsofproof.supernode.model.JpaStore.java
@Override protected void backwardCache(Blk b, TxOutCache cache, boolean modify) { List<Tx> txs = new ArrayList<Tx>(); txs.addAll(b.getTransactions());/*from w w w .j a va2s . co m*/ Collections.reverse(txs); for (Tx t : txs) { for (TxOut out : t.getOutputs()) { if (modify) { out.setAvailable(false); } cache.remove(t.getHash(), out.getIx()); } for (TxIn in : t.getInputs()) { if (!in.getSourceHash().equals(Hash.ZERO_HASH_STRING)) { TxOut source = in.getSource(); if (modify) { source.setAvailable(true); } cache.add(source.flatCopy(null)); } } } }
From source file:com.norconex.commons.lang.io.IOUtil.java
/** * Gets the last lines from an input stream, using the specified encoding. * This method is null-safe.//ww w .ja v a 2 s. c o m * If the input stream is null or empty, an empty string array will * be returned. * <br><br> * Use of this method can often be a bad idea (especially on large streams) * since it needs to read the entire stream to return the last lines. * If you are dealing with files, use * {@link com.norconex.commons.lang.file.FileUtil#tail( * File, String, int)} instead, which can read * a file starting from the end. * @param is input stream * @param encoding character encoding * @param lineQty maximum number of lines to return * @return lines as a string array * @throws IOException problem reading lines * @since 1.5.0 */ public static String[] tail(final InputStream is, String encoding, final int lineQty) throws IOException { if (is == null) { return EMPTY_STRINGS; } String safeEncoding = encoding; if (StringUtils.isBlank(safeEncoding)) { safeEncoding = CharEncoding.UTF_8; } BufferedReader br = new BufferedReader(new InputStreamReader(is, safeEncoding)); List<String> lines = new ArrayList<String>(lineQty); String line; while ((line = br.readLine()) != null) { lines.add(0, line); if (lines.size() > lineQty) { lines.remove(lineQty); } } br.close(); Collections.reverse(lines); return lines.toArray(EMPTY_STRINGS); }
From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoresFragment.java
private void initializeListView(int selectedExerciseId, Level level) { mHighscoreListView = (ListView) mRootView.findViewById(R.id.list_view_highscores); if (firstTime()) { addBasicHighscores();//from ww w.ja va2 s . co m } ArrayList<Highscore> highscores = loadHighscores(level); highscores = selectHighscores(highscores, selectedExerciseId); Collections.sort(highscores); Collections.reverse(highscores); HighscoreAdapter adapter = new HighscoreAdapter(getActivity(), highscores); mHighscoreListView.setAdapter(adapter); }
From source file:de.unisb.cs.st.javalanche.rhino.coverage.CoberturaParser.java
private static double[] generateAverageData(FailureMatrix fm, List<List<PriorizationResult>> averageList) { double[] values = new double[averageList.get(0).size()]; for (List<PriorizationResult> singleResult : averageList) { Collections.reverse(singleResult); List<String> testList = new ArrayList<String>(); for (int i = 0; i < singleResult.size(); i++) { PriorizationResult prioritizationResult = singleResult.get(i); testList.add(prioritizationResult.getTestName()); int detectedFailures = fm.getDetectedFailures(testList); // System.out.println("Detected Failures: " + detectedFailures); values[i] += 1. * detectedFailures; }// ww w.java 2 s .co m } double size = 1. * averageList.size(); for (int i = 0; i < values.length; i++) { values[i] = values[i] / size; } return values; }
From source file:controller.HostelController.java
@ResponseBody @RequestMapping(value = "/getPlans.do") public Map getPlans(@RequestBody Map hostel, HttpServletRequest request, HttpServletResponse response) throws Exception { String hostelIdStr = (String) hostel.get("hostelId"); int hostelId = Integer.parseInt(hostelIdStr); Map<String, Object> result = new HashMap<String, Object>(); List<Plan> plans = hostelService.getPlans(hostelId); Collections.reverse(plans); result.put("plans", plans); return result; }
From source file:org.oscarehr.web.OcanReportingAction.java
public ActionForward getAssessments(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { String strClientId = request.getParameter("clientId"); SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); Integer facilityId = LoggedInInfo.loggedInInfo.get().currentFacility.getId(); List<OcanStaffForm> staffForms = ocanStaffFormDao.findLatestSignedOcanForms(facilityId, Integer.parseInt(strClientId)); Collections.reverse(staffForms); List<LabelValueBean> results = new ArrayList<LabelValueBean>(); if (staffForms.size() == 0) { MiscUtils.getLogger().info("No OCAN Assessments found for this client: " + strClientId); JSONArray jsonArray = JSONArray.fromObject(results); response.getWriter().print(jsonArray); return null; }//www . j a va2 s . c o m //we know there's atleast 1. OcanStaffForm firstOcan = staffForms.get(0); String label = convertOcanReasonUserString(firstOcan.getReasonForAssessment()); results.add(new LabelValueBean(label + " - " + dateFormatter.format(firstOcan.getCreated()), String.valueOf(firstOcan.getId()))); if (staffForms.size() > 1) { OcanStaffForm latestOcan = staffForms.get(staffForms.size() - 1); results.add(new LabelValueBean("Current OCAN - " + dateFormatter.format(latestOcan.getCreated()), String.valueOf(latestOcan.getId()))); } if (staffForms.size() > 2) { OcanStaffForm previousOcan = staffForms.get(staffForms.size() - 2); results.add(1, new LabelValueBean("Previous OCAN - " + dateFormatter.format(previousOcan.getCreated()), String.valueOf(previousOcan.getId()))); } int counter = 1; if (staffForms.size() > 3) { for (int x = 1; x <= staffForms.size() - 3; x++) { OcanStaffForm staffForm = staffForms.get(x); label = convertOcanReasonUserString(staffForm.getReasonForAssessment()) + " " + counter + " - " + dateFormatter.format(staffForm.getCreated()); results.add(counter, new LabelValueBean(label, String.valueOf(staffForm.getId()))); counter++; } } JSONArray jsonArray = JSONArray.fromObject(results); response.getWriter().print(jsonArray); return null; }
From source file:com.atlassian.launchpad.jira.gerrittabpanel.GerritTabPanel.java
@Override public List<IssueAction> getActions(Issue issue, User remoteUser) { List<IssueAction> messages = new ArrayList<IssueAction>(); System.err.println(USER);/*from w ww . j av a 2s.c o m*/ //read and validate the Gerrit commit hash CustomField gerritLinkFieldContent = ComponentAccessor.getCustomFieldManager() .getCustomFieldObjectByName(GERRIT_ID_FIELD_NAME); if (gerritLinkFieldContent == null) { messages.add(new GenericMessageAction("\"" + GERRIT_ID_FIELD_NAME + "\" custom field not available. Cannot process Gerrit Review comments")); return messages; } Object gitHashFieldObj = issue.getCustomFieldValue(gerritLinkFieldContent); if (gitHashFieldObj == null) { messages.add(new GenericMessageAction("\"" + GERRIT_ID_FIELD_NAME + "\" not provided. Please provide Gerrit ID to see review comments for this issue.")); return messages; } String gitHash = gitHashFieldObj.toString().trim(); if (gitHash.length() == 0) { messages.add(new GenericMessageAction( "To view related Gerrit review comments for this issue please provide the Git Commit Hash")); return messages; } else if (!isValidGitHash(gitHash)) { messages.add(new GenericMessageAction("Gerrit Commit ID not properly formatted")); return messages; } //frame command to access SSH API String sshCom = "ssh -i /home/jira/.ssh/id_rsa -p " + PORT + " " + USER + "@" + HOST + " gerrit query --format=json --current-patch-set --comments change:" + gitHash; try { Process p = Runtime.getRuntime().exec(sshCom); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = reader.readLine(); if (line != null) { JSONTokener tokener = new JSONTokener(line); JSONObject finalResult = new JSONObject(tokener); if (!finalResult.has(KEY_COMMENTS)) { messages.add(new GenericMessageAction("No comments available for this Gerrit review.")); return messages; } JSONArray commentsJson = finalResult.getJSONArray(KEY_COMMENTS); for (int k = 0; k < commentsJson.length(); k++) { JSONObject commentJson = commentsJson.getJSONObject(k); GerritCommentAction commentAction = createCommentActionFromJSON(commentJson); messages.add(commentAction); } String status = finalResult.getString("status"); messages.add(new GenericMessageAction("<h2>Gerrit Status: " + status + "</h2>")); //reverse message order to display most recent first Collections.reverse(messages); } } catch (JSONException e) { // JSON returned from SSH API did not contain proper keys e.printStackTrace(); } catch (InterruptedException e) { // Exception in attempting to execute the ssh command e.printStackTrace(); } catch (IOException e) { // Exception in reading from the input stream e.printStackTrace(); } return messages; }
From source file:com.powers.wsexplorer.gui.GUIUtil.java
public static Listener createTextSortListener(final Table table, final Map<String, String> map) { Listener sortListener = new Listener() { public void handleEvent(Event e) { final int direction = table.getSortDirection(); Collator collator = Collator.getInstance(Locale.getDefault()); TableColumn column = (TableColumn) e.widget; Set<String> keys = map.keySet(); List<String> l = new LinkedList<String>(); l.addAll(keys);//from w ww. j a va 2 s . co m Collections.sort(l, collator); if (direction == SWT.DOWN) { Collections.reverse(l); table.setSortDirection(SWT.UP); } else { table.setSortDirection(SWT.DOWN); } table.removeAll(); Iterator<String> itr = l.iterator(); String key = null; String value = null; while (itr.hasNext()) { key = itr.next(); if (StringUtils.isNotBlank(key)) { TableItem ti = new TableItem(table, SWT.BORDER); ti.setText(0, key); value = map.get(key); if (StringUtils.isNotBlank(value)) { ti.setText(1, value); } } } table.setSortColumn(column); } }; return sortListener; }
From source file:org.dspace.orm.entity.Community.java
@Transient public List<Community> getHierarchyList() { List<Community> parents = new ArrayList<Community>(); Community tmp = this; while (tmp != null) { if (tmp.hasParents()) { tmp = tmp.getParent();/*from www . j av a 2 s .c o m*/ if (tmp != null) parents.add(tmp); } else tmp = null; } Collections.reverse(parents); return parents; }
From source file:graph.inference.module.DisjointWithWorker.java
private Collection<? extends Node[]> alterGenlJustification(QueryObject genlResults, DAGNode disjointNode, boolean isReversed) { TransitiveIntervalSchemaModule transModule = (TransitiveIntervalSchemaModule) dag_ .getModule(TransitiveIntervalSchemaModule.class); if (transModule != null && transModule.isReady()) { DAGNode baseNode = (DAGNode) genlResults.getNode(1); List<Node[]> justification = transModule.justifyTransitive(baseNode, disjointNode); if (isReversed) Collections.reverse(justification); return justification; }// w w w. ja v a 2s . c om List<Node[]> justifications = genlResults.getJustification(); int i = 0; for (i = 0; i < justifications.size(); i++) { Node[] nodes = justifications.get(i); if (nodes[1].equals(disjointNode)) break; if (nodes[2].equals(disjointNode)) { i++; break; } } justifications = justifications.subList(0, i); genlResults.cleanTransitiveJustification(justifications); if (isReversed) { List<Node[]> reversed = new ArrayList<>(genlResults.getJustification()); Collections.reverse(reversed); return reversed; } return genlResults.getJustification(); }