下面列出了com.google.common.collect.Lists#reverse ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void addSecurityRules ( final Rules rules, final IProgressMonitor monitor )
{
if ( rules == null )
{
return;
}
int priority = 1000;
monitor.beginTask ( "Encoding security rules", rules.getRules ().size () );
for ( final Rule rule : Lists.reverse ( rules.getRules () ) )
{
final RuleEncoder encoder = RuleEncoder.findEncoder ( rule );
if ( encoder != null )
{
encoder.encodeRule ( this.ctx, priority += 100 );
}
monitor.worked ( 1 );
}
monitor.done ();
}
@Test
public void testGetSecurityRoleFunctionKeys()
{
// Create a list of security role to function mapping keys.
final List<SecurityRoleFunctionKey> securityRoleFunctionKeys = ImmutableList
.of(new SecurityRoleFunctionKey(SECURITY_ROLE, SECURITY_FUNCTION), new SecurityRoleFunctionKey(SECURITY_ROLE, SECURITY_FUNCTION_2),
new SecurityRoleFunctionKey(SECURITY_ROLE_2, SECURITY_FUNCTION), new SecurityRoleFunctionKey(SECURITY_ROLE_2, SECURITY_FUNCTION_2));
// Create and persist security role to function mapping entities in reverse order.
for (SecurityRoleFunctionKey securityRoleFunctionKey : Lists.reverse(securityRoleFunctionKeys))
{
securityRoleFunctionDaoTestHelper.createSecurityRoleFunctionEntity(securityRoleFunctionKey);
}
// Get a list of keys for all security role to function mappings registered in the system.
assertEquals(securityRoleFunctionKeys, securityRoleFunctionDao.getSecurityRoleFunctionKeys());
}
/**
* Gets the {@linkplain Path#toRealPath(LinkOption...) real path} to the file located by the given
* path.
*/
public JimfsPath toRealPath(
JimfsPath path, PathService pathService, Set<? super LinkOption> options) throws IOException {
checkNotNull(path);
checkNotNull(options);
store.readLock().lock();
try {
DirectoryEntry entry = lookUp(path, options).requireExists(path);
List<Name> names = new ArrayList<>();
names.add(entry.name());
while (!entry.file().isRootDirectory()) {
entry = entry.directory().entryInParent();
names.add(entry.name());
}
// names are ordered last to first in the list, so get the reverse view
List<Name> reversed = Lists.reverse(names);
Name root = reversed.remove(0);
return pathService.createPath(root, reversed);
} finally {
store.readLock().unlock();
}
}
private List<String> resolveProductParts(String path) {
// To speedup the lookup, we try to find the longest possible category path
// Example for path: /var/commerce/products/cloudcommerce/Men/Coats/meskwielt.1-s
// Remove root (/var/commerce/products/cloudcommerce) then try to find category /Men/Coats
// --> we find the category /Men/Coats and try to fetch the product meskwielt.1-s
// Example for path: /var/commerce/products/cloudcommerce/Men/Coats/meskwielt.1-s/meskwielt.2-l
// Remove root (/var/commerce/products/cloudcommerce) then try to find category /Men/Coats/meskwielt.1-s
// --> that category is not found, so we try to find the category /Men/Coats
// --> we find the category /Men/Coats and try to fetch the product meskwielt.1-s and variant meskwielt.2-l
String subPath = path.substring(root.length() + 1);
int backtrackCounter = 0;
List<String> productParts = new ArrayList<>();
String[] parts = subPath.split("/");
for (String part : Lists.reverse(Arrays.asList(parts))) {
productParts.add(part);
backtrackCounter -= part.length() + 1;
String categorySubPath = StringUtils.substring(subPath, 0, backtrackCounter);
if (graphqlDataService.getCategoryByPath(categorySubPath, storeView) != null) {
break;
}
}
productParts = Lists.reverse(productParts);
return productParts;
}
public static QualifiedObjectName createQualifiedObjectName(Session session, Node node, QualifiedName name)
{
requireNonNull(session, "session is null");
requireNonNull(name, "name is null");
if (name.getParts().size() > 3) {
throw new PrestoException(SYNTAX_ERROR, format("Too many dots in table name: %s", name));
}
List<String> parts = Lists.reverse(name.getParts());
String objectName = parts.get(0);
String schemaName = (parts.size() > 1) ? parts.get(1) : session.getSchema().orElseThrow(() ->
semanticException(MISSING_SCHEMA_NAME, node, "Schema must be specified when session schema is not set"));
String catalogName = (parts.size() > 2) ? parts.get(2) : session.getCatalog().orElseThrow(() ->
semanticException(MISSING_CATALOG_NAME, node, "Catalog must be specified when session catalog is not set"));
return new QualifiedObjectName(catalogName, schemaName, objectName);
}
/**
* Post-processes the blocks, coming from
* {@link #doGetBlocks(int, BlockFilteringOption, Long, BlockTimeOption)}:
* 1. Turns them in ascending order by height.
* 2. Keeps only blocks that fall in range [fromHeight; toHeight].
*/
private static BlocksRange postProcessResponseBlocks(long fromHeight, long toHeight,
List<Block> blocks) {
// Turn the blocks in ascending order
blocks = Lists.reverse(blocks);
// Filter the possible blocks that are out of the requested range
// No Stream#dropWhile in Java 8 :(
int firstInRange = indexOf(blocks, b -> b.getHeight() >= fromHeight)
.orElse(blocks.size());
blocks = blocks.subList(firstInRange, blocks.size());
// Do not bother trimming — BlocksRange copies the list
return new BlocksRange(fromHeight, toHeight, blocks);
}
/**
* @return number of times the given test should run. If the test doesn't match any of the
* filters, runs it once.
*/
public int getRunsPerTestForLabel(Label label) {
for (PerLabelOptions perLabelRuns : Lists.reverse(options.runsPerTest)) {
if (perLabelRuns.isIncluded(label)) {
return Integer.parseInt(Iterables.getOnlyElement(perLabelRuns.getOptions()));
}
}
return 1;
}
public List<PhysicalOperator> getSortedOperators(boolean reverse){
List<PhysicalOperator> list = GraphAlgos.TopoSorter.sort(graph);
if(reverse){
return Lists.reverse(list);
}else{
return list;
}
}
@Override
public void stop() throws Exception {
for (Managed managed : Lists.reverse(_managed)) {
managed.stop();
}
_managed.clear();
}
/**
* Register model scheme. If model class extends other classes, superclasses will be processed first
* (bottom to top). On each class from hierarchy extensions are searched and applied. Processed classes are
* cashed to avoid multiple processing of the same base model class.
*
* @param model model class
*/
public void register(final Class<?> model) {
final ODatabaseObject db = dbProvider.get();
// auto create schema for new classes
((OObjectDatabaseTx) db).setAutomaticSchemaGeneration(true);
// processing lower hierarchy types first
try {
for (Class<?> type : Lists.reverse(SchemeUtils.resolveHierarchy(model))) {
processType(db, type);
}
} catch (Throwable th) {
throw new SchemeInitializationException("Failed to register model class " + model.getName(), th);
}
}
private void close(final ArgNode<XtaState<S>, XtaAction> coveree) {
stats.startClosing();
final Iterable<ArgNode<XtaState<S>, XtaAction>> candidates = Lists.reverse(passed.get(coveree));
for (final ArgNode<XtaState<S>, XtaAction> coverer : candidates) {
stats.checkCoverage();
if (algorithmStrategy.mightCover(coveree, coverer)) {
stats.attemptCoverage();
coveree.setCoveringNode(coverer);
final Collection<ArgNode<XtaState<S>, XtaAction>> uncoveredNodes = new ArrayList<>();
algorithmStrategy.cover(coveree, coverer, uncoveredNodes, stats);
waiting.addAll(uncoveredNodes.stream().filter(n -> !n.equals(coveree)));
if (coveree.isCovered()) {
stats.successfulCoverage();
stats.stopClosing();
return;
}
}
}
stats.stopClosing();
}
public T getLatest(Matcher<? super T> matcher) {
synchronized (messageLog) {
for (T element : Lists.reverse(messageLog)) {
if (matcher.matches(element)) {
return element;
}
}
}
return null;
}
/**
* Iterate using Guava {@link Lists} API.
*
* @param list the list
*/
public void iterateUsingGuava(final List<String> list) {
final List<String> reversedList = Lists.reverse(list);
for (final String item : reversedList) {
System.out.println(item);
}
}
private static List<Anchor> getPath(Anchor source, Anchor target, Map<Anchor, Anchor> prev) {
final List<Anchor> out = new ArrayList<>();
Anchor it = target;
if (prev.containsKey(it) || it == source) {
while (it != null) {
out.add(it); // supposed to add to the beginning of the list but returning a reverse view will have the same effect
it = prev.get(it);
}
}
return Lists.reverse(out);
}
private List<WorkWrapper> createWorkList(List<T> completeWorkList) {
List<WorkWrapper> workList = new ArrayList<>();
for (T work : completeWorkList) {
workList.add(new WorkWrapper(work));
}
Collections.sort(workList);
// we want largest work units first in the list
return Lists.reverse(workList);
}
static MessageId findFirstLedgerWithinThreshold(List<PersistentTopicInternalStats.LedgerInfo> ledgers,
long sizeThreshold) {
long suffixSize = 0L;
ledgers = Lists.reverse(ledgers);
long previousLedger = ledgers.get(0).ledgerId;
for (PersistentTopicInternalStats.LedgerInfo l : ledgers) {
suffixSize += l.size;
if (suffixSize > sizeThreshold) {
return new MessageIdImpl(previousLedger, 0L, -1);
}
previousLedger = l.ledgerId;
}
return null;
}
public void close() {
List<OperatorImpl> initializationOrder = new ArrayList<>(operatorImpls.values());
List<OperatorImpl> finalizationOrder = Lists.reverse(initializationOrder);
finalizationOrder.forEach(OperatorImpl::close);
}
public static <T> List<T> reverseIfNecessary(List<T> list, boolean reverse) {
if (!reverse) {
return list;
}
return Lists.reverse(list);
}
List<String> getBranch(FlowNode flowNode) {
return Lists.reverse(flowNode.getAllEnclosingIds());
}
@Override
public void applyMigration() {
final long start = System.currentTimeMillis();
final List<SingularityTaskId> taskIds = taskManager.getActiveTaskIds();
for (SingularityTaskId taskId : taskIds) {
List<SingularityTaskHistoryUpdate> updates = Lists.reverse(
taskManager.getTaskHistoryUpdates(taskId)
);
Optional<MesosTaskStatusObject> taskStatus = Optional.empty();
for (SingularityTaskHistoryUpdate update : updates) {
if (update.getTaskState().toTaskState().isPresent()) {
Optional<SingularityTask> task = taskManager.getTask(taskId);
taskStatus =
Optional.of(
mesosProtosUtils.taskStatusFromProtos(
TaskStatus
.newBuilder()
.setTaskId(TaskID.newBuilder().setValue(taskId.getId()))
.setAgentId(MesosProtosUtils.toAgentId(task.get().getAgentId()))
.setState(MesosProtosUtils.toTaskState(update.getTaskState()))
.build()
)
);
break;
}
}
SingularityTaskStatusHolder taskStatusHolder = new SingularityTaskStatusHolder(
taskId,
taskStatus,
start,
serverId,
Optional.empty()
);
taskManager.saveLastActiveTaskStatus(taskStatusHolder);
}
}