Example usage for java.util Collections reverse

List of usage examples for java.util Collections reverse

Introduction

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

Prototype

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void reverse(List<?> list) 

Source Link

Document

Reverses the order of the elements in the specified list.

This method runs in linear time.

Usage

From source file:cz.incad.Kramerius.views.inc.details.tabs.LoadCustomViewObject.java

public String getContent() throws IOException, ParserConfigurationException, SAXException {
    StringBuilder stringBuilder = new StringBuilder();

    String tab = this.requestProvider.get().getParameter("tab");
    String ds = tab;//from w w  w .java 2  s  . c  o  m
    String xsl = tab;
    if (tab.indexOf('.') >= 0) {
        ds = tab.split("\\.")[0];
        xsl = tab.split("\\.")[1] + ".xsl";
    }

    String pid_path = this.requestProvider.get().getParameter("pid_path");
    List<String> pids = Arrays.asList(pid_path.split("/"));
    if (ds.startsWith("-")) {
        Collections.reverse(pids);
        ds = ds.substring(1);
    }
    for (String pid : pids) {
        if (fedoraAccess.isStreamAvailable(pid, ds)) {

            String mime = fedoraAccess.getMimeTypeForStream(pid, ds);
            if (mime.equals("text/plain")) {
                try {
                    InputStream is = fedoraAccess.getDataStream(pid, ds);
                    byte[] bytes = org.apache.commons.io.IOUtils.toByteArray(is);
                    String enc = UnicodeUtil.getEncoding(bytes);
                    ByteArrayInputStream is2 = new ByteArrayInputStream(bytes);
                    stringBuilder.append("<textarea style=\"width:98%; height:98%; border:0; \">"
                            + IOUtils.readAsString(is2, Charset.forName(enc), true) + "</textarea>");
                } catch (cz.incad.kramerius.security.SecurityException e) {
                    LOGGER.log(Level.INFO, e.getMessage());
                }
            } else if (mime.equals("text/xml") || mime.equals("application/rdf+xml")) {
                try {
                    if (xslService.isAvailable(xsl)) {
                        org.w3c.dom.Document xml = XMLUtils.parseDocument(fedoraAccess.getDataStream(pid, ds),
                                true);
                        String text = xslService.transform(xml, xsl, this.localesProvider.get());
                        stringBuilder.append(text);
                    } else {
                        String xmltext = org.apache.commons.io.IOUtils
                                .toString(fedoraAccess.getDataStream(pid, ds), Charset.forName("UTF-8"));
                        stringBuilder.append(StringEscapeUtils.escapeHtml4(xmltext));
                    }
                } catch (cz.incad.kramerius.security.SecurityException e) {
                    LOGGER.log(Level.INFO, e.getMessage());
                } catch (Exception e) {
                    LOGGER.log(Level.SEVERE, e.getMessage(), e);
                }
            } else if (mime.equals("text/html")) {
                try {
                    String xmltext = org.apache.commons.io.IOUtils.toString(fedoraAccess.getDataStream(pid, ds),
                            Charset.forName("UTF-8"));
                    stringBuilder.append(xmltext);
                } catch (cz.incad.kramerius.security.SecurityException e) {
                    LOGGER.log(Level.INFO, e.getMessage());
                } catch (Exception e) {
                    LOGGER.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    }
    return stringBuilder.toString();
}

From source file:org.openmrs.module.rheapocadapter.web.controller.TransactionServiceController.java

@RequestMapping("/module/rheapocadapter/backEnteredQueue.form")
public String showBackEnteredQueue(ModelMap map) {
    EnteredHandler enteredHandler = new EnteredHandler();
    List<Encounter> encounter = enteredHandler.getEncounterNotSent();
    Collections.reverse(encounter);
    map.addAttribute("encounterNotSent", encounter);

    return "/module/rheapocadapter/backEnteredQueue";
}

From source file:org.grails.plugins.web.filters.CompositeInterceptor.java

protected void initReversed() {
    handlersReversed = new ArrayList<HandlerInterceptor>(handlers);
    Collections.reverse(handlersReversed);
}

From source file:com.collabnet.ccf.teamforge.TFAppHandler.java

/**
 * This method retrieves all the comments added to a particular artifact
 * (represented by the ArtifactSoapDO) and adds all the comments that are
 * added after the lastModifiedDate into the ArtifcatSoapDO's flex fields
 * with the field name as "Comment Text" [as this is the name displayed in
 * the TF trackers for the Comments]/*from w  w  w. j  a va2s.  com*/
 * 
 * It calls the private method addComments which can add comments for a list
 * of artifacts by querying the ISourceForgeSoap object for this particular
 * TF system.
 * 
 * The comments added by the connector user are ignored by this method.
 * 
 * @param artifact
 *            - The ArtifactSoapDO object whose comments need to be added
 * @param lastModifiedDate
 *            - The last read time of this tracker
 * @param connectorUser
 *            - The username that is configured to log into the TF to
 *            retrieve the artifact data.
 * @param resyncUser
 *            - The resync user for CCF
 */
public void addComments(ArtifactDO artifact, Date lastModifiedDate, String connectorUser, String resyncUser,
        boolean isPreserveBulkCommentOrder) {
    try {
        CommentList commentList = connection.getTeamForgeClient().getCommentList(artifact.getId());
        CommentRow[] comments = commentList.getDataRows();

        if (comments != null) {
            if (isPreserveBulkCommentOrder && comments.length > 1) {
                Collections.reverse(Arrays.asList(comments));
            }
            for (CommentRow comment : comments) {
                String createdBy = comment.getCreatedBy();
                Date createdDate = comment.getDateCreated();
                if (createdBy.equals(connectorUser) || createdBy.equals(resyncUser)) {
                    continue;
                }
                if (lastModifiedDate.after(createdDate) || lastModifiedDate.equals(createdDate)) {
                    continue;
                }
                String description = comment.getDescription();
                description = "\nOriginal commenter: " + createdBy + "\n" + description;
                this.addComment(TFArtifactMetaData.TFFields.commentText.getFieldName(), artifact, description);
            }
        }
    } catch (RemoteException e) {
        log.error("Could not get comments list for artifact " + artifact.getId() + ": " + e.getMessage());
    }
}

From source file:Service.MessageServiceImpl.java

/**
 * Rcupre les messages envoys par une personne  l'utilisateur
 *
 * @param idUser l'id de l'utilisateur// w ww  .  jav a2  s. com
 * @param idPersonne l'id de la personne qui a envoy les messages
 * @return un string des messages formats
 */
@Override
public String getMessagesSinglePersonne(int idUser, int idPersonne) {
    List<MessagesEntity> messages = messagesDAO.findByPersonne(idPersonne, idUser);
    Collections.sort(messages, new Comparator<MessagesEntity>() {
        @Override
        public int compare(MessagesEntity o1, MessagesEntity o2) {
            return o2.getDate().compareTo(o1.getDate());
        }
    });

    Collections.reverse(messages);

    String message = "";
    for (MessagesEntity me : messages) {

        SimpleDateFormat messageDate = new SimpleDateFormat("dd,MM,yyyy 'a' HH:mm:ss ");
        String date;
        date = messageDate.format(me.getDate());

        message += "<div class=\"message col-lg-offset-1 col-lg-10 col-lg-offset-1\">"; // Conteneur du statut

        message += "<div class=\"row rowMessage\">";
        message += "<div class=\"message\">";
        message += me.getEmetteur().getPrenom() + " " + me.getEmetteur().getNom();
        message += "</div>";
        message += "</div>";

        message += "<div class=\"row rowMessage messageText\">";
        message += "<div class=\"message\">"; // Conteneur du texte du statut
        message += me.getTexte();
        message += "</div>";
        message += "</div>";

        message += "<div class=\"row rowMessage\">";
        message += "<div class=\"date\">Envoy le " + date + "</div>";
        message += "</div>";
        message += "</div>";
    }
    return message;
}

From source file:com.logsniffer.web.controller.system.SystemBaseController.java

private List<NavNode> getBreadcrumb(NavNode activeNode) {
    ArrayList<NavNode> nodes = new ArrayList<NavNode>();
    while (activeNode.getParent() != null) {
        nodes.add(activeNode.getParent());
        activeNode = activeNode.getParent();
    }//from   w  w  w.  j  a va2s  .  c o m
    Collections.reverse(nodes);
    return nodes;
}

From source file:com.ait.lienzo.test.stub.overlays.NArrayBaseJSO.java

public void reverse() {
    Collections.reverse(list);
}

From source file:de.jcup.egradle.core.util.History.java

/**
 * Returns list of current items inside history. The list is ordered from
 * last to first/*ww w . j  a va 2  s  .  c  o m*/
 * 
 * @return a list of all items.
 */
public List<T> toList() {
    List<T> toList = new ArrayList<>(list);
    Collections.reverse(toList);
    return toList;
}

From source file:com.dickthedeployer.dick.web.service.GroupService.java

public GroupModel getGroup(String name) throws NotFoundException {
    Optional<Group> groupOptional = groupDao.findByNamespaceName(name);
    Group group = groupOptional.orElseThrow(NotFoundException::new);
    List<ProjectModel> projectModels = group.getNamespace().getProjects().stream().map((Project project) -> {
        ProjectModel model = ProjectMapper.mapProjectView(project);
        model.setLastBuild(buildService.findLastBuild(project));
        return model;
    }).collect(toList());/*from w ww.j  a  va 2s.  co  m*/
    GroupModel model = GroupMapper.mapGroupShallow(group);
    Collections.reverse(projectModels);
    model.setProjects(projectModels);
    return model;
}

From source file:com.sangupta.clitools.dir.FileSort.java

@Override
protected void postProcess() {
    // number of files
    final int num = files.size();

    // now sort these files
    Comparator<File> comparator;
    if ("date".equalsIgnoreCase(this.on)) {
        comparator = new FileDateComparator();
    } else if ("size".equalsIgnoreCase(this.on)) {
        comparator = new FileSizeComparator();
    } else if ("name".equalsIgnoreCase(this.on)) {
        comparator = new FileNameComparator();
    } else {//from  w ww . jav  a  2  s  . c o m
        System.out.println("Unrecognized sort option: " + this.on);
        return;
    }

    // sort
    Collections.sort(this.files, comparator);

    // now depending on the asc/desc order rename
    if (this.descending) {
        Collections.reverse(this.files);
    }

    // iterate
    int count = 1;
    int maxStringSize = String.valueOf(num).length();
    for (File file : this.files) {
        File baseDir = file.getParentFile();
        String newName = format(maxStringSize, count++) + "-" + file.getName();
        System.out.println("Renaming file " + file.getAbsolutePath() + " to " + newName);
        file.renameTo(new File(baseDir, newName));
    }
}