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.axelor.studio.service.data.exporter.ExportService.java
private void updateMenuPath(MetaMenu metaMenu) { List<String> menus = new ArrayList<String>(); menus.add(metaMenu.getTitle());// w ww. ja va 2 s . com addParentMenus(menus, metaMenu); Collections.reverse(menus); menuPath = Joiner.on("/").join(menus); }
From source file:NimbleTree.java
/** * Get all the chains of ancestors of length n in this tree. Used * as sources for NGram model.// ww w . j av a 2 s .c o m */ public ArrayList<ArrayList<TreeNode<E>>> getAncestorChains(int n) { ArrayList<ArrayList<TreeNode<E>>> retval = new ArrayList<ArrayList<TreeNode<E>>>(); for (TreeNode<E> node : depthFirstTraversal(getRoot())) { ArrayList<TreeNode<E>> chain = getAncestorChain(node, n); if (chain.size() == n) { Collections.reverse(chain); retval.add(chain); } } return retval; }
From source file:com.silverpeas.look.SilverpeasLook.java
public String getSpaceLook(String spaceId) { List<SpaceInst> path = organizationController.getSpacePath(spaceId); Collections.reverse(path); String spaceLook = null;//from ww w . j av a 2 s . co m for (SpaceInst space : path) { spaceLook = space.getLook(); if (StringUtil.isDefined(space.getLook())) { break; } } return spaceLook; }
From source file:fr.univrouen.poste.services.GalaxieExcelParser.java
public Map<String, String> getCells4GalaxieEntry(GalaxieExcel galaxieExcel, GalaxieEntry galaxieEntry) throws SQLException { Map<String, String> cellsMap = null; List<List<String>> cells = excelParser .getCells(galaxieExcel.getBigFile().getBinaryFile().getBinaryStream()); List<String> cellsHead = cells.remove(0); // dans le doute EsupDematEC considre la dernire ligne comme la plus jour Collections.reverse(cells); for (List<String> row : cells) { // create a new galaxyEntry GalaxieEntry ge = new GalaxieEntry(); int position = 0; for (String cellName : cellsHead) { if (position < row.size()) { String cellValue = row.get(position); galaxieMappingService.setAttrFromCell(ge, cellName, cellValue); }/* w ww.ja v a 2 s . co m*/ position++; } if (getList4Id(galaxieEntry).equals(getList4Id(ge))) { cellsMap = new HashMap<String, String>(); position = 0; for (String cellName : cellsHead) { if (position < row.size()) { String cellValue = row.get(position); cellsMap.put(cellName, cellValue); } position++; } break; } } return cellsMap; }
From source file:com.github.braully.graph.BatchExecuteOperation.java
void processDirectory(List<IGraphOperation> operationsToExecute, String directory, boolean contProcess) { if (verbose) { System.out.println("Processing directory: " + directory); }/* w w w .ja v a 2 s . c o m*/ try { File dir = new File(directory); String dirname = dir.getName(); File[] files = dir.listFiles(); // Arrays.sort(files); List<File> filesList = sortFileArrayBySize(files); Collections.reverse(filesList); // for (File file : filesList) { long continueOffset = -1; for (IGraphOperation operation : operationsToExecute) { String resultFileNameGroup = getResultFileName(operation, dirname, null); // long continueOffset = -1; if (contProcess) { File file = getExistResultFile(dir, resultFileNameGroup); if (file != null && file.exists()) { BufferedReader reader = new BufferedReader(new FileReader(file)); while (reader.readLine() != null) { continueOffset++; } reader.close(); } } for (File file : filesList) { String name = null; long graphCount = 0; try { name = file.getName(); if (name.toLowerCase().endsWith(".mat")) { if (graphCount > continueOffset) { processFileMat(operation, file, dirname); } graphCount++; } else if (name.toLowerCase().endsWith(".g6")) { processFileG6(operation, file, dirname, contProcess); } else if (name.toLowerCase().endsWith(".g6.gz")) { processFileG6GZ(operation, file, dirname, contProcess); } } catch (Exception e) { System.err.println("Fail in process: " + name); e.printStackTrace(); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.mines.letschat.GcmIntentService.java
private void sendNotification(String msg, String senderID) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(this, MainActivity.class); intent.putExtra(MainActivity.EXTRA_NOTIFICATION_RETRIEVE, senderID); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notificationCounter++;/*from ww w.ja v a 2s. co m*/ if (messages.size() > 1) { msg = msg + "..."; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setVibrate(new long[] { 0, 500, 250, 500, 250 }).setLights(Color.BLUE, 200, 200) .setSmallIcon(R.drawable.logo).setContentTitle("Let's Chat Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setNumber(notificationCounter) .setTicker(msg).setContentText(msg); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // Sets a title for the Inbox style big view inboxStyle.setBigContentTitle("Unread messages (" + notificationCounter + "):"); // Moves events into the big view ArrayList<String> temp = new ArrayList<String>(); for (int i = 0; i < 5; ++i) { if (i == messages.size()) { break; } temp.add(messages.get(i)); } Collections.reverse(temp); messages = temp; for (String s : messages) { inboxStyle.addLine(s); } mBuilder.setStyle(inboxStyle); mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); // AwesomeAdapter.animate = true; }
From source file:org.codehaus.griffon.commons.ClassPropertyFetcher.java
private List<Class<?>> resolveAllClasses(Class<?> c) { List<Class<?>> list = new ArrayList<Class<?>>(); Class<?> currentClass = c; while (currentClass != null) { list.add(currentClass);/*from w w w .j av a 2s .c om*/ currentClass = currentClass.getSuperclass(); } Collections.reverse(list); return list; }
From source file:gov.medicaid.screening.dao.impl.MarriageAndFamilyTherapyLicenseDAOBean.java
/** * Performs search by Name or License number. * * @param criteria The search criteria./*from w w w .j a v a 2s. c om*/ * @param identifier The search identifier. * @param host The host * @param pageSize The page size requested * @param pageNumber The page number requested * @param sortColumn the sort column * @param sortOrder the sort order * @return search results - licenses. * @throws PersistenceException When an error occurs while trying to persist statistics. * @throws ServiceException When an error occurs while trying to perform search. */ @SuppressWarnings("unchecked") private SearchResult<License> performSearch(String criteria, String identifier, String host, int pageSize, int pageNumber, String sortColumn, SortOrder sortOrder) throws PersistenceException, ServiceException { String signature = "BaseLicenseDataAccessImpl#performSearch"; try { if (pageNumber > 0 && pageSize < 1) { throw new ServiceException(ErrorCode.MITA10002.getDesc()); } SearchResult<License> allResults = getAllResults(criteria, identifier, host, 1); if (sortColumn != null) { Collections.sort(allResults.getItems(), new BeanComparator(sortColumn)); if (sortOrder == SortOrder.DESC) { Collections.reverse(allResults.getItems()); } } // trim result List<License> trimmedResults = new ArrayList<License>(); List<License> allResultsList = allResults.getItems(); if (pageNumber > 0) { if (allResultsList != null && !allResultsList.isEmpty()) { int fromIndex = Math.min(pageSize * (pageNumber - 1), allResultsList.size() - 1); int toIndex = Math.min(fromIndex + pageSize, allResultsList.size()); trimmedResults.addAll(allResultsList.subList(fromIndex, toIndex)); } } else { trimmedResults.addAll(allResultsList); } SearchResult<License> result = new SearchResult<License>(); result.setPageNumber(pageNumber); result.setPageSize(pageSize); result.setItems(trimmedResults); result.setTotal(allResultsList.size()); int totalPages; if (pageSize > 0) { totalPages = (int) Math.ceil((double) allResultsList.size() / pageSize); } else { totalPages = allResultsList.isEmpty() ? 0 : 1; } result.setTotalPages(totalPages); return result; } catch (PersistenceException e) { LogUtil.traceError(getLog(), signature, e); throw new ServiceException(ErrorCode.MITA50000.getDesc(), e); } catch (IOException e) { LogUtil.traceError(getLog(), signature, e); throw new ServiceException(ErrorCode.MITA50002.getDesc(), e); } catch (URISyntaxException e) { LogUtil.traceError(getLog(), signature, e); throw new ServiceException(ErrorCode.MITA50002.getDesc(), e); } catch (ParseException e) { LogUtil.traceError(getLog(), signature, e); throw new ServiceException(ErrorCode.MITA50002.getDesc(), e); } }
From source file:com.flexive.tests.embedded.WorkflowTest.java
/** * Tests if workflows are updated properly. * * @throws Exception if an error occured *//*www .jav a 2 s . c om*/ @Test public void updateWorkflow() throws Exception { long workflowId = createTestWorkflow(); try { WorkflowEdit editWorkflow = new WorkflowEdit(getEnvironment().getWorkflow(workflowId)); editWorkflow.setName(StringUtils.reverse(WORKFLOW_NAME)); editWorkflow.setDescription(StringUtils.reverse(WORKFLOW_DESCRIPTION)); editWorkflow.getSteps().add(new StepEdit( new Step(-1, StepDefinition.EDIT_STEP_ID, editWorkflow.getId(), myWorkflowACL.getId()))); editWorkflow.getSteps().add(new StepEdit( new Step(-2, StepDefinition.LIVE_STEP_ID, editWorkflow.getId(), myWorkflowACL.getId()))); editWorkflow.getRoutes().add(new Route(-1, UserGroup.GROUP_EVERYONE, -1, -2)); workflowEngine.update(editWorkflow); // revert step order editWorkflow = getEnvironment().getWorkflow(editWorkflow.getId()).asEditable(); final List<StepEdit> steps = Lists.newArrayList(); for (Step step : editWorkflow.getSteps()) { steps.add(step.asEditable()); } Assert.assertEquals(steps.size(), 2); Collections.reverse(steps); assertStepOrder(steps, editWorkflow.getSteps(), false); // update workflow editWorkflow.setSteps(steps); workflowEngine.update(editWorkflow); editWorkflow = getEnvironment().getWorkflow(editWorkflow.getId()).asEditable(); // order should have been preserved assertStepOrder(editWorkflow.getSteps(), steps, true); // remove and add edit step for (Step step : editWorkflow.getSteps()) { if (step.getStepDefinitionId() == StepDefinition.EDIT_STEP_ID) { editWorkflow.getSteps().remove(step); break; } } // route from/to new step (created after this statement) to remaining live step editWorkflow.getRoutes() .add(new Route(-1, UserGroup.GROUP_OWNER, -1, editWorkflow.getSteps().get(0).getId())); editWorkflow.getRoutes() .add(new Route(-2, UserGroup.GROUP_OWNER, editWorkflow.getSteps().get(0).getId(), -1)); // create step for route editWorkflow.getSteps().add(new StepEdit( new Step(-1, StepDefinition.EDIT_STEP_ID, editWorkflow.getId(), myWorkflowACL.getId()))); workflowEngine.update(editWorkflow); Workflow workflow = getEnvironment().getWorkflow(workflowId); Assert.assertTrue(getUserTicket().isInRole(Role.WorkflowManagement), "User is not in role workflow management - call should have failed."); Assert.assertTrue(StringUtils.reverse(WORKFLOW_NAME).equals(workflow.getName()), "Workflow name not updated properly."); Assert.assertTrue(StringUtils.reverse(WORKFLOW_DESCRIPTION).equals(workflow.getDescription()), "Workflow description not updated properly."); Assert.assertTrue(workflow.getSteps().size() == 2, "Unexpected number of workflow steps: " + workflow.getSteps().size()); Assert.assertTrue(workflow.getRoutes().size() == 3, "Unexpected number of workflow routes: " + workflow.getRoutes()); } finally { // cleanup workflowEngine.remove(workflowId); } }
From source file:edu.jhuapl.dorset.agents.StockAgent.java
protected JsonObject processData(String json, String keyWordCompanyName) { Gson gson = new Gson(); JsonObject returnObj = new JsonObject(); JsonObject jsonObj = gson.fromJson(json, JsonObject.class); if (jsonObj != null) { if ((jsonObj.get("dataset")) != null) { JsonArray jsonDataArray = (JsonArray) (((JsonObject) jsonObj.get("dataset")).get("data")); ArrayList<JsonElement> responseDataArrayList = new ArrayList<>(); ArrayList<JsonElement> responseLabelsArrayList = new ArrayList<>(); for (int i = 0; i < jsonDataArray.size(); i++) { JsonArray jsonDataArrayNested = (JsonArray) (jsonDataArray.get(i)); responseDataArrayList.add(jsonDataArrayNested.get(4)); responseLabelsArrayList.add(jsonDataArrayNested.get(0)); }/*from ww w.ja v a 2s.com*/ Collections.reverse(responseDataArrayList); Collections.reverse(responseLabelsArrayList); List<JsonElement> returnDataJsonList = responseDataArrayList .subList(responseDataArrayList.size() - DAYS_IN_A_MONTH, responseDataArrayList.size()); JsonArray returnDataJsonListStr = new JsonArray(); for (int i = 0; i < returnDataJsonList.size(); i++) { returnDataJsonListStr.add(returnDataJsonList.get(i)); } JsonObject jsonData = new JsonObject(); jsonData.add(keyWordCompanyName, returnDataJsonListStr); returnObj.addProperty("data", jsonData.toString()); List<JsonElement> returnLabelsJsonList = responseLabelsArrayList .subList(responseLabelsArrayList.size() - DAYS_IN_A_MONTH, responseLabelsArrayList.size()); returnObj.addProperty("labels", returnLabelsJsonList.toString()); returnObj.addProperty("title", keyWordCompanyName + " Stock Ticker"); returnObj.addProperty("xaxis", "Day"); returnObj.addProperty("yaxis", "Close of day market price ($)"); returnObj.addProperty("plotType", "lineplot"); } } return returnObj; }