List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:com.searchcode.app.util.LoggerWrapper.java
public synchronized List<String> getAllLogs() { List<String> values = new ArrayList<>(); try {//from w w w. j a va2 s .c om values = new ArrayList(this.allCache); values = Lists.reverse(values); } catch (ArrayIndexOutOfBoundsException ignored) { } return values; }
From source file:co.cask.cdap.data2.transaction.queue.hbase.HBaseQueueClientFactory.java
@Override public QueueConsumer createConsumer(final QueueName queueName, final ConsumerConfig consumerConfig, int numGroups) throws IOException { final HBaseQueueAdmin admin = ensureTableExists(queueName); try {/*from w w w . ja v a 2 s.c om*/ final long groupId = consumerConfig.getGroupId(); // A callback for create a list of HBaseQueueConsumer // based on the current queue consumer state of the given group Callable<List<HBaseQueueConsumer>> consumerCreator = new Callable<List<HBaseQueueConsumer>>() { @Override public List<HBaseQueueConsumer> call() throws Exception { List<HBaseConsumerState> states; try (HBaseConsumerStateStore stateStore = admin.getConsumerStateStore(queueName)) { TransactionExecutor txExecutor = Transactions.createTransactionExecutor(txExecutorFactory, stateStore); // Find all consumer states for consumers that need to be created based on current state states = txExecutor.execute(new Callable<List<HBaseConsumerState>>() { @Override public List<HBaseConsumerState> call() throws Exception { List<HBaseConsumerState> consumerStates = Lists.newArrayList(); HBaseConsumerState state = stateStore.getState(groupId, consumerConfig.getInstanceId()); if (state.getPreviousBarrier() == null) { // Old HBase consumer (Salted based, not sharded) consumerStates.add(state); return consumerStates; } // Find the smallest start barrier that has something to consume for this instance. // It should always exists since we assume the queue is configured before this method is called List<QueueBarrier> queueBarriers = stateStore.getAllBarriers(groupId); if (queueBarriers.isEmpty()) { throw new IllegalStateException(String.format( "No consumer information available. Queue: %s, GroupId: %d, InstanceId: %d", queueName, groupId, consumerConfig.getInstanceId())); } QueueBarrier startBarrier = Iterables.find(Lists.reverse(queueBarriers), new Predicate<QueueBarrier>() { @Override public boolean apply(QueueBarrier barrier) { return barrier.getGroupConfig().getGroupSize() > consumerConfig .getInstanceId() && stateStore.isAllConsumed(consumerConfig, barrier.getStartRow()); } }, queueBarriers.get(0)); int groupSize = startBarrier.getGroupConfig().getGroupSize(); for (int i = consumerConfig.getInstanceId(); i < groupSize; i += consumerConfig .getGroupSize()) { consumerStates.add(stateStore.getState(groupId, i)); } return consumerStates; } }); } List<HBaseQueueConsumer> consumers = Lists.newArrayList(); for (HBaseConsumerState state : states) { QueueType queueType = (state.getPreviousBarrier() == null) ? QueueType.QUEUE : QueueType.SHARDED_QUEUE; HTable hTable = createHTable(admin.getDataTableId(queueName, queueType)); int distributorBuckets = getDistributorBuckets(hTable.getTableDescriptor()); HBaseQueueStrategy strategy = (state.getPreviousBarrier() == null) ? new SaltedHBaseQueueStrategy(hBaseTableUtil, distributorBuckets) : new ShardedHBaseQueueStrategy(hBaseTableUtil, distributorBuckets); consumers.add(queueUtil.getQueueConsumer(cConf, hTable, queueName, state, admin.getConsumerStateStore(queueName), strategy)); } return consumers; } }; return new SmartQueueConsumer(queueName, consumerConfig, consumerCreator); } catch (Exception e) { // If there is exception, nothing much can be done here besides propagating Throwables.propagateIfPossible(e); throw new IOException(e); } }
From source file:com.netxforge.netxstudio.screens.f2.NodeTypeHistory.java
@SuppressWarnings("unused") private void historicalNodeTypes(List<HistoricNodeType> histNodeTypes) { String historicalResourceName = editingService.resolveHistoricalResourceName(nodeType); if (historicalResourceName != null) { URI uri = URI.createURI(historicalResourceName); if (editingService.getData().hasResource(uri)) { Resource historyResource = editingService.getData() .getResource(editingService.getEditingDomain().getResourceSet(), uri); int entryCount = historyResource.getContents().size(); // We need the resource list backwards. for (EObject object : Lists.reverse(historyResource.getContents())) { histNodeTypes.add(new HistoricNodeType(entryCount, (NodeType) object)); entryCount--;/* w w w . j a va 2s .c om*/ } } else { histNodeTypes.add(new HistoricNodeType(1, nodeType)); } } }
From source file:org.apache.druid.indexing.firehose.IngestSegmentFirehoseFactory.java
@VisibleForTesting static List<String> getUniqueDimensions(List<TimelineObjectHolder<String, DataSegment>> timelineSegments, @Nullable Set<String> excludeDimensions) { final BiMap<String, Integer> uniqueDims = HashBiMap.create(); // Here, we try to retain the order of dimensions as they were specified since the order of dimensions may be // optimized for performance. // Dimensions are extracted from the recent segments to olders because recent segments are likely to be queried more // frequently, and thus the performance should be optimized for recent ones rather than old ones. // timelineSegments are sorted in order of interval int index = 0; for (TimelineObjectHolder<String, DataSegment> timelineHolder : Lists.reverse(timelineSegments)) { for (PartitionChunk<DataSegment> chunk : timelineHolder.getObject()) { for (String dimension : chunk.getObject().getDimensions()) { if (!uniqueDims.containsKey(dimension) && (excludeDimensions == null || !excludeDimensions.contains(dimension))) { uniqueDims.put(dimension, index++); }//from w ww . j a v a 2 s. co m } } } final BiMap<Integer, String> orderedDims = uniqueDims.inverse(); return IntStream.range(0, orderedDims.size()).mapToObj(orderedDims::get).collect(Collectors.toList()); }
From source file:com.tasktop.koans.PathToEnlightment.java
private void storeFailures() { List<String> failures = getLastFailures(); failures.add(firstFailure.getDescription().getDisplayName()); try {/*from ww w . j a va2 s . co m*/ File file = getTmpFile(); CharSink sink = Files.asCharSink(file, Charsets.UTF_8); sink.writeLines(Lists.reverse(Lists.reverse(failures).stream().limit(10).collect(Collectors.toList())), "\n"); } catch (IOException shouldNotHappen) { throw new IllegalStateException(shouldNotHappen); } }
From source file:org.apache.gobblin.config.common.impl.InMemoryTopology.java
public List<ConfigKeyPath> getImportsRecursively(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { return new ImportTraverser<>(key -> { if (key.isRootPath()) { return new LinkedList<>(); }/* ww w .ja v a 2 s .c om*/ List<ConfigKeyPath> imports = Lists.newArrayList(); imports.addAll(Lists.reverse(getOwnImports(key, runtimeConfig))); imports.add(key.getParent()); return imports; }, this.recursiveImportMap).traverseGraphRecursively(configKey); }
From source file:com.b2international.snowowl.datastore.server.history.HistoryInfoQueryExecutorImpl.java
protected List<CDOBranchPoint> getBranchPoints(final InternalHistoryInfoConfiguration configuration) { final CDOBranch currentBranch = configuration.getView().getBranch(); final ImmutableList.Builder<CDOBranchPoint> branchPointsBuilder = ImmutableList.builder(); final CDOBranchPoint[] basePath = currentBranch.getBasePath(); for (int i = 1; i < basePath.length; i++) { branchPointsBuilder.add(basePath[i]); }//w w w . j a va 2s.com branchPointsBuilder.add(currentBranch.getPoint(Long.MAX_VALUE)); // Start with the branch in question, then work our way back return ImmutableList.copyOf(Lists.reverse(branchPointsBuilder.build())); }
From source file:org.openqa.selenium.remote.server.rest.ResultConfig.java
public Throwable getRootExceptionCause(Throwable originalException) { Throwable toReturn = originalException; if (originalException instanceof UndeclaredThrowableException) { // An exception was thrown within an invocation handler. Not smart. // Extract the original exception toReturn = originalException.getCause().getCause(); }/* ww w. j ava 2s . c o m*/ // When catching an exception here, it is most likely wrapped by // several other exceptions. Peel the layers and use the original // exception as the one to return to the client. That is the most // likely to contain informative data about the error. // This is a safety measure to make sure this loop is never endless List<Throwable> chain = Lists.newArrayListWithExpectedSize(10); for (Throwable current = toReturn; current != null && chain.size() < 10; current = current.getCause()) { chain.add(current); } if (chain.isEmpty()) { return null; } // If the root cause came from another server implementing the wire protocol, there might // not have been enough information to fully reconstitute its error, in which case we'll // want to return the last 2 causes - with the outer error providing context to the // true root cause. These case are identified by the root cause not being mappable to a // standard WebDriver error code, but its wrapper is mappable. // // Of course, if we only have one item in our chain, go ahead and return. ErrorCodes ec = new ErrorCodes(); Iterator<Throwable> reversedChain = Lists.reverse(chain).iterator(); Throwable rootCause = reversedChain.next(); if (!reversedChain.hasNext() || ec.isMappableError(rootCause)) { return rootCause; } Throwable nextCause = reversedChain.next(); return ec.isMappableError(nextCause) ? nextCause : rootCause; }
From source file:org.sosy_lab.cpachecker.cfa.postprocessing.function.NullPointerChecks.java
private static void handleEdge(CFAEdge edge, MutableCFA cfa, Supplier<CFANode> targetNode, CBinaryExpressionBuilder builder) throws CParserException { ContainsPointerVisitor visitor = new ContainsPointerVisitor(); if (edge instanceof CReturnStatementEdge) { Optional<CExpression> returnExp = ((CReturnStatementEdge) edge).getExpression(); if (returnExp.isPresent()) { returnExp.get().accept(visitor); }//ww w . j a v a 2s .c om } else if (edge instanceof CStatementEdge) { CStatement stmt = ((CStatementEdge) edge).getStatement(); if (stmt instanceof CFunctionCallStatement) { ((CFunctionCallStatement) stmt).getFunctionCallExpression().accept(visitor); } else if (stmt instanceof CExpressionStatement) { ((CExpressionStatement) stmt).getExpression().accept(visitor); } else if (stmt instanceof CAssignment) { ((CAssignment) stmt).getRightHandSide().accept(visitor); ((CAssignment) stmt).getLeftHandSide().accept(visitor); } } else if (edge instanceof CDeclarationEdge) { CDeclaration decl = ((CDeclarationEdge) edge).getDeclaration(); if (!decl.isGlobal() && decl instanceof CVariableDeclaration) { try { for (CAssignment assignment : CInitializers.convertToAssignments((CVariableDeclaration) decl, edge)) { // left-hand side can be ignored (it is the currently declared variable assignment.getRightHandSide().accept(visitor); } } catch (UnrecognizedCCodeException e) { throw new CParserException(e); } } } else if (edge instanceof CAssumeEdge) { ((CAssumeEdge) edge).getExpression().accept(visitor); } for (CExpression exp : Lists.reverse(visitor.dereferencedExpressions)) { edge = insertNullPointerCheck(edge, exp, cfa, targetNode, builder); } }
From source file:com.searchcode.app.util.LoggerWrapper.java
public synchronized List<String> getInfoLogs() { List<String> values = new ArrayList<>(); try {//from w w w . j a va2 s . c o m values = new ArrayList(this.infoRecentCache); values = Lists.reverse(values); } catch (ArrayIndexOutOfBoundsException ignored) { } return values; }