Java Code Examples for com.google.common.collect.ImmutableMultimap#isEmpty()

The following examples show how to use com.google.common.collect.ImmutableMultimap#isEmpty() . 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: ConfigSetting.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Check to make sure this config_setting contains and sets least one of {values, define_values,
 * flag_value or constraint_values}.
 */
private boolean valuesAreSet(
    ImmutableMultimap<String, String> nativeFlagSettings,
    Map<Label, String> userDefinedFlagSettings,
    Iterable<Label> constraintValues,
    RuleErrorConsumer errors) {
  if (nativeFlagSettings.isEmpty()
      && userDefinedFlagSettings.isEmpty()
      && Iterables.isEmpty(constraintValues)) {
    errors.ruleError(
        String.format(
            "Either %s, %s or %s must be specified and non-empty",
            ConfigSettingRule.SETTINGS_ATTRIBUTE,
            ConfigSettingRule.FLAG_SETTINGS_ATTRIBUTE,
            ConfigSettingRule.CONSTRAINT_VALUES_ATTRIBUTE));
    return false;
  }
  return true;
}
 
Example 2
Source File: APKModuleGraph.java    From buck with Apache License 2.0 6 votes vote down vote up
private void verifyNoSharedSeeds() {
  ImmutableMultimap<BuildTarget, String> sharedSeeds = sharedSeedsSupplier.get();
  if (!sharedSeeds.isEmpty()) {
    StringBuilder errorMessage = new StringBuilder();
    for (BuildTarget seed : sharedSeeds.keySet()) {
      errorMessage
          .append("BuildTarget: ")
          .append(seed)
          .append(" is used as seed in multiple modules: ");
      for (String module : sharedSeeds.get(seed)) {
        errorMessage.append(module).append(' ');
      }
      errorMessage.append('\n');
    }
    throw new IllegalArgumentException(errorMessage.toString());
  }
}
 
Example 3
Source File: NativeExoHelper.java    From buck with Apache License 2.0 6 votes vote down vote up
private ImmutableMap<String, ImmutableMultimap<String, Path>> getFilesByHashForAbis()
    throws IOException {
  List<String> deviceAbis = abiSupplier.get();
  ImmutableMap.Builder<String, ImmutableMultimap<String, Path>> filesByHashForAbisBuilder =
      ImmutableMap.builder();
  ImmutableMultimap<String, Path> allLibraries = getAllLibraries();
  ImmutableSet.Builder<String> providedLibraries = ImmutableSet.builder();
  for (String abi : deviceAbis) {
    ImmutableMultimap<String, Path> filesByHash =
        getRequiredLibrariesForAbi(allLibraries, abi, providedLibraries.build());
    if (filesByHash.isEmpty()) {
      continue;
    }
    providedLibraries.addAll(filesByHash.keySet());
    filesByHashForAbisBuilder.put(abi, filesByHash);
  }
  return filesByHashForAbisBuilder.build();
}
 
Example 4
Source File: HttpHandler.java    From cassandra-exporter with Apache License 2.0 5 votes vote down vote up
/***
 * @return map of matched SupportedMediaTypes -> AcceptedMediaTypes
 */
private Multimap<MediaType, MediaType> checkAndGetPreferredMediaTypes(final List<MediaType> acceptedMediaTypes, final MediaType... supportedMediaTypes) {
    if (acceptedMediaTypes.isEmpty()) {
        // client didn't state that what they want, so give them the first preference
        final MediaType firstSupportedType = supportedMediaTypes[0];
        return ImmutableMultimap.of(firstSupportedType, firstSupportedType);
    }

    final ImmutableMultimap.Builder<MediaType, MediaType> preferredMediaTypes = ImmutableMultimap.builder();

    outer:
    for (final MediaType acceptedMediaType : acceptedMediaTypes) {
        for (final MediaType supportedMediaType : supportedMediaTypes) {
            if (supportedMediaType.is(acceptedMediaType.withoutParameters())) {
                preferredMediaTypes.put(supportedMediaType, acceptedMediaType);
                continue outer;
            }
        }
    }

    final ImmutableMultimap<MediaType, MediaType> map = preferredMediaTypes.build();

    if (map.isEmpty()) {
        throw new HttpException(HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE, "None of the specified acceptable media types are supported for this URI.");
    }

    return map;
}
 
Example 5
Source File: HUsToPickViewBasedProcess.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
private boolean huRowReservationMatchesPackageableRow(@NonNull final HUEditorRow huRow)
{
	final Optional<OrderLineId> orderLineId = Optional
			.ofNullable(getSingleSelectedPackageableRowOrNull())
			.flatMap(PackageableRow::getSalesOrderLineId);

	final ImmutableMultimap<OrderLineId, HUEditorRow> //
	includedOrderLineReservations = huRow.getIncludedOrderLineReservations();

	if (orderLineId.isPresent())
	{
		final int numberOfOrderLineIds = includedOrderLineReservations.keySet().size();
		final boolean reservedForMoreThanOneOrderLine = numberOfOrderLineIds > 1;
		if (reservedForMoreThanOneOrderLine)
		{
			return false;
		}
		else if (numberOfOrderLineIds == 1)
		{
			final boolean reservedForDifferentOrderLine = !includedOrderLineReservations.containsKey(orderLineId.get());
			if (reservedForDifferentOrderLine)
			{
				return false;
			}
		}
	}
	else
	{
		final boolean rowHasHuWithReservation = !includedOrderLineReservations.isEmpty();
		if (rowHasHuWithReservation)
		{
			return false;
		}
	}
	return true;
}
 
