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:de.codesourcery.eve.skills.ui.model.DefaultTreeNode.java
@Override public TreePath getPathToRoot() { final List<ITreeNode> stack = new ArrayList<ITreeNode>(); ITreeNode current = this; do {/*ww w.jav a2 s . c om*/ stack.add(current); current = (ITreeNode) current.getParent(); } while (current != null); Collections.reverse(stack); return new TreePath(stack.toArray(new ITreeNode[stack.size()])); }
From source file:br.com.everson.clei.springmvc.controller.ContasController.java
@RequestMapping("/PainelDoClienteComOperacoes") public String painelComOperacoesDoCliente(HttpSession hs, Model m) { Cliente cliente = (Cliente) hs.getAttribute("clienteAtual"); List<Operacao> operacoesEncontradas = new ArrayList<>(); operacoes.stream().filter((op) -> (op.getConta().getCliente().getId().equals(cliente.getId()))) .forEach((op) -> {/*from w ww. j a va 2 s . c om*/ operacoesEncontradas.add(op); }); Collections.reverse(operacoesEncontradas); m.addAttribute("cliente", cliente); m.addAttribute("operacoesEncontradas", operacoesEncontradas); return "clientes/PainelDoCliente"; }
From source file:org.openmrs.module.rheapocadapter.web.controller.TransactionServiceController.java
@RequestMapping("/module/rheapocadapter/processingQueue.form") public String showProcessingQueue(ModelMap map) { EnteredHandler enteredHandler = new EnteredHandler(); List<ProcessingTransaction> processingTransactions = new ArrayList<ProcessingTransaction>(); processingTransactions = (List<ProcessingTransaction>) enteredHandler.getProcessingQueue(); Collections.reverse(processingTransactions); map.addAttribute("processingTransactions", processingTransactions); return "/module/rheapocadapter/processingQueue"; }
From source file:Navigation.Vertex.java
public static List<Vertex> getShortestPathTo(Vertex target) { List<Vertex> path = new ArrayList<Vertex>(); for (Vertex vertex = target; vertex != null; vertex = vertex.previous) { path.add(vertex);/*from www . j a v a2 s . co m*/ } Collections.reverse(path); return path; }
From source file:com.haulmont.cuba.gui.CompanionDependencyInjector.java
public void inject() { Map<AnnotatedElement, Class> toInject = new HashMap<>(); @SuppressWarnings("unchecked") List<Class> classes = ClassUtils.getAllSuperclasses(companion.getClass()); classes.add(0, companion.getClass()); Collections.reverse(classes); for (Field field : getAllFields(classes)) { Class aClass = injectionAnnotation(field); if (aClass != null) { toInject.put(field, aClass); }//from ww w . j a va2 s.c o m } for (Method method : companion.getClass().getMethods()) { Class aClass = injectionAnnotation(method); if (aClass != null) { toInject.put(method, aClass); } } for (Map.Entry<AnnotatedElement, Class> entry : toInject.entrySet()) { doInjection(entry.getKey(), entry.getValue()); } }
From source file:net.sf.jabref.logic.journals.JournalAbbreviationLoader.java
public void update(JournalAbbreviationPreferences journalAbbreviationPreferences) { journalAbbrev = new JournalAbbreviationRepository(); // the order of reading the journal lists is important // method: last added abbreviation wins // for instance, in the personal list one can overwrite abbreviations in the built in list // Read builtin list journalAbbrev.addEntries(readJournalListFromResource(JOURNALS_FILE_BUILTIN)); // read IEEE list if (journalAbbreviationPreferences.isUseIEEEAbbreviations()) { journalAbbrev.addEntries(getOfficialIEEEAbbreviations()); } else {//from www.ja v a2 s . com journalAbbrev.addEntries(getStandardIEEEAbbreviations()); } // Read external lists List<String> lists = journalAbbreviationPreferences.getExternalJournalLists(); if (!(lists.isEmpty())) { Collections.reverse(lists); for (String filename : lists) { try { journalAbbrev.addEntries(readJournalListFromFile(new File(filename))); } catch (FileNotFoundException e) { // The file couldn't be found... should we tell anyone? LOGGER.info("Cannot find external journal list file " + filename, e); } } } // Read personal list String personalJournalList = journalAbbreviationPreferences.getPersonalJournalLists(); if ((personalJournalList != null) && !personalJournalList.trim().isEmpty()) { try { journalAbbrev.addEntries(readJournalListFromFile(new File(personalJournalList), journalAbbreviationPreferences.getDefaultEncoding())); } catch (FileNotFoundException e) { LOGGER.info("Personal journal list file '" + personalJournalList + "' not found.", e); } } }
From source file:cl.usach.trellosessionbeans.ActividadTrello.java
@Override public void buscarActividades(Equipo equipo) { Trello trello = new TrelloMake(); trello.setConfigTrello(equipo.getIdCuenta().getKeyCuenta(), equipo.getIdCuenta().getSecretCuenta(), equipo.getIdCuenta().getTokenCuenta()); try {// w w w .j ava 2 s. c o m List<ActionElement> actionElements = trello.getActions(equipo.getIdTablero().getIdTableroExt()); Collections.reverse(actionElements); if (actividadFacade.existeActividadPorTablero(equipo.getIdTablero())) { Actividad ultimaActividad = actividadFacade.buscarUltimaActividad(equipo.getIdTablero()); List<ActionElement> auxLista = new ArrayList<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Calendar cal = Calendar.getInstance(); for (ActionElement actionElement : actionElements) { Date date = null; if (actionElement.getDate() != null) { cal.setTime(formatter.parse(actionElement.getDate())); cal.add(Calendar.HOUR, -4); date = cal.getTime(); } if (ultimaActividad.getFechaActividad().after(date)) { auxLista.add(actionElement); } } actionElements.removeAll(auxLista); } for (ActionElement actionElement : actionElements) { TipoActividad tipoActividad; if (tipoActividadFacade.existeActividadPorNombre(actionElement.getType())) { tipoActividad = tipoActividadFacade.buscarPorNombre(actionElement.getType()); } else { TipoCuenta tipoCuenta = tipoCuentaFacade.buscarPorNombreTipoCuenta("Trello"); TipoActividad ta = new TipoActividad(actionElement.getType(), tipoCuenta); tipoActividadFacade.create(ta); tipoActividad = tipoActividadFacade.buscarPorNombre(actionElement.getType()); } if (!actividadFacade.existeActividadPorIdActividadExt(actionElement.getId())) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Calendar cal = Calendar.getInstance(); Date date = null; if (actionElement.getDate() != null) { cal.setTime(formatter.parse(actionElement.getDate())); cal.add(Calendar.HOUR, -4); date = cal.getTime(); } Actividad actividad = new Actividad(actionElement.getId(), date, tipoActividad); //Asignar miembro si es que existe if (miembroFacade.existeMiembroPorIdTableroYIdMiembroExt(equipo.getIdTablero(), actionElement.getIdMemberCreator())) { Miembro miembro = miembroFacade.buscarMiembroPorIdTableroYIdMiembroExt( equipo.getIdTablero(), actionElement.getIdMemberCreator()); actividad.setIdMiembro(miembro); } //Asignar tarjeta si es que tiene if (actionElement.getCardId() != null) { if (tarjetaFacade.existeTarjetaPorIdTarjetaExt(actionElement.getCardId())) { Tarjeta tarjeta = tarjetaFacade.buscarPorIdTarjetaExt(actionElement.getCardId()); actividad.setIdTarjeta(tarjeta); if (tipoActividad.getNombreTipoActividad().equals("updateCard")) { List<Lista> listaPU = listaFacade .buscarPrimeraYUltimaPorTablero(equipo.getIdTablero()); if (!listaPU.isEmpty()) { //Da fecha de inicio de la tarjeta if (actionElement.getIdListBefore() != null && listaPU.get(0) != null && listaPU .get(0).getIdListaExt().equals(actionElement.getIdListBefore())) { EstadoTarjeta estado = estadoTarjetaFacade .buscarPorNombreEstadoTarjeta("En proceso"); tarjeta.setIdEstadoTarjeta(estado); tarjeta.setFechaInicioTarjeta(date); if (tarjeta.getFechaCreacionTarjeta() == null) tarjeta.setFechaCreacionTarjeta(date); tarjetaFacade.edit(tarjeta); } else { //Da fecha fin de la tarjeta if (actionElement.getIdListAfter() != null && listaPU.get(1) != null && listaPU.get(1).getIdListaExt() .equals(actionElement.getIdListAfter())) { EstadoTarjeta estado = estadoTarjetaFacade .buscarPorNombreEstadoTarjeta("Terminada"); tarjeta.setIdEstadoTarjeta(estado); tarjeta.setFechaFinalTarjeta(date); if (tarjeta.getFechaCreacionTarjeta() == null) tarjeta.setFechaCreacionTarjeta(date); tarjetaFacade.edit(tarjeta); } else { //Eliminar fecha fin de la tarjeta if (actionElement.getIdListBefore() != null && listaPU.get(1) != null && listaPU.get(1).getIdListaExt() .equals(actionElement.getIdListBefore())) { EstadoTarjeta estado = estadoTarjetaFacade .buscarPorNombreEstadoTarjeta("En proceso"); tarjeta.setIdEstadoTarjeta(estado); tarjeta.setFechaFinalTarjeta(null); if (tarjeta.getFechaCreacionTarjeta() == null) tarjeta.setFechaCreacionTarjeta(date); tarjetaFacade.edit(tarjeta); } } } } } else { //Instrucciones si la tarjeta no se crea en la primera lista del tablero if (tipoActividad.getNombreTipoActividad().equals("createCard")) { //Agregar Fecha de creacion tarjeta.setFechaCreacionTarjeta(date); List<Lista> listaPU = listaFacade .buscarPrimeraYUltimaPorTablero(equipo.getIdTablero()); if (!listaPU.isEmpty()) { //Si la tarjeta se crea en la ultima lista if (listaPU.get(1) != null && listaPU.get(1).getIdLista() .equals(tarjeta.getIdLista().getIdLista())) { EstadoTarjeta estado = estadoTarjetaFacade .buscarPorNombreEstadoTarjeta("Terminada"); tarjeta.setIdEstadoTarjeta(estado); tarjeta.setFechaInicioTarjeta(date); tarjeta.setFechaFinalTarjeta(date); tarjetaFacade.edit(tarjeta); } else { //Si la tarjeta se crea en cualquier otra lista que no sea la primera ni la ultima if (listaPU.get(0) != null && !listaPU.get(0).getIdLista() .equals(tarjeta.getIdLista().getIdLista())) { EstadoTarjeta estado = estadoTarjetaFacade .buscarPorNombreEstadoTarjeta("En proceso"); tarjeta.setIdEstadoTarjeta(estado); tarjeta.setFechaInicioTarjeta(date); tarjetaFacade.edit(tarjeta); } } } } } } } actividadFacade.create(actividad); } } } catch (IOException | JSONException | ParseException ex) { Logger.getLogger(ActividadTrello.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.ibm.bluej.commonutil.PrecisionRecallThreshold.java
public SummaryScores computeSummaryScores(double limitProb) { if (limitProb < 0.5) { throw new IllegalArgumentException("Probabilities cannot be limited to below 50%"); }/*from www . ja va 2s .co m*/ SummaryScores sum = new SummaryScores(); Collections.shuffle(scoredPlusGold, RANDOMNESS); Collections.sort(scoredPlusGold, new FirstPairComparator(null)); Collections.reverse(scoredPlusGold); double tpRelative = 0; double fpRelative = 0; double cummulativeCorrect = 0; double auc = 0; double allPositive = 0; double averageScore = 0; for (Pair<Double, Boolean> p : scoredPlusGold) { if (p.second) allPositive += 1; averageScore += p.first; } averageScore /= scoredPlusGold.size(); sum.relativeThreshold = averageScore; double maxF = 0; double maxFThresh = 0; double logLike = 0; double maxAcc = 0; double maxAccThresh = 0; sum.relativePrecision = Double.NaN; for (int i = 0; i < scoredPlusGold.size(); ++i) { Pair<Double, Boolean> p = scoredPlusGold.get(i); if (p.second) { ++cummulativeCorrect; auc += cummulativeCorrect / ((i + 1) * allPositive); } double tp = cummulativeCorrect; double fp = (i + 1) - cummulativeCorrect; double fn = allPositive - cummulativeCorrect; double tn = (scoredPlusGold.size() - (i + 1)) - fn; double precision = (double) (tp) / (tp + fp); double recall = (double) (tp) / (tp + fn); double accuracy = (tp + tn) / scoredPlusGold.size(); double f1 = 2 * precision * recall / (precision + recall); if (p.second) { if (p.first > sum.relativeThreshold) tpRelative++; } else { if (p.first > sum.relativeThreshold) fpRelative++; } if (f1 > maxF) { maxF = f1; maxFThresh = p.first; } if (accuracy > maxAcc) { maxAcc = accuracy; maxAccThresh = p.first; } double prob = p.second ? p.first : 1 - p.first; if (prob < 0 || prob > 1) { logLike = Double.NaN; } if (prob > limitProb) { prob = limitProb; } if (prob < 1 - limitProb) { prob = 1 - limitProb; } logLike += Math.log(prob); } sum.maxFScore = maxF; sum.maxFScoreThreshold = maxFThresh; sum.auc = auc; sum.pearsonsR = pearsonsR(); sum.logLikelihood = logLike; sum.maxAccuracy = maxAcc; sum.maxAccuracyThreshold = maxAccThresh; sum.relativePrecision = tpRelative / (tpRelative + (fpRelative * (allPositive / (scoredPlusGold.size() - allPositive)))); if (Double.isNaN(sum.relativePrecision)) sum.relativePrecision = 0; sum.relativeRecall = tpRelative / allPositive; sum.relativeFScore = 2 * sum.relativePrecision * sum.relativeRecall / (sum.relativePrecision + sum.relativeRecall); if (Double.isNaN(sum.relativeFScore)) sum.relativeFScore = 0; return sum; }
From source file:com.lithium.flow.shell.tunnel.ShellTunneler.java
@Nonnull public Tunnel getTunnel(@Nonnull String host, int port, @Nullable String through) throws IOException { List<Login> logins = Lists.newArrayList(); Login endLogin = access.getLogin(host); logins.add(endLogin);//from w w w . j a v a2 s . c o m if (through != null) { logins.add(access.getLogin(through)); } Optional<String> match = config.getMatch("shell.tunnels", endLogin.getHost()); if (match.isPresent()) { for (String tunnel : Splitter.on(';').split(match.get())) { logins.add(access.getLogin(tunnel)); } } Collections.reverse(logins); Tunnel tunnel = null; for (int i = 0; i < logins.size() - 1; i++) { Login thisLogin = logins.get(i); Login nextLogin = logins.get(i + 1); if (i == logins.size() - 2) { nextLogin = nextLogin.toBuilder().setPort(port).build(); } log.debug("tunneling through {} to {}", thisLogin, nextLogin.getHostAndPort()); Login login = thisLogin; if (tunnel != null) { login = login.toBuilder().setHost("localhost").setPort(tunnel.getPort()).build(); } String message = login.getKeyPath() != null ? login.getKeyPath() : thisLogin.getDisplayString(); Function<Boolean, String> pass = retry -> access.getPrompt().prompt(message, message, true, retry); login = login.toBuilder().setPass(pass).build(); tunnel = shore.getShell(login).tunnel(0, nextLogin.getHost(), nextLogin.getPortOrDefault(22)); } if (tunnel != null) { tunnels.add(tunnel); return tunnel; } else { return new NoTunnel(host, port); } }
From source file:com.boozallen.cognition.ingest.storm.bolt.enrich.GeoJsonPointReverseArrayBolt.java
String reverseJsonArray(String src) { Gson gson = new Gson(); List list = gson.fromJson(src, List.class); if (CollectionUtils.isEmpty(list)) { return StringUtils.EMPTY; } else {// ww w . ja v a2s. co m Collections.reverse(list); return gson.toJson(list); } }