com.google.common.collect.ImmutableCollection#size ( )源码实例Demo

下面列出了com.google.common.collect.ImmutableCollection#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: LuckPerms   文件: AbstractUserManager.java
/**
 * Check whether the user's state indicates that they should be persisted to storage.
 *
 * @param user the user to check
 * @return true if the user should be saved
 */
@Override
public boolean shouldSave(User user) {
    ImmutableCollection<Node> nodes = user.normalData().immutable().values();
    if (nodes.size() != 1) {
        return true;
    }

    Node onlyNode = nodes.iterator().next();
    if (!(onlyNode instanceof InheritanceNode)) {
        return true;
    }

    if (onlyNode.hasExpiry() || !onlyNode.getContexts().isEmpty()) {
        return true;
    }

    if (!((InheritanceNode) onlyNode).getGroupName().equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME)) {
        // The user's only node is not the default group one.
        return true;
    }


    // Not in the default primary group
    return !user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME);
}
 
源代码2 项目: LuckPerms   文件: PermissionHolder.java
public boolean clearNodes(DataType dataType, ContextSet contextSet, boolean giveDefault) {
    NodeMap data = getData(dataType);
    ImmutableCollection<? extends Node> before = data.immutable().values();

    if (contextSet == null) {
        data.clear();
    } else {
        data.clear(contextSet);
    }

    if (getType() == HolderType.USER && giveDefault) {
        getPlugin().getUserManager().giveDefaultIfNeeded((User) this, false);
    }

    invalidateCache();

    ImmutableCollection<? extends Node> after = data.immutable().values();

    if (before.size() == after.size()) {
        return false;
    }

    this.plugin.getEventDispatcher().dispatchNodeClear(this, dataType, before, after);
    return true;
}
 
源代码3 项目: buck   文件: IjSourceRootSimplifier.java
/**
 * Tries to find the best folder type to create using the types of the children.
 *
 * <p>The best type in this algorithm is the type with the maximum number of children.
 */
private FolderTypeWithPackageInfo findBestFolderType(ImmutableCollection<IjFolder> children) {
  if (children.size() == 1) {
    return FolderTypeWithPackageInfo.fromFolder(children.iterator().next());
  }

  return children.stream()
      .collect(
          Collectors.groupingBy(FolderTypeWithPackageInfo::fromFolder, Collectors.counting()))
      .entrySet()
      .stream()
      .max(
          (c1, c2) -> {
            long count1 = c1.getValue();
            long count2 = c2.getValue();
            if (count1 == count2) {
              return c2.getKey().ordinal() - c1.getKey().ordinal();
            } else {
              return (int) (count1 - count2);
            }
          })
      .orElseThrow(() -> new IllegalStateException("Max count should exist"))
      .getKey();
}
 
源代码4 项目: codebuff   文件: CollectionFuture.java
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);
  }
}
 
源代码5 项目: codebuff   文件: CollectionFuture.java
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);
  }
}
 
源代码6 项目: codebuff   文件: CollectionFuture.java
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);
  }
}
 
源代码7 项目: codebuff   文件: CollectionFuture.java
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);
  }
}
 
源代码8 项目: codebuff   文件: AggregateFuture.java
RunningState(
    ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures,
    boolean allMustSucceed,
    boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
源代码9 项目: codebuff   文件: CollectionFuture.java
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);
  }
}
 
