List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:io.airlift.event.client.EventFieldMetadata.java
private static void checkForCycles(Object value, Deque<Object> objectStack) throws InvalidEventException { for (Object o : objectStack) { if (value == o) { List<Object> path = Lists.reverse(Lists.newArrayList(objectStack)); throw new InvalidEventException("Cycle detected in event data: %s", path); }//w w w . j ava2s .com } }
From source file:org.inria.myriads.snoozecommon.communication.groupmanager.GroupManagerDescription.java
/** * Returns the algorithm virtual machine meta data. * /*www.j a v a2 s .c o m*/ * @param numberOfMonitoringEntries The number of monitoring entries * @return The group manager summary data */ private LRUCache<Long, GroupManagerSummaryInformation> getGroupManagerSummaryData( int numberOfMonitoringEntries) { Guard.check(numberOfMonitoringEntries); LRUCache<Long, GroupManagerSummaryInformation> result = new LRUCache<Long, GroupManagerSummaryInformation>( numberOfMonitoringEntries); // Indeed we want the n most recent values -> Reverse the list List<GroupManagerSummaryInformation> reverseList = Lists.reverse(Lists.newArrayList(summary_.values())); for (GroupManagerSummaryInformation summaryInformation : reverseList) { GroupManagerSummaryInformation copiedEntity = new GroupManagerSummaryInformation(summaryInformation); if (result.size() == numberOfMonitoringEntries) { break; } log_.debug(String.format( "Copied group manager summary data. Time: %s, active: %s, and used capacity: %s", copiedEntity.getTimeStamp(), copiedEntity.getActiveCapacity(), copiedEntity.getUsedCapacity())); result.put(copiedEntity.getTimeStamp(), copiedEntity); } return result; }
From source file:us.eharning.atomun.mnemonic.spi.electrum.v2.MnemonicUnitSpiImpl.java
/** * Convert a sequence of mnemonic word into a byte array for validation and usage. * * @param dictionary/* ww w .ja v a 2s. co m*/ * instance to check for the presence of all words. * @param mnemonicWordList * sequence of mnemonic words to map against a dictionary for bit values. * * @return sequence of bytes based on word list. */ @Nonnull private static byte[] mnemonicToBytesWithMultiplication(@Nonnull BidirectionalDictionary dictionary, @Nonnull List<String> mnemonicWordList) { Converter<String, Integer> reverseConverter = dictionary.reverse(); BigInteger total = BigInteger.ZERO; BigInteger multiplier = BigInteger.valueOf(dictionary.getSize()); for (String word : Lists.reverse(mnemonicWordList)) { /* Find the word index in the wordList. */ /* Warning suppressed due to word guaranteed non-null */ //noinspection ConstantConditions int index = reverseConverter.convert(word); total = total.multiply(multiplier).add(BigInteger.valueOf(index)); } /* Convert the resultant value to an unsigned byte-array */ byte[] result = total.toByteArray(); if (result[0] == 0) { byte[] tmp = new byte[result.length - 1]; System.arraycopy(result, 1, tmp, 0, tmp.length); result = tmp; } return result; }
From source file:com.sixt.service.framework.servicetest.eventing.ServiceTestEventHandler.java
@SuppressWarnings("unchecked") public <T> T getEvent(String eventName, Class eventClass, Predicate<T> predicate, long timeout) { long start = System.currentTimeMillis(); while (System.currentTimeMillis() - start < timeout) { //the reversing is for starting with the newest events List<T> events = Lists.reverse(getEventsOfType(eventName, eventClass)); for (T event : events) { if (predicate.test(event)) { return event; }//from w ww . j a v a 2s . co m } new Sleeper().sleepNoException(10); } logger.error("The event {} is not found after {} ms", eventName, timeout); return null; }
From source file:org.auraframework.impl.css.parser.plugin.FlavorExtendsPlugin.java
@Rework public void doReplacements(Stylesheet stylesheet) throws StyleParserException { // first check that we don't have any extension hierarchies going on for (String extended : extensions.values()) { if (extensions.containsKey(extended)) { throw new StyleParserException(String.format(HIERARCHY, extended, extended), null); }// w w w. j a va 2 s .com } // now do the magic for (Entry<String, String> entry : Lists.reverse(Lists.newArrayList(extensions.entrySet()))) { String extension = entry.getKey(); String extended = entry.getValue(); for (Selector selector : selectors.get(extended)) { // create a copy of the extended selector, changing flavored class names to the extension instead Selector copy = new Selector(); for (SelectorPart part : selector.parts()) { boolean replaced = false; if (part instanceof ClassSelector) { // check if it is a flavored selector that we need to rename ClassSelector cs = (ClassSelector) part; Optional<String> flavor = FlavorPluginUtil.extractFlavor(cs, componentClass); if (flavor.isPresent() && flavor.get().equals(extended)) { // rename the flavor String renamed = cs.name().replaceFirst(flavor.get(), extension); copy.append(new ClassSelector(renamed)); replaced = true; } } if (!replaced) { copy.append(part.copy()); // maybe it makes sense to append same ref? so updates are reflected? } } selector.append(copy); } } }
From source file:co.paralleluniverse.strands.queues.SingleConsumerLinkedArrayQueue.java
@Override public List<E> snapshot() { final int blockSize = blockSize(); ArrayList<E> list = new ArrayList<E>(); for (Node p = tail; p != null; p = p.prev) { for (int i = (p == head ? headIndex : 0); i < blockSize; i++) { if (p == tail && !hasValue(p, i)) break; if (hasValue(p, i) && !isDeleted(p, i)) list.add(value(p, i));//from w w w. j ava 2 s .c o m } } return Lists.reverse(list); }
From source file:org.jetbrains.jet.lang.resolve.lazy.LazyImportScope.java
public static LazyImportScope createImportScopeForFile(@NotNull ResolveSession resolveSession, @NotNull PackageViewDescriptor packageDescriptor, @NotNull JetFile jetFile, @NotNull BindingTrace traceForImportResolve, @NotNull String debugName) { return new LazyImportScope(resolveSession, packageDescriptor, Lists.reverse(jetFile.getImportDirectives()), traceForImportResolve, debugName, packageDescriptor.getFqName().isRoot()); }
From source file:com.axelor.db.JpaFixture.java
@Transactional public void load(String fixture) { final InputStream stream = read(fixture); final Map<Node, Object> objects = Maps.newLinkedHashMap(); if (stream == null) { throw new IllegalArgumentException("No such fixture found: " + fixture); }//from w w w . ja v a2s.c o m final Constructor ctor = new Constructor() { { yamlClassConstructors.put(NodeId.scalar, new TimeStampConstruct()); } class TimeStampConstruct extends Constructor.ConstructScalar { Construct dateConstructor = yamlConstructors.get(Tag.TIMESTAMP); @Override public Object construct(Node nnode) { if (nnode.getTag().equals(Tag.TIMESTAMP)) { Date date = (Date) dateConstructor.construct(nnode); if (nnode.getType() == LocalDate.class) { return new LocalDate(date, DateTimeZone.UTC); } if (nnode.getType() == LocalDateTime.class) { return new LocalDateTime(date, DateTimeZone.UTC); } return new DateTime(date, DateTimeZone.UTC); } else { return super.construct(nnode); } } } @Override protected Object constructObject(Node node) { Object obj = super.constructObject(node); if (objects.containsKey(node)) { return objects.get(node); } if (obj instanceof Model) { objects.put(node, obj); return obj; } return obj; } }; for (Class<?> klass : JPA.models()) { ctor.addTypeDescription(new TypeDescription(klass, "!" + klass.getSimpleName() + ":")); } Yaml data = new Yaml(ctor); data.load(stream); for (Object item : Lists.reverse(Lists.newArrayList(objects.values()))) { try { JPA.manage((Model) item); } catch (Exception e) { } } }
From source file:org.sonar.java.cfg.LiveVariables.java
private void processBlockElements(CFG.Block block, Set<Symbol> blockKill, Set<Symbol> blockGen) { // process elements from bottom to top Set<Tree> assignmentLHS = new HashSet<>(); for (Tree element : Lists.reverse(block.elements())) { switch (element.kind()) { case ASSIGNMENT: processAssignment((AssignmentExpressionTree) element, blockKill, blockGen, assignmentLHS); break; case IDENTIFIER: processIdentifier((IdentifierTree) element, blockGen, assignmentLHS); break; case MEMBER_SELECT: processMemberSelect((MemberSelectExpressionTree) element, assignmentLHS, blockGen); break; case VARIABLE: blockKill.add(((VariableTree) element).symbol()); blockGen.remove(((VariableTree) element).symbol()); break; case LAMBDA_EXPRESSION: blockGen.addAll(getUsedVariables(((LambdaExpressionTree) element).body(), cfg.methodSymbol())); break; case METHOD_REFERENCE: blockGen.addAll(getUsedVariables(((MethodReferenceTree) element).expression(), cfg.methodSymbol())); break; case NEW_CLASS: blockGen.addAll(getUsedVariables(((NewClassTree) element).classBody(), cfg.methodSymbol())); break; default:/* w w w .java 2s . c o m*/ // Ignore other kind of elements, no change of gen/kill } } }
From source file:org.jetbrains.kotlin.resolve.lazy.ScopeProvider.java
private JetScope createScopeWithDefaultImports() { PackageViewDescriptor rootPackage = resolveSession.getModuleDescriptor().getPackage(FqName.ROOT); if (rootPackage == null) { throw new IllegalStateException("Root package not found"); }/*from w ww . j a va 2 s.c o m*/ JetImportsFactory importsFactory = resolveSession.getJetImportsFactory(); List<ImportPath> defaultImports = resolveSession.getModuleDescriptor().getDefaultImports(); Collection<JetImportDirective> defaultImportDirectives = importsFactory .createImportDirectives(defaultImports); return new LazyImportScope(resolveSession, rootPackage, Lists.reverse(Lists.newArrayList(defaultImportDirectives)), TemporaryBindingTrace .create(resolveSession.getTrace(), "Transient trace for default imports lazy resolve"), "Lazy default imports scope", false); }