Java Code Examples for com.google.common.collect.ImmutableCollection#size()

The following examples show how to use com.google.common.collect.ImmutableCollection#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PermissionHolder.java    From LuckPerms with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: IjSourceRootSimplifier.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example 3
Source File: AbstractUserManager.java    From LuckPerms with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: CollectionFuture.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
  }
}
 
Example 5
Source File: DlpDomainRules.java    From james-project with Apache License 2.0 5 votes vote down vote up
private boolean containsDuplicateIds(ImmutableCollection<Rule> rules) {
    long distinctIdCount = rules.stream()
        .map(Rule::id)
        .distinct()
        .count();
    return distinctIdCount != rules.size();
}
 
Example 6
Source File: SearchCluster.java    From vespa with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: CollectionFuture.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
  }
}
 
Example 8
Source File: CollectionFuture.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
  }
}
 
Example 9
Source File: AggregateFuture.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
RunningState(
    ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures,
    boolean allMustSucceed,
    boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
Example 10
Source File: CollectionFuture.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
  }
}
 
Example 11
Source File: CollectionFuture.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
  }
}
 
Example 12
Source File: AggregateFuture.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
Example 13
Source File: AggregateFuture.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
Example 14
Source File: AggregateFuture.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
Example 15
Source File: AggregateFuture.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues) {
  super(futures.size());
  this.futures = checkNotNull(futures);
  this.allMustSucceed = allMustSucceed;
  this.collectsValues = collectsValues;
}
 
Example 16
Source File: ServiceManager.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 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);
}
 
Example 17
Source File: ServiceManager.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: ServiceManager.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 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);
}
 
Example 19
Source File: ServiceManager.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: ServiceManager.java    From codebuff with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 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);
}