源代码10 项目: vespa   文件: SearchCluster.java
private static Optional<Node> findLocalCorpusDispatchTarget(String selfHostname,
                                                            int searchClusterSize,
                                                            int containerClusterSize,
                                                            ImmutableMultimap<String, Node> nodesByHost,
                                                            ImmutableMap<Integer, Group> groups) {
    // A search node in the search cluster in question is configured on the same host as the currently running container.
    // It has all the data <==> No other nodes in the search cluster have the same group id as this node.
    //         That local search node responds.
    // The search cluster to be searched has at least as many nodes as the container cluster we're running in.
    ImmutableCollection<Node> localSearchNodes = nodesByHost.get(selfHostname);
    // Only use direct dispatch if we have exactly 1 search node on the same machine:
    if (localSearchNodes.size() != 1) return Optional.empty();

    Node localSearchNode = localSearchNodes.iterator().next();
    Group localSearchGroup = groups.get(localSearchNode.group());

    // Only use direct dispatch if the local search node has the entire corpus
    if (localSearchGroup.nodes().size() != 1) return Optional.empty();

    // Only use direct dispatch if this container cluster has at least as many nodes as the search cluster
    // to avoid load skew/preserve fanout in the case where a subset of the search nodes are also containers.
    // This disregards the case where the search and container clusters are partially overlapping.
    // Such configurations produce skewed load in any case.
    if (containerClusterSize < searchClusterSize) return Optional.empty();

    return Optional.of(localSearchNode);
}
 
源代码11 项目: james-project   文件: DlpDomainRules.java
private boolean containsDuplicateIds(ImmutableCollection<Rule> rules) {
    long distinctIdCount = rules.stream()
        .map(Rule::id)
        .distinct()
        .count();
    return distinctIdCount != rules.size();
}
 
源代码12 项目: codebuff   文件: AggregateFuture.java
RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
源代码13 项目: codebuff   文件: AggregateFuture.java
RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
源代码14 项目: codebuff   文件: AggregateFuture.java
RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
源代码15 项目: codebuff   文件: AggregateFuture.java
RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
源代码16 项目: codebuff   文件: ServiceManager.java
/**
 * It is implicitly assumed that all the services are NEW and that they will all remain NEW
 * until all the Listeners are installed and {@link #markReady()} is called. It is our caller's
 * responsibility to only call {@link #markReady()} if all services were new at the time this
 * method was called and when all the listeners were installed.
 */

ServiceManagerState(ImmutableCollection<Service> services) {
  this.numberOfServices = services.size();
  servicesByState.putAll(NEW, services);
}
 
源代码17 项目: codebuff   文件: ServiceManager.java
/**
 * It is implicitly assumed that all the services are NEW and that they will all remain NEW
 * until all the Listeners are installed and {@link #markReady()} is called. It is our caller's
 * responsibility to only call {@link #markReady()} if all services were new at the time this
 * method was called and when all the listeners were installed.
 */

ServiceManagerState(ImmutableCollection<Service> services) {
  this.numberOfServices = services.size();
  servicesByState.putAll(NEW, services);
}
 
源代码18 项目: codebuff   文件: ServiceManager.java
/**
 * It is implicitly assumed that all the services are NEW and that they will all remain NEW
 * until all the Listeners are installed and {@link #markReady()} is called. It is our caller's
 * responsibility to only call {@link #markReady()} if all services were new at the time this
 * method was called and when all the listeners were installed.
 */

ServiceManagerState(ImmutableCollection<Service> services) {
  this.numberOfServices = services.size();
  servicesByState.putAll(NEW, services);
}
 
源代码19 项目: codebuff   文件: ServiceManager.java
/**
 * It is implicitly assumed that all the services are NEW and that they will all remain NEW
 * until all the Listeners are installed and {@link #markReady()} is called. It is our caller's
 * responsibility to only call {@link #markReady()} if all services were new at the time this
 * method was called and when all the listeners were installed.
 */

ServiceManagerState(ImmutableCollection<Service> services) {
  this.numberOfServices = services.size();
  servicesByState.putAll(NEW, services);
}
 
源代码20 项目: codebuff   文件: ServiceManager.java
/**
 * It is implicitly assumed that all the services are NEW and that they will all remain NEW
 * until all the Listeners are installed and {@link #markReady()} is called. It is our caller's
 * responsibility to only call {@link #markReady()} if all services were new at the time this
 * method was called and when all the listeners were installed.
 */
ServiceManagerState(ImmutableCollection<Service> services) {
  this.numberOfServices = services.size();
  servicesByState.putAll(NEW, services);
}