List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:web.DiaryServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response.setHeader("Pragma", "no-cache"); // HTTP 1.0. response.setDateHeader("Expires", 0); // Proxies. HttpSession session = request.getSession(); try (PrintWriter out = response.getWriter()) { String action = request.getParameter("action"); if (action == null) { Profilo personalProfile = profiloFacade.getProfilo((Long) (session.getAttribute("id"))); request.setAttribute("profilo", personalProfile); RequestDispatcher rd = getServletContext().getRequestDispatcher("/profile.jsp"); rd.forward(request, response); } else if (action.equals("goToDiary")) { if (request.getParameter("idDiario") != null && !request.getParameter("idDiario").equals("")) { Long idDiario = new Long(request.getParameter("idDiario")); Diario d = gestoreDiari.getDiario(idDiario); Profilo p = profiloFacade.getProfilo((String) session.getAttribute("email")); //List<Post> posts = gestoreDiari.getPosts(idDiario); if (d != null) { d.setPost(Lists.reverse(d.getPost())); String post;//from w w w . jav a 2 s. c o m String tmp = ""; String tmphashtag = ""; for (int i = 0; i < d.getPost().size(); i++) { if (!d.getPost().get(i).getHashtags().isEmpty()) { post = d.getPost().get(i).getTesto(); for (int j = 0; j < post.length(); j++) { if (post.charAt(j) == '#') { tmp += "<a href='/HomeTogether-web/NavBarServlet?action=searchUtente&ric_utente=%23"; j++; while (j < post.length() && post.charAt(j) != ' ') { tmphashtag += post.charAt(j); j++; } tmp += tmphashtag + "' style='color:rgba(228, 131, 18, 0.6)'><B>#"; tmp += tmphashtag; tmp += "</B></a>"; if (j < post.length()) { tmp += post.charAt(j); } tmphashtag = ""; } else { tmp += post.charAt(j); } } d.getPost().get(i).setTesto(tmp); tmp = ""; } } request.setAttribute("profilo", p); request.setAttribute("diario", d); RequestDispatcher rd = getServletContext().getRequestDispatcher("/diary.jsp"); rd.forward(request, response); } else { Profilo personalProfile = profiloFacade.getProfilo((Long) (session.getAttribute("id"))); request.setAttribute("profilo", personalProfile); request.setAttribute("danger", "diario non esistente!"); RequestDispatcher rd = getServletContext().getRequestDispatcher("/profile.jsp"); rd.forward(request, response); } } else { Profilo personalProfile = profiloFacade.getProfilo((Long) (session.getAttribute("id"))); request.setAttribute("profilo", personalProfile); request.setAttribute("danger", "diario non esistente!"); RequestDispatcher rd = getServletContext().getRequestDispatcher("/profile.jsp"); rd.forward(request, response); } } else if (action.equals("submitPost")) { Long idDiario = new Long(request.getParameter("idDiario")); String text = request.getParameter("text"); Diario d = gestoreDiari.getDiario(idDiario); Profilo p = profiloFacade.getProfilo((String) session.getAttribute("email")); Post post = gestoreDiari.aggiungiPost(d, p, text); //estrazione degli hashtag nel testo String[] hashtags = text.split("#"); String[] tmp; for (int i = 0; i < hashtags.length; i++) { if (i == 0 && text.charAt(0) == '#') { tmp = hashtags[i].split(" "); gestoreDiari.aggiungiHashtag(post, tmp[0]); } else if (i != 0) { tmp = hashtags[i].split(" "); gestoreDiari.aggiungiHashtag(post, tmp[0]); } } out.println(post.getId()); } else if (action.equals("editPost")) { Long idPost = new Long(request.getParameter("idPost")); String testo = request.getParameter("testo"); Post post = gestoreDiari.getPost(idPost); gestoreDiari.modificaPost(post, testo); out.println("0"); } else if (action.equals("removePost")) { Long idPost = new Long(request.getParameter("idPost")); Post post = gestoreDiari.getPost(idPost); gestoreDiari.eliminaPost(post); out.println("0"); } else if (action.equals("addLike")) { Long idPost = new Long(request.getParameter("idPost")); Post post = gestoreDiari.getPost(idPost); Profilo p = profiloFacade.getProfilo((String) session.getAttribute("email")); gestoreDiari.aggiungiLike(post, p); out.println("0"); } else if (action.equals("removeLike")) { Long idPost = new Long(request.getParameter("idPost")); Post post = gestoreDiari.getPost(idPost); Profilo p = profiloFacade.getProfilo((String) session.getAttribute("email")); int res = gestoreDiari.rimuoviLike(post, p); out.println(res); } else if (action.equals("addComment")) { Long idPost = new Long(request.getParameter("idPost")); String testo = request.getParameter("testo"); Post post = gestoreDiari.getPost(idPost); Profilo p = profiloFacade.getProfilo((String) session.getAttribute("email")); Long idCommento = gestoreDiari.aggiungiCommento(post, p, testo); out.println(idCommento); } else if (action.equals("editComment")) { Long idCommento = new Long(request.getParameter("idCommento")); String testo = request.getParameter("testo"); Commento commento = gestoreDiari.getCommento(idCommento); gestoreDiari.modificaCommento(commento, testo); out.println("0"); } else if (action.equals("removeComment")) { Long idCommento = new Long(request.getParameter("idCommento")); Commento commento = gestoreDiari.getCommento(idCommento); gestoreDiari.eliminaCommento(commento); out.println("0"); } else { Profilo personalProfile = profiloFacade.getProfilo((Long) (session.getAttribute("id"))); request.setAttribute("profilo", personalProfile); request.setAttribute("danger", "azione sconosciuta!"); RequestDispatcher rd = getServletContext().getRequestDispatcher("/profile.jsp"); rd.forward(request, response); } } }
From source file:io.hops.hopsworks.common.dao.pythonDeps.LibVersions.java
public void reverseVersionList() { this.versions = Lists.reverse(this.versions); }
From source file:org.sonar.javascript.checks.ShorthandPropertiesNotGroupedCheck.java
@Override public void visitObjectLiteral(ObjectLiteralTree tree) { // list keeps true for shorthand property List<Boolean> isShorthandPropertyList = new ArrayList<>(); int shorthandPropertiesNumber = 0; for (Tree propertyTree : tree.properties()) { boolean isShorthandProperty = isShorthand(propertyTree); isShorthandPropertyList.add(isShorthandProperty); shorthandPropertiesNumber += isShorthandProperty ? 1 : 0; }// ww w .jav a2 s. c o m if (shorthandPropertiesNumber > 0) { int numberOfShorthandAtBeginning = getNumberOfTrueAtBeginning(isShorthandPropertyList); int numberOfShorthandAtEnd = getNumberOfTrueAtBeginning(Lists.reverse(isShorthandPropertyList)); boolean allAtBeginning = numberOfShorthandAtBeginning == shorthandPropertiesNumber; boolean allAtEnd = numberOfShorthandAtEnd == shorthandPropertiesNumber; int propertiesNumber = tree.properties().size(); if (!allAtBeginning && numberOfShorthandAtBeginning > numberOfShorthandAtEnd) { raiseIssuePattern(tree, numberOfShorthandAtBeginning, propertiesNumber, "beginning"); } else if (!allAtEnd && numberOfShorthandAtEnd > numberOfShorthandAtBeginning) { raiseIssuePattern(tree, 0, propertiesNumber - numberOfShorthandAtEnd, "end"); } else if (!allAtBeginning && !allAtEnd) { raiseIssue(tree, 0, propertiesNumber, MESSAGE, SECONDARY_MESSAGE); } } super.visitObjectLiteral(tree); }
From source file:da.RequestJpaController.java
public List<Request> getRequests(int type) { TypedQuery<Request> query = getEntityManager() .createQuery("SELECT r FROM Request r WHERE r.type=:type ORDER BY r.time DESC", Request.class); query.setParameter("type", type); return Lists.reverse(query.getResultList()); }
From source file:com.searchcode.app.jobs.repository.IndexGitHistoryJob.java
public void getGitChangeSets() throws IOException, GitAPIException { //Repository localRepository = new FileRepository(new File("./repo/server/.git")); Repository localRepository = new FileRepository(new File("./repo/thumbor/.git")); Git git = new Git(localRepository); Iterable<RevCommit> logs = git.log().call(); List<GitChangeSet> gitChangeSets = new ArrayList<>(); for (RevCommit rev : logs) { String message = rev.getFullMessage(); String author = rev.getAuthorIdent().getName(); Date expiry = new Date(Long.valueOf(rev.getCommitTime()) * 1000); System.out.println(expiry.toString() + " " + rev.getCommitTime() + " " + rev.getName()); gitChangeSets.add(new GitChangeSet(message, author, rev.getName(), expiry)); }/*from www.ja v a 2 s . com*/ gitChangeSets = Lists.reverse(gitChangeSets); // TODO currently this is ignoring the very first commit changes need to include those for (int i = 1; i < gitChangeSets.size(); i++) { System.out.println("///////////////////////////////////////////////"); this.getRevisionChanges(localRepository, git, gitChangeSets.get(i - 1), gitChangeSets.get(i)); } }
From source file:cf.adriantodt.David.modules.cmds.FeedCmd.java
public static void onFeed(Subscription subs) { try {/* w w w.jav a2 s. co m*/ SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(new XmlReader(subs.url)); Holder<Integer> i = new Holder<>(0); Holder<Optional<Integer>> h = new Holder<>(Optional.empty()); Lists.reverse(CollectionUtils.subListOn(feed.getEntries(), entryPredicate -> subs.equalsLastHashCode(entryPredicate.getLink().hashCode()))) .forEach(entry -> { i.var++; subs.compiledPushes.add(FeedingUtil.handleEntry(subs, entry)); h.var = Optional.of(entry.getLink().hashCode()); }); if (i.var != 0) logger.trace(subs.pushName + ".size() += " + i.var); h.var.ifPresent(subs::setLastHashCode); } catch (Exception e) { logger.error("Error while creating messages", e); } }
From source file:org.sonar.javascript.checks.CommaOperatorUseCheck.java
private static List<SyntaxToken> getCommas(BinaryExpressionTree tree) { List<SyntaxToken> commas = new ArrayList<>(); commas.add(tree.operator());/*from www . j ava2s . com*/ ExpressionTree currentExpression = tree.leftOperand(); while (currentExpression.is(Kind.COMMA_OPERATOR)) { commas.add(((BinaryExpressionTree) currentExpression).operator()); currentExpression = ((BinaryExpressionTree) currentExpression).leftOperand(); } return Lists.reverse(commas); }
From source file:com.butent.bee.shared.treelayout.util.AbstractTreeForTreeLayout.java
@Override public List<T> getChildrenReverse(T node) { return Lists.reverse(getChildren(node)); }
From source file:com.github.fhirschmann.clozegen.lib.generators.FrequencyGapGenerator.java
@Override public Optional<Gap> generate(final int count) { if (model.getMultiset().contains(token)) { int tokenCount = model.getMultiset().count(token); Multiset<String> ms = HashMultiset.create(); // compute a multiset with counts(x) = |count(x) - count(token)| for (Entry<String> entry : model.getMultiset().entrySet()) { ms.add(entry.getElement(), Math.abs(entry.getCount() - tokenCount)); }//from www . ja v a 2 s. c o m if (ms.elementSet().size() < count - 1) { // not enough data to create as many answer options as requested return Optional.absent(); } else { return Optional.of( Gap.with(token, Lists.reverse(MultisetUtils.sortedElementList(ms)).subList(0, count - 1))); } } else { // we have no knowledge of the word in question return Optional.absent(); } }
From source file:com.facebook.presto.metadata.MetadataUtil.java
public static QualifiedTableName createQualifiedTableName(Session session, Node node, QualifiedName name) { requireNonNull(session, "session is null"); requireNonNull(name, "name is null"); checkArgument(name.getParts().size() <= 3, "Too many dots in table name: %s", name); List<String> parts = Lists.reverse(name.getParts()); String tableName = parts.get(0); String schemaName = (parts.size() > 1) ? parts.get(1) : session.getSchema().orElseThrow(() -> new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set")); String catalogName = (parts.size() > 2) ? parts.get(2) : session.getCatalog().orElseThrow(() -> new SemanticException(SCHEMA_NOT_SPECIFIED, node, "Schema must be specified when session schema is not set")); return new QualifiedTableName(catalogName, schemaName, tableName); }