List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:edu.udo.scaffoldhunter.view.scaffoldtree.config.ConfigMapping.java
/** * For Interval Mappings this can be used to query the color of the value's * interval.// ww w . ja va 2 s . c o m * <p> * For a Gradient Mapping a value between 0 and 1 can be used to index into * the gradient defined by both gradient Colors. For a GradientMapping * values larger 1 are treated as 1, values smaller than 0 are treated as 0. * * @param value * the value which is mapped to a color * @return a Color based on the mapping type, interval colors or gradient * colors respectively and the provided value */ public Color getColor(double value) { // Lower bound is not included except for the lowest interval. // As a result, intervals with lb=ub are not supported. switch (mappingType) { case Interval: for (Interval i : Lists.reverse(intervals)) { if (value > i.getLowerBound()) return i.getColor(); } if (!intervals.isEmpty()) { return intervals.get(0).getColor(); } break; case Gradient: if (Double.isNaN(value)) return null; if (value > 1) value = 1; else if (value < 0) value = 0; int r1 = gradientColor1.getRed(); int r2 = gradientColor2.getRed(); int g1 = gradientColor1.getGreen(); int g2 = gradientColor2.getGreen(); int b1 = gradientColor1.getBlue(); int b2 = gradientColor2.getBlue(); int r = (int) ((r2 - r1) * value) + r1; int g = (int) ((g2 - g1) * value) + g1; int b = (int) ((b2 - b1) * value) + b1; return new Color(r, g, b); } return null; }
From source file:com.google.devtools.moe.client.project.ProjectContextFactory.java
private List<InverseTranslatorStep> makeInverseStepsFromConfigs(List<StepConfig> stepConfigs) throws InvalidProject { ImmutableList.Builder<InverseTranslatorStep> inverseSteps = ImmutableList.builder(); for (StepConfig sc : Lists.reverse(stepConfigs)) { inverseSteps.add(new InverseTranslatorStep("inverse_" + sc.getName(), makeInverseEditorFromConfig("inverse_" + sc.getName(), sc.getEditorConfig()))); }//from w w w. j a va 2 s. c o m return inverseSteps.build(); }
From source file:com.android.ahat.AhatSnapshot.java
/** * Look up the site at which the given object was allocated. *//*from ww w. j a v a 2s . c om*/ public Site getSiteForInstance(Instance inst) { Site site = mRootSite; StackTrace stack = getStack(inst); if (stack != null) { StackFrame[] frames = getStackFrames(stack); if (frames != null) { List<StackFrame> path = Lists.reverse(Arrays.asList(frames)); site = mRootSite.getChild(path.iterator()); } } return site; }
From source file:org.sonar.javascript.cfg.ControlFlowGraphBuilder.java
private void build(List<? extends Tree> trees) { for (Tree tree : Lists.reverse(trees)) { build(tree); } }
From source file:edu.cmu.lti.oaqa.baseqa.answer.CavUtil.java
public static List<Token> getPath(Token src, Token dst) { if (src == null || dst == null) { return null; }/*from ww w .j av a2 s . c om*/ List<Token> srcPathFromRoot = Lists.reverse(getPathToRoot(src)); List<Token> dstPathFromRoot = Lists.reverse(getPathToRoot(dst)); int commonLen = Math.min(srcPathFromRoot.size(), dstPathFromRoot.size()); int firstDiffIndex = IntStream.range(0, commonLen) .filter(i -> !srcPathFromRoot.get(i).equals(dstPathFromRoot.get(i))).findFirst().orElse(commonLen); // different root: src and dst may be from different sentences if (firstDiffIndex == 0) { return null; } ImmutableList.Builder<Token> builder = ImmutableList.builder(); builder.addAll(Lists.reverse(srcPathFromRoot.subList(firstDiffIndex, srcPathFromRoot.size()))); builder.add(srcPathFromRoot.get(firstDiffIndex - 1)); builder.addAll(dstPathFromRoot.subList(firstDiffIndex, dstPathFromRoot.size())); return builder.build(); }
From source file:org.richfaces.resource.optimizer.ordering.PartialOrderToCompleteOrder.java
private void registerDependencies(Collection<T> collection) { List<T> reversedOrder = Lists.reverse(Lists.newLinkedList(collection)); Set<T> newItemDependencies = Sets.newLinkedHashSet(collection); for (T newItem : reversedOrder) { newItemDependencies.remove(newItem); registerDependenciesForItem(newItem, Sets.newLinkedHashSet(newItemDependencies)); }//from ww w . j a v a2 s .com }
From source file:org.sonatype.nexus.rest.feeds.sources.ErrorWarningFeedSource.java
/** * Extracts ERROR and WARN log lines from given log file. It returns ordered list (newest 1st, oldest last) of * found//from w w w . ja va 2 s . co m * log lines, and that list is maximized to have {@code entriesToExtract} entries. * * @param logFile the log file to scan. * @param entriesToExtract The number how much "newest" entries should be collected. */ protected List<SyndEntry> extractEntriesFromLogfile(final File logFile, final int entriesToExtract) throws IOException { final List<SyndEntry> entries = Lists.newArrayList(); Closer closer = Closer.create(); try { final BufferedReader reader = Files.newReader(logFile, Charset.forName("UTF-8")); String logLine = reader.readLine(); while (logLine != null) { if (logLine.contains(" WARN ") || logLine.contains(" ERROR ")) { final SyndEntry entry = new SyndEntryImpl(); entry.setPublishedDate(new Date()); // FIXME: item.getEventDate(); entry.setAuthor(getNexusAuthor()); entry.setLink("/"); if (logLine.contains(" ERROR ")) { entry.setTitle("Error"); } else if (logLine.contains(" WARN ")) { entry.setTitle("Warning"); } final StringBuilder contentValue = new StringBuilder(); contentValue.append(logLine); // FIXME: Grab following stacktrace if any in log // if ( StringUtils.isNotEmpty( item.getStackTrace() ) ) // { // // we need <br/> and to display stack trace on RSS // String stackTrace = item.getStackTrace().replace( // (String) System.getProperties().get( "line.separator" ), // "<br/>" ); // stackTrace = stackTrace.replace( "\t", " " ); // contentValue.append( "<br/>" ).append( stackTrace ); // } SyndContent content = new SyndContentImpl(); content.setType(MediaType.TEXT_PLAIN.toString()); content.setValue(contentValue.toString()); entry.setDescription(content); entries.add(entry); if (entries.size() > entriesToExtract) { entries.remove(0); } } logLine = reader.readLine(); } } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } return Lists.reverse(entries); }
From source file:net.sourceforge.ganttproject.parser.TaskTagHandler.java
@Override public void parsingFinished() { List<Task> tasksBottomUp = Lists.reverse(myManager.getTaskHierarchy().breadthFirstSearch(null, false)); for (Task t : tasksBottomUp) { myTreeFacade.setExpanded(t,/*from w w w . j a v a2s.co m*/ Objects.firstNonNull(myTaskIdToExpansionState.get(t.getTaskID()), Boolean.TRUE)); } }
From source file:com.google.javascript.jscomp.LateEs6ToEs3Converter.java
/** * Transpiles an object node with computed property, * and add type information to the new nodes if this pass ran after type checking. * For example,<pre> {@code//from w w w . j ava 2s. c om * var obj = {a: 1, [i++]: 2} * is transpiled to * var $jscomp$compprop0 = {}; * var obj = ($jscomp$compprop0.a = 1, ($jscomp$compprop0[i++] = 2, $jscomp$compprop0)); * }</pre> * Note that when adding type information to the nodes, the NAME node $jscomp$compprop0 * would always be assigned the type of the entire object (in the above example {a: number}). * This is because we do not have sufficient type information during transpilation to know, * for example, $jscomp$compprop0 has type Object{} in the expression $jscomp$compprop0.a = 1 */ private void visitObjectWithComputedProperty(Node obj) { checkArgument(obj.isObjectLit()); List<Node> props = new ArrayList<>(); Node currElement = obj.getFirstChild(); JSType objectType = obj.getJSType(); while (currElement != null) { if (currElement.getBooleanProp(Node.COMPUTED_PROP_GETTER) || currElement.getBooleanProp(Node.COMPUTED_PROP_SETTER)) { Es6ToEs3Util.cannotConvertYet(compiler, currElement, "computed getter/setter in an object literal"); return; } else if (currElement.isGetterDef() || currElement.isSetterDef()) { currElement = currElement.getNext(); } else { Node nextNode = currElement.getNext(); obj.removeChild(currElement); props.add(currElement); currElement = nextNode; } } String objName = FRESH_COMP_PROP_VAR + compiler.getUniqueNameIdSupplier().get(); props = Lists.reverse(props); Node result = withType(IR.name(objName), objectType); for (Node propdef : props) { if (propdef.isComputedProp()) { Node propertyExpression = propdef.removeFirstChild(); Node value = propdef.removeFirstChild(); JSType valueType = value.getJSType(); result = withType(IR.comma(withType(IR.assign( withUnknownType(IR.getelem(withType(IR.name(objName), objectType), propertyExpression)), value), valueType), result), objectType); } else { Node val = propdef.removeFirstChild(); JSType valueType = val.getJSType(); propdef.setToken(Token.STRING); propdef.setJSType(stringType); Token token = propdef.isQuotedString() ? Token.GETELEM : Token.GETPROP; Node access = withType(new Node(token, withType(IR.name(objName), objectType), propdef), valueType); result = withType(IR.comma(withType(IR.assign(access, val), valueType), result), objectType); } } Node statement = obj; while (!NodeUtil.isStatement(statement)) { statement = statement.getParent(); } result.useSourceInfoIfMissingFromForTree(obj); obj.replaceWith(result); JSType simpleObjectType = createType(addTypes, registry, JSTypeNative.EMPTY_OBJECT_LITERAL_TYPE); Node var = IR.var(withType(IR.name(objName), objectType), withType(obj, simpleObjectType)); var.useSourceInfoIfMissingFromForTree(statement); statement.getParent().addChildBefore(var, statement); compiler.reportChangeToEnclosingScope(var); }
From source file:net.sourceforge.ganttproject.TaskContainmentHierarchyFacadeImpl.java
@Override public List<Integer> getOutlinePath(Task task) { int depth = getDepth(task); List<Integer> result = Lists.newArrayListWithExpectedSize(depth); TreeNode node = myTask2treeNode.get(task); for (int i = 0; i < depth; i++) { TreeNode containerNode = node.getParent(); result.add(i, containerNode.getIndex(node) + 1); node = containerNode;//from w ww . j a va 2 s . c o m } return Lists.reverse(result); }