@Override
protected final void afterDone() {
super.afterDone();
RunningState localRunningState = runningState;
if (localRunningState != null) {
// Let go of the memory held by the running state
this.runningState = null;
ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures =
localRunningState.futures;
boolean wasInterrupted = wasInterrupted();
if (wasInterrupted()) {
localRunningState.interruptTask();
}
if (isCancelled() & futures != null) {
for (ListenableFuture<?> future : futures) {
future.cancel(wasInterrupted);
}
}
}
}
java类com.google.common.collect.ImmutableCollection的实例源码
AggregateFuture.java 文件源码
项目:guava-mock
阅读 39
收藏 0
点赞 0
评论 0
CShuffleList.java 文件源码
项目:Equella
阅读 38
收藏 0
点赞 0
评论 0
@Override
public void validate()
{
if( checkDuplication || forceUnique )
{
final Set<String> values = new HashSet<String>();
for( NameValue nv : namesValues )
{
// nv.value is URL encoded, but the name is ok to use
values.add(nv.getName());
}
final ImmutableCollection<String> valuesReadonly = ImmutableSet.copyOf(values);
// We need to inform the wizard to check for uniqueness every time,
// no matter what
final boolean isUnique = getRepository().checkDataUniqueness(getFirstTarget().getXoqlPath(),
valuesReadonly, !forceUnique);
setInvalid(forceUnique && !isUnique && !isInvalid(),
new KeyLabel("wizard.controls.editbox.uniqueerror")); //$NON-NLS-1$
}
}
AggregateFuture.java 文件源码
项目:googles-monorepo-demo
阅读 41
收藏 0
点赞 0
评论 0
@Override
protected final void afterDone() {
super.afterDone();
RunningState localRunningState = runningState;
if (localRunningState != null) {
// Let go of the memory held by the running state
this.runningState = null;
ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures =
localRunningState.futures;
boolean wasInterrupted = wasInterrupted();
if (wasInterrupted()) {
localRunningState.interruptTask();
}
if (isCancelled() & futures != null) {
for (ListenableFuture<?> future : futures) {
future.cancel(wasInterrupted);
}
}
}
}
CollectorsTest.java 文件源码
项目:de.flapdoodle.solid
阅读 50
收藏 0
点赞 0
评论 0
@Test
public void immutableMultiMapCollector() {
ImmutableMultimap<Integer, Integer> result = Stream.iterate(0, p -> p+1)
.parallel()
.limit(GENERATED_ITEMS)
.collect(Collectors.groupingBy(i -> i % 10));
assertEquals(GENERATED_ITEMS,result.size());
assertEquals(10,result.asMap().size());
for (int i=0;i<10;i++) {
int key=i;
ImmutableCollection<Integer> values = result.get(key);
values.forEach(v -> {
assertEquals(key,v % 10);
});
}
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 31
收藏 0
点赞 0
评论 0
public boolean removeIf(Predicate<Node> predicate) {
boolean result;
ImmutableCollection<Node> before = getEnduringNodes().values();
this.nodesLock.lock();
try {
result = this.nodes.values().removeIf(predicate);
} finally {
this.nodesLock.unlock();
}
if (!result) {
return false;
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 48
收藏 0
点赞 0
评论 0
/**
* Sets a permission node
*
* @param node the node to set
*/
public DataMutateResult setPermission(Node node) {
if (hasPermission(node, false) != Tristate.UNDEFINED) {
return DataMutateResult.ALREADY_HAS;
}
ImmutableCollection<Node> before = getEnduringNodes().values();
this.nodesLock.lock();
try {
this.nodes.put(node.getFullContexts().makeImmutable(), node);
} finally {
this.nodesLock.unlock();
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeAdd(node, this, before, after);
return DataMutateResult.SUCCESS;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 32
收藏 0
点赞 0
评论 0
/**
* Sets a transient permission node
*
* @param node the node to set
*/
public DataMutateResult setTransientPermission(Node node) {
if (hasPermission(node, true) != Tristate.UNDEFINED) {
return DataMutateResult.ALREADY_HAS;
}
ImmutableCollection<Node> before = getTransientNodes().values();
this.transientNodesLock.lock();
try {
this.transientNodes.put(node.getFullContexts().makeImmutable(), node);
} finally {
this.transientNodesLock.unlock();
}
invalidateCache();
ImmutableCollection<Node> after = getTransientNodes().values();
this.plugin.getEventFactory().handleNodeAdd(node, this, before, after);
return DataMutateResult.SUCCESS;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 39
收藏 0
点赞 0
评论 0
/**
* Unsets a permission node
*
* @param node the node to unset
*/
public DataMutateResult unsetPermission(Node node) {
if (hasPermission(node, false) == Tristate.UNDEFINED) {
return DataMutateResult.LACKS;
}
ImmutableCollection<Node> before = getEnduringNodes().values();
this.nodesLock.lock();
try {
this.nodes.get(node.getFullContexts().makeImmutable()).removeIf(e -> e.almostEquals(node));
} finally {
this.nodesLock.unlock();
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeRemove(node, this, before, after);
return DataMutateResult.SUCCESS;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 34
收藏 0
点赞 0
评论 0
/**
* Unsets a transient permission node
*
* @param node the node to unset
*/
public DataMutateResult unsetTransientPermission(Node node) {
if (hasPermission(node, true) == Tristate.UNDEFINED) {
return DataMutateResult.LACKS;
}
ImmutableCollection<Node> before = getTransientNodes().values();
this.transientNodesLock.lock();
try {
this.transientNodes.get(node.getFullContexts().makeImmutable()).removeIf(e -> e.almostEquals(node));
} finally {
this.transientNodesLock.unlock();
}
invalidateCache();
ImmutableCollection<Node> after = getTransientNodes().values();
this.plugin.getEventFactory().handleNodeRemove(node, this, before, after);
return DataMutateResult.SUCCESS;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 35
收藏 0
点赞 0
评论 0
public boolean clearNodes(ContextSet contextSet) {
ImmutableCollection<Node> before = getEnduringNodes().values();
this.nodesLock.lock();
try {
this.nodes.removeAll(contextSet.makeImmutable());
} finally {
this.nodesLock.unlock();
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
if (before.size() == after.size()) {
return false;
}
this.plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 39
收藏 0
点赞 0
评论 0
public boolean clearParents(boolean giveDefault) {
ImmutableCollection<Node> before = getEnduringNodes().values();
this.nodesLock.lock();
try {
boolean b = this.nodes.values().removeIf(Node::isGroupNode);
if (!b) {
return false;
}
} finally {
this.nodesLock.unlock();
}
if (this.getType().isUser() && giveDefault) {
this.plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 35
收藏 0
点赞 0
评论 0
public boolean clearMeta(MetaType type) {
ImmutableCollection<Node> before = getEnduringNodes().values();
this.nodesLock.lock();
try {
if (!this.nodes.values().removeIf(type::matches)) {
return false;
}
} finally {
this.nodesLock.unlock();
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 35
收藏 0
点赞 0
评论 0
public boolean clearMeta(MetaType type, ContextSet contextSet) {
ImmutableCollection<Node> before = getEnduringNodes().values();
this.nodesLock.lock();
try {
SortedSet<Node> nodes = this.nodes.get(contextSet.makeImmutable());
if (nodes == null) {
return false;
}
boolean b = nodes.removeIf(type::matches);
if (!b) {
return false;
}
} finally {
this.nodesLock.unlock();
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 31
收藏 0
点赞 0
评论 0
public boolean clearMetaKeys(String key, boolean temp) {
ImmutableCollection<Node> before = getEnduringNodes().values();
this.nodesLock.lock();
try {
boolean b = this.nodes.values().removeIf(n -> n.isMeta() && (n.isTemporary() == temp) && n.getMeta().getKey().equalsIgnoreCase(key));
if (!b) {
return false;
}
} finally {
this.nodesLock.unlock();
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
PermissionHolder.java 文件源码
项目:LuckPerms
阅读 42
收藏 0
点赞 0
评论 0
public boolean clearMetaKeys(String key, ContextSet contextSet, boolean temp) {
ImmutableCollection<Node> before = getEnduringNodes().values();
this.nodesLock.lock();
try {
SortedSet<Node> nodes = this.nodes.get(contextSet.makeImmutable());
if (nodes == null) {
return false;
}
boolean b = nodes.removeIf(n -> n.isMeta() && (n.isTemporary() == temp) && n.getMeta().getKey().equalsIgnoreCase(key));
if (!b) {
return false;
}
} finally {
this.nodesLock.unlock();
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
InsertQueryImpl.java 文件源码
项目:grakn
阅读 41
收藏 0
点赞 0
评论 0
/**
* At least one of {@code tx} and {@code match} must be absent.
*
* @param vars a collection of Vars to insert
* @param match the {@link Match} to insert for each result
* @param tx the graph to execute on
*/
InsertQueryImpl(ImmutableCollection<VarPatternAdmin> vars, Optional<MatchAdmin> match, Optional<GraknTx> tx) {
// match and graph should never both be present (should get graph from inner match)
assert(!match.isPresent() || !tx.isPresent());
if (vars.isEmpty()) {
throw GraqlQueryException.noPatterns();
}
this.match = match;
this.tx = tx;
this.originalVars = vars;
// Get all variables, including ones nested in other variables
this.vars = vars.stream().flatMap(v -> v.innerVarPatterns().stream()).collect(toImmutableList());
for (VarPatternAdmin var : this.vars) {
var.getProperties().forEach(property -> ((VarPropertyInternal) property).checkInsertable(var));
}
}
BlazeConfigurationResolverResult.java 文件源码
项目:intellij
阅读 44
收藏 0
点赞 0
评论 0
@Nullable
OCResolveConfiguration getConfigurationForFile(VirtualFile sourceFile) {
SourceToTargetMap sourceToTargetMap = SourceToTargetMap.getInstance(project);
ImmutableCollection<TargetKey> targetsForSourceFile =
sourceToTargetMap.getRulesForSourceFile(VfsUtilCore.virtualToIoFile(sourceFile));
if (targetsForSourceFile.isEmpty()) {
return null;
}
// If a source file is in two different targets, we can't possibly show how it will be
// interpreted in both contexts at the same time in the IDE, so just pick the "first" target.
TargetKey targetKey = targetsForSourceFile.stream().min(TargetKey::compareTo).orElse(null);
Preconditions.checkNotNull(targetKey);
return configurationMap.get(targetKey);
}
BlazeAndroidModelTest.java 文件源码
项目:intellij
阅读 41
收藏 0
点赞 0
评论 0
MockJavaPsiFacade(
Project project, PsiManager psiManager, ImmutableCollection<String> classNames) {
super(project, psiManager, null, null);
ImmutableMap.Builder<String, PsiClass> classesBuilder = ImmutableMap.builder();
ImmutableMap.Builder<String, Long> timestampsBuilder = ImmutableMap.builder();
for (String className : classNames) {
VirtualFile virtualFile =
new MockVirtualFile("/src/" + className.replace('.', '/') + ".java");
PsiFile psiFile = mock(PsiFile.class);
when(psiFile.getVirtualFile()).thenReturn(virtualFile);
PsiClass psiClass = mock(PsiClass.class);
when(psiClass.getContainingFile()).thenReturn(psiFile);
classesBuilder.put(className, psiClass);
timestampsBuilder.put(className, virtualFile.getTimeStamp());
}
classes = classesBuilder.build();
timestamps = timestampsBuilder.build();
}
AggregateFuture.java 文件源码
项目:codebuff
阅读 42
收藏 0
点赞 0
评论 0
@CanIgnoreReturnValue
@Override
public final boolean cancel(boolean mayInterruptIfRunning) {
// Must get a reference to the futures before we cancel, as they'll be cleared out.
RunningState localRunningState = runningState;
ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures = (localRunningState != null) ? localRunningState.futures : null;
// Cancel all the component futures.
boolean cancelled = super.cancel(mayInterruptIfRunning);
// & is faster than the branch required for &&
if (cancelled & futures != null) {
for (ListenableFuture<?> future : futures) {
future.cancel(mayInterruptIfRunning);
}
}
return cancelled;
}
ImportRoots.java 文件源码
项目:intellij
阅读 31
收藏 0
点赞 0
评论 0
public ImportRoots build() {
ImmutableCollection<WorkspacePath> rootDirectories = rootDirectoriesBuilder.build();
// for bazel projects, if we're including the workspace root,
// we force-exclude the bazel artifact directories
// (e.g. bazel-bin, bazel-genfiles).
if (buildSystem == BuildSystem.Bazel && hasWorkspaceRoot(rootDirectories)) {
excludeBuildSystemArtifacts();
}
ImmutableSet<WorkspacePath> minimalExcludes =
WorkspacePathUtil.calculateMinimalWorkspacePaths(excludeDirectoriesBuilder.build());
// Remove any duplicates, overlapping, or excluded directories
ImmutableSet<WorkspacePath> minimalRootDirectories =
WorkspacePathUtil.calculateMinimalWorkspacePaths(rootDirectories, minimalExcludes);
return new ImportRoots(minimalRootDirectories, minimalExcludes);
}
AggregateFuture.java 文件源码
项目:codebuff
阅读 35
收藏 0
点赞 0
评论 0
@CanIgnoreReturnValue
@Override
public final boolean cancel(boolean mayInterruptIfRunning) {
// Must get a reference to the futures before we cancel, as they'll be cleared out.
RunningState localRunningState = runningState;
ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures = (localRunningState != null) ? localRunningState.futures : null;
// Cancel all the component futures.
boolean cancelled = super.cancel(mayInterruptIfRunning);
// & is faster than the branch required for &&
if (cancelled & futures != null) {
for (ListenableFuture<?> future : futures) {
future.cancel(mayInterruptIfRunning);
}
}
return cancelled;
}
AggregateFuture.java 文件源码
项目:codebuff
阅读 42
收藏 0
点赞 0
评论 0
@CanIgnoreReturnValue
@Override
public final boolean cancel(boolean mayInterruptIfRunning) {
// Must get a reference to the futures before we cancel, as they'll be cleared out.
RunningState localRunningState = runningState;
ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures = (localRunningState != null) ? localRunningState.futures : null;
// Cancel all the component futures.
boolean cancelled = super.cancel(mayInterruptIfRunning);
// & is faster than the branch required for &&
if (cancelled & futures != null) {
for (ListenableFuture<?> future : futures) {
future.cancel(mayInterruptIfRunning);
}
}
return cancelled;
}
RestoreOriginalAuthor.java 文件源码
项目:copybara
阅读 37
收藏 0
点赞 0
评论 0
@Override
public void transform(TransformWork work)
throws IOException, ValidationException {
Author author = null;
// If multiple commits are included (for example on a squash for skipping a bad change),
// last author wins.
for (Change<?> change : work.getChanges().getCurrent()) {
ImmutableCollection<String> labelValue = change.getLabels().get(label);
if (!labelValue.isEmpty()) {
try {
author = Author.parse(/*location=*/null, Iterables.getLast(labelValue));
} catch (EvalException e) {
// Don't fail the migration because the label is wrong since it is very
// difficult for a user to recover from this.
work.getConsole().warn("Cannot restore original author: " + e.getMessage());
}
}
if (!searchAllChanges) {
break;
}
}
if (author != null) {
work.setAuthor(author);
work.removeLabel(label, /*wholeMessage=*/true);
}
}
ChangeVisitable.java 文件源码
项目:copybara
阅读 41
收藏 0
点赞 0
评论 0
/**
* Visit only changes that contain any of the labels in {@code labels}.
*/
default void visitChangesWithAnyLabel(
R start, ImmutableCollection<String> labels, ChangesLabelVisitor visitor)
throws RepoException, ValidationException {
visitChanges(start, input -> {
// We could return all the label values, but this is really only used for
// RevId like ones and last is good enough for now.
Map<String, String> copy = Maps.newHashMap(Maps.transformValues(input.getLabels().asMap(),
Iterables::getLast));
copy.keySet().retainAll(labels);
if (copy.isEmpty()) {
return VisitResult.CONTINUE;
}
return visitor.visit(input, ImmutableMap.copyOf(copy));
});
}
IcannReportingStager.java 文件源码
项目:nomulus
阅读 31
收藏 0
点赞 0
评论 0
/** Creates and stores activity reports on GCS, returns a list of files stored. */
private ImmutableList<String> stageActivityReports(
String headerRow, ImmutableCollection<Map<TableFieldSchema, Object>> rows)
throws IOException {
ImmutableList.Builder<String> manifestBuilder = new ImmutableList.Builder<>();
// Create a report csv for each tld from query table, and upload to GCS
for (Map<TableFieldSchema, Object> row : rows) {
// Get the tld (first cell in each row)
String tld = row.values().iterator().next().toString();
if (isNullOrEmpty(tld)) {
throw new RuntimeException("Found an empty row in the activity report table!");
}
ImmutableList<String> rowStrings = ImmutableList.of(constructRow(row.values()));
// Create and upload the activity report with a single row
manifestBuilder.add(
saveReportToGcs(tld, createReport(headerRow, rowStrings), ReportType.ACTIVITY));
}
return manifestBuilder.build();
}
ModifiablesTest.java 文件源码
项目:GitHub
阅读 51
收藏 0
点赞 0
评论 0
@Test
@SuppressWarnings("deprecation")
public void modifiableImmutableCollections() {
ModifiableMutableImmutableCollection m = ModifiableMutableImmutableCollection.create();
m.addA("a");
m.addA("b", "c");
m.addB("d", "e");
m.putC("x", 1);
m.putC("y", 2);
check(m.a()).isA(ImmutableCollection.class);
check(m.b()).isA(ImmutableCollection.class);
check(m.c()).isA(ImmutableMultimap.class);
check(m.d()).isA(ImmutableMap.class);
check(m.a()).isOf("a", "b", "c");
check(m.b()).isOf("d", "e");
check(m.c().values()).isOf(1, 2);
check(m.c().keySet()).isOf("x", "y");
check(m.d().isEmpty());
m.clear();
check(m.a()).isEmpty();
check(m.b()).isEmpty();
check(m.c().entries()).isEmpty();
check(m.d().entrySet()).isEmpty();
}
AggregateFuture.java 文件源码
项目:guava-mock
阅读 30
收藏 0
点赞 0
评论 0
RunningState(
ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures,
boolean allMustSucceed,
boolean collectsValues) {
super(futures.size());
this.futures = checkNotNull(futures);
this.allMustSucceed = allMustSucceed;
this.collectsValues = collectsValues;
}
CollectionFuture.java 文件源码
项目:guava-mock
阅读 35
收藏 0
点赞 0
评论 0
CollectionFutureRunningState(
ImmutableCollection<? extends ListenableFuture<? extends V>> futures,
boolean allMustSucceed) {
super(futures, allMustSucceed, true);
this.values =
futures.isEmpty()
? ImmutableList.<Optional<V>>of()
: Lists.<Optional<V>>newArrayListWithCapacity(futures.size());
// Populate the results list with null initially.
for (int i = 0; i < futures.size(); ++i) {
values.add(null);
}
}
CombinedFuture.java 文件源码
项目:guava-mock
阅读 41
收藏 0
点赞 0
评论 0
CombinedFuture(
ImmutableCollection<? extends ListenableFuture<?>> futures,
boolean allMustSucceed,
Executor listenerExecutor,
AsyncCallable<V> callable) {
init(
new CombinedFutureRunningState(
futures,
allMustSucceed,
new AsyncCallableInterruptibleTask(callable, listenerExecutor)));
}
CombinedFuture.java 文件源码
项目:guava-mock
阅读 30
收藏 0
点赞 0
评论 0
CombinedFuture(
ImmutableCollection<? extends ListenableFuture<?>> futures,
boolean allMustSucceed,
Executor listenerExecutor,
Callable<V> callable) {
init(
new CombinedFutureRunningState(
futures, allMustSucceed, new CallableInterruptibleTask(callable, listenerExecutor)));
}