Example 6
Source File: AspectParameters.java    From bazel with Apache License 2.0 5 votes vote down vote up
@AutoCodec.Instantiator
@AutoCodec.VisibleForSerialization
static AspectParameters create(ImmutableMultimap<String, String> attributes) {
  if (attributes.isEmpty()) {
    return EMPTY;
  }
  return new AspectParameters(attributes);
}
 
Example 7
Source File: APKModuleGraph.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Group the classes in the input jars into a multimap based on the APKModule they belong to
 *
 * @param apkModuleToJarPathMap the mapping of APKModules to the path for the jar files
 * @param translatorFunction function used to translate the class names to obfuscated names
 * @param filesystem filesystem representation for resolving paths
 * @return The mapping of APKModules to the class names they contain
 * @throws IOException
 */
public static ImmutableMultimap<APKModule, String> getAPKModuleToClassesMap(
    ImmutableMultimap<APKModule, Path> apkModuleToJarPathMap,
    Function<String, String> translatorFunction,
    ProjectFilesystem filesystem)
    throws IOException {
  ImmutableMultimap.Builder<APKModule, String> builder = ImmutableSetMultimap.builder();
  if (!apkModuleToJarPathMap.isEmpty()) {
    for (APKModule dexStore : apkModuleToJarPathMap.keySet()) {
      for (Path jarFilePath : apkModuleToJarPathMap.get(dexStore)) {
        ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();
        classpathTraverser.traverse(
            new ClasspathTraversal(ImmutableSet.of(jarFilePath), filesystem) {
              @Override
              public void visit(FileLike entry) {
                if (!entry.getRelativePath().endsWith(".class")) {
                  // ignore everything but class files in the jar.
                  return;
                }

                String classpath = entry.getRelativePath().replaceAll("\\.class$", "");

                if (translatorFunction.apply(classpath) != null) {
                  builder.put(dexStore, translatorFunction.apply(classpath));
                }
              }
            });
      }
    }
  }
  return builder.build();
}
 
Example 8
Source File: UnrenewDomainCommand.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
protected void init() {
  checkArgument(period >= 1 && period <= 9, "Period must be in the range 1-9");
  DateTime now = clock.nowUtc();
  ImmutableSet.Builder<String> domainsNonexistentBuilder = new ImmutableSet.Builder<>();
  ImmutableSet.Builder<String> domainsDeletingBuilder = new ImmutableSet.Builder<>();
  ImmutableMultimap.Builder<String, StatusValue> domainsWithDisallowedStatusesBuilder =
      new ImmutableMultimap.Builder<>();
  ImmutableMap.Builder<String, DateTime> domainsExpiringTooSoonBuilder =
      new ImmutableMap.Builder<>();

  for (String domainName : mainParameters) {
    if (ofy().load().type(ForeignKeyDomainIndex.class).id(domainName).now() == null) {
      domainsNonexistentBuilder.add(domainName);
      continue;
    }
    Optional<DomainBase> domain = loadByForeignKey(DomainBase.class, domainName, now);
    if (!domain.isPresent()
        || domain.get().getStatusValues().contains(StatusValue.PENDING_DELETE)) {
      domainsDeletingBuilder.add(domainName);
      continue;
    }
    domainsWithDisallowedStatusesBuilder.putAll(
        domainName, Sets.intersection(domain.get().getStatusValues(), DISALLOWED_STATUSES));
    if (isBeforeOrAt(
        leapSafeSubtractYears(domain.get().getRegistrationExpirationTime(), period), now)) {
      domainsExpiringTooSoonBuilder.put(domainName, domain.get().getRegistrationExpirationTime());
    }
  }

  ImmutableSet<String> domainsNonexistent = domainsNonexistentBuilder.build();
  ImmutableSet<String> domainsDeleting = domainsDeletingBuilder.build();
  ImmutableMultimap<String, StatusValue> domainsWithDisallowedStatuses =
      domainsWithDisallowedStatusesBuilder.build();
  ImmutableMap<String, DateTime> domainsExpiringTooSoon = domainsExpiringTooSoonBuilder.build();

  boolean foundInvalidDomains =
      !(domainsNonexistent.isEmpty()
          && domainsDeleting.isEmpty()
          && domainsWithDisallowedStatuses.isEmpty()
          && domainsExpiringTooSoon.isEmpty());
  if (foundInvalidDomains) {
    System.err.print("Found domains that cannot be unrenewed for the following reasons:\n\n");
  }
  if (!domainsNonexistent.isEmpty()) {
    System.err.printf("Domains that don't exist: %s\n\n", domainsNonexistent);
  }
  if (!domainsDeleting.isEmpty()) {
    System.err.printf("Domains that are deleted or pending delete: %s\n\n", domainsDeleting);
  }
  if (!domainsWithDisallowedStatuses.isEmpty()) {
    System.err.printf("Domains with disallowed statuses: %s\n\n", domainsWithDisallowedStatuses);
  }
  if (!domainsExpiringTooSoon.isEmpty()) {
    System.err.printf("Domains expiring too soon: %s\n\n", domainsExpiringTooSoon);
  }
  checkArgument(!foundInvalidDomains, "Aborting because some domains cannot be unrewed");
}