Example usage for com.google.common.collect ImmutableSortedMap copyOf

List of usage examples for com.google.common.collect ImmutableSortedMap copyOf

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedMap copyOf.

Prototype

public static <K, V> ImmutableSortedMap<K, V> copyOf(
            Iterable<? extends Entry<? extends K, ? extends V>> entries) 

Source Link

Usage

From source file:com.google.cloud.dns.testing.LocalDnsHelper.java

/**
 * Applies changes to a zone. Repeatedly tries until succeeds. Thread safe and deadlock safe.
 *///from  w  w w . j  a v  a2 s  .  c  om
private void applyExistingChange(String projectId, String zoneName, String changeId) {
    Change change = findChange(projectId, zoneName, changeId);
    if (change == null) {
        return; // no such change exists, nothing to do
    }
    ZoneContainer wrapper = findZone(projectId, zoneName);
    if (wrapper == null) {
        return; // no such zone exists; it might have been deleted by another thread
    }
    AtomicReference<ImmutableSortedMap<String, ResourceRecordSet>> dnsRecords = wrapper.dnsRecords();
    while (true) {
        // managed zone must have a set of records which is not null
        ImmutableSortedMap<String, ResourceRecordSet> original = dnsRecords.get();
        // the copy will be populated when handling deletions
        SortedMap<String, ResourceRecordSet> copy = new TreeMap<>();
        // apply deletions first
        List<ResourceRecordSet> deletions = change.getDeletions();
        if (deletions != null) {
            for (Map.Entry<String, ResourceRecordSet> entry : original.entrySet()) {
                if (!deletions.contains(entry.getValue())) {
                    copy.put(entry.getKey(), entry.getValue());
                }
            }
        } else {
            copy.putAll(original);
        }
        // apply additions
        List<ResourceRecordSet> additions = change.getAdditions();
        if (additions != null) {
            for (ResourceRecordSet addition : additions) {
                ResourceRecordSet rrset = new ResourceRecordSet();
                rrset.setName(addition.getName());
                rrset.setRrdatas(ImmutableList.copyOf(addition.getRrdatas()));
                rrset.setTtl(addition.getTtl());
                rrset.setType(addition.getType());
                String id = getUniqueId(copy.keySet());
                copy.put(id, rrset);
            }
        }
        boolean success = dnsRecords.compareAndSet(original, ImmutableSortedMap.copyOf(copy));
        if (success) {
            break; // success if no other thread modified the value in the meantime
        }
    }
    change.setStatus("done");
}

From source file:com.facebook.buck.apple.ProjectGenerator.java

private ImmutableSortedMap<Path, SourcePath> getPublicCxxHeaders(
        TargetNode<? extends CxxLibraryDescription.Arg> targetNode) {
    CxxLibraryDescription.Arg arg = targetNode.getConstructorArg();
    if (arg instanceof AppleNativeTargetDescriptionArg) {
        Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix((AppleNativeTargetDescriptionArg) arg,
                targetNode.getBuildTarget());
        ImmutableSortedMap<String, SourcePath> cxxHeaders = AppleDescriptions
                .convertAppleHeadersToPublicCxxHeaders(sourcePathResolver, headerPathPrefix, arg);
        return convertMapKeysToPaths(cxxHeaders);
    } else {/*w w  w  .  j a va 2s .c o m*/
        SourcePathResolver sourcePathResolver = sourcePathResolverForNode.apply(targetNode);
        return ImmutableSortedMap.copyOf(CxxDescriptionEnhancer.parseExportedHeaders(
                targetNode.getBuildTarget(), sourcePathResolver, Optional.<CxxPlatform>absent(), arg));
    }
}

From source file:com.facebook.buck.apple.ProjectGenerator.java

private ImmutableSortedMap<Path, SourcePath> getPrivateCxxHeaders(
        TargetNode<? extends CxxLibraryDescription.Arg> targetNode) {
    CxxLibraryDescription.Arg arg = targetNode.getConstructorArg();
    if (arg instanceof AppleNativeTargetDescriptionArg) {
        Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix((AppleNativeTargetDescriptionArg) arg,
                targetNode.getBuildTarget());
        ImmutableSortedMap<String, SourcePath> cxxHeaders = AppleDescriptions
                .convertAppleHeadersToPrivateCxxHeaders(sourcePathResolver, headerPathPrefix, arg);
        return convertMapKeysToPaths(cxxHeaders);
    } else {//  w w w.j a v a2 s .c  o  m
        SourcePathResolver sourcePathResolver = sourcePathResolverForNode.apply(targetNode);
        return ImmutableSortedMap.copyOf(CxxDescriptionEnhancer.parseHeaders(targetNode.getBuildTarget(),
                sourcePathResolver, Optional.<CxxPlatform>absent(), arg));
    }
}

From source file:com.facebook.buck.apple.ProjectGenerator.java

private Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> getXcodeBuildConfigurationsForTargetNode(
        TargetNode<?> targetNode, ImmutableMap<String, String> appendedConfig) {
    Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> configs = Optional.absent();
    Optional<TargetNode<AppleNativeTargetDescriptionArg>> appleTargetNode = targetNode
            .castArg(AppleNativeTargetDescriptionArg.class);
    Optional<TargetNode<HalideLibraryDescription.Arg>> halideTargetNode = targetNode
            .castArg(HalideLibraryDescription.Arg.class);
    if (appleTargetNode.isPresent()) {
        configs = appleTargetNode.get().getConstructorArg().configs;
    } else if (halideTargetNode.isPresent()) {
        configs = halideTargetNode.get().getConstructorArg().configs;
    }/*from w w w  .  j  a  va  2s. c  om*/
    if (!configs.isPresent() || (configs.isPresent() && configs.get().isEmpty())
            || targetNode.getType().equals(CxxLibraryDescription.TYPE)) {
        ImmutableMap<String, ImmutableMap<String, String>> defaultConfig = CxxPlatformXcodeConfigGenerator
                .getDefaultXcodeBuildConfigurationsFromCxxPlatform(defaultCxxPlatform, appendedConfig);
        configs = Optional.of(ImmutableSortedMap.copyOf(defaultConfig));
    }
    return configs;
}

From source file:com.facebook.buck.apple.project_generator.ProjectGenerator.java

private ImmutableSortedMap<Path, SourcePath> getPublicCxxHeaders(
        TargetNode<? extends CxxLibraryDescription.Arg, ?> targetNode) {
    CxxLibraryDescription.Arg arg = targetNode.getConstructorArg();
    if (arg instanceof AppleNativeTargetDescriptionArg) {
        Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix((AppleNativeTargetDescriptionArg) arg,
                targetNode.getBuildTarget());
        ImmutableSortedMap<String, SourcePath> cxxHeaders = AppleDescriptions
                .convertAppleHeadersToPublicCxxHeaders(sourcePathResolver, headerPathPrefix, arg);
        return convertMapKeysToPaths(cxxHeaders);
    } else {/*from  w ww.j  ava  2s  .  com*/
        SourcePathResolver sourcePathResolver = sourcePathResolverForNode.apply(targetNode);
        return ImmutableSortedMap.copyOf(CxxDescriptionEnhancer
                .parseExportedHeaders(targetNode.getBuildTarget(), sourcePathResolver, Optional.empty(), arg));
    }
}

From source file:com.facebook.buck.apple.project_generator.ProjectGenerator.java

private ImmutableSortedMap<Path, SourcePath> getPrivateCxxHeaders(
        TargetNode<? extends CxxLibraryDescription.Arg, ?> targetNode) {
    CxxLibraryDescription.Arg arg = targetNode.getConstructorArg();
    if (arg instanceof AppleNativeTargetDescriptionArg) {
        Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix((AppleNativeTargetDescriptionArg) arg,
                targetNode.getBuildTarget());
        ImmutableSortedMap<String, SourcePath> cxxHeaders = AppleDescriptions
                .convertAppleHeadersToPrivateCxxHeaders(sourcePathResolver, headerPathPrefix, arg);
        return convertMapKeysToPaths(cxxHeaders);
    } else {/*w w w  .  j a  v  a2s.  c  o m*/
        SourcePathResolver sourcePathResolver = sourcePathResolverForNode.apply(targetNode);
        return ImmutableSortedMap.copyOf(CxxDescriptionEnhancer.parseHeaders(targetNode.getBuildTarget(),
                sourcePathResolver, Optional.empty(), arg));
    }
}

From source file:com.facebook.buck.apple.project_generator.ProjectGenerator.java

private Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> getXcodeBuildConfigurationsForTargetNode(
        TargetNode<?, ?> targetNode, ImmutableMap<String, String> appendedConfig) {
    Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> configs = Optional.empty();
    Optional<TargetNode<AppleNativeTargetDescriptionArg, ?>> appleTargetNode = targetNode
            .castArg(AppleNativeTargetDescriptionArg.class);
    Optional<TargetNode<HalideLibraryDescription.Arg, ?>> halideTargetNode = targetNode
            .castArg(HalideLibraryDescription.Arg.class);
    if (appleTargetNode.isPresent()) {
        configs = Optional.of(appleTargetNode.get().getConstructorArg().configs);
    } else if (halideTargetNode.isPresent()) {
        configs = Optional.of(halideTargetNode.get().getConstructorArg().configs);
    }//w  w  w . j  ava  2s . co m
    if (!configs.isPresent() || (configs.isPresent() && configs.get().isEmpty())
            || targetNode.getDescription() instanceof CxxLibraryDescription) {
        ImmutableMap<String, ImmutableMap<String, String>> defaultConfig = CxxPlatformXcodeConfigGenerator
                .getDefaultXcodeBuildConfigurationsFromCxxPlatform(defaultCxxPlatform, appendedConfig);
        configs = Optional.of(ImmutableSortedMap.copyOf(defaultConfig));
    }
    return configs;
}