Search in sources :

Example 76 with EnumSet

use of java.util.EnumSet in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class DetectedLinkageFindings method setLinkedPairs.

public void setLinkedPairs(Set<HaplotypePair> linkedPairs) {
    EnumSet<Locus> loci = null;
    if (linkedPairs.iterator().hasNext() && linkedPairs.iterator().next().isByRace()) {
        HashMap<Set<Locus>, HashMap<String, Double>> raceTotalFreqsMap = new HashMap<Set<Locus>, HashMap<String, Double>>();
        Set<HaplotypePair> noRaceOverlapPairs = new HashSet<HaplotypePair>();
        RelativeFrequencyByRace relativeRaceFreq;
        String race;
        Double totalFreq;
        for (HaplotypePair pair : linkedPairs) {
            loci = Locus.lookup(pair.getLoci());
            if (pair.getPrimaryFrequency() == null) {
                noRaceOverlapPairs.add(pair);
                continue;
            }
            for (Object freqByRace : pair.getFrequencies()) {
                relativeRaceFreq = (RelativeFrequencyByRace) freqByRace;
                race = relativeRaceFreq.getRace();
                raceTotalFreqsMap = calculateTotalFrequency(loci, raceTotalFreqsMap, relativeRaceFreq, race);
            }
        }
        linkedPairs.removeAll(noRaceOverlapPairs);
        HashMap<String, List<Float>> minimumDifferenceMap;
        for (HaplotypePair pair : linkedPairs) {
            loci = Locus.lookup(pair.getLoci());
            setLinkedPairs(loci, true);
            minimumDifferenceMap = minimumDifferenceMapOfMaps.get(loci) != null ? minimumDifferenceMapOfMaps.get(loci) : new HashMap<String, List<Float>>();
            Set<RelativeFrequencyByRace> freqsByRace = new RelativeFrequencyByRaceSet(new RelativeFrequencyByRaceComparator());
            for (Object freqByRace : pair.getFrequencies()) {
                relativeRaceFreq = (RelativeFrequencyByRace) freqByRace;
                totalFreq = raceTotalFreqsMap.get(loci).get(relativeRaceFreq.getRace());
                relativeRaceFreq.setRelativeFrequency(new Float((relativeRaceFreq.getFrequency() * 100) / totalFreq));
                freqsByRace.add(relativeRaceFreq);
                List<Float> relativeFrequencies;
                if (minimumDifferenceMap.containsKey(relativeRaceFreq.getRace())) {
                    relativeFrequencies = minimumDifferenceMap.get(relativeRaceFreq.getRace());
                } else {
                    relativeFrequencies = new ArrayList<Float>();
                }
                relativeFrequencies.add(relativeRaceFreq.getRelativeFrequency());
                minimumDifferenceMap.put(relativeRaceFreq.getRace(), relativeFrequencies);
            }
            minimumDifferenceMapOfMaps.put(loci, minimumDifferenceMap);
            this.linkedPairs.add(pair);
        }
    } else {
        for (HaplotypePair pair : linkedPairs) {
            loci = Locus.lookup(pair.getLoci());
            setLinkedPairs(loci, true);
        }
        this.linkedPairs = linkedPairs;
    }
    Set<EnumSet<Locus>> lociSet = this.linkedPairsMap.keySet();
    for (EnumSet<Locus> lociInSet : lociSet) {
        getFirstPair(lociInSet);
    }
}
Also used : HaplotypePairSet(org.dash.valid.gl.haplo.HaplotypePairSet) Set(java.util.Set) RelativeFrequencyByRaceSet(org.dash.valid.race.RelativeFrequencyByRaceSet) HashSet(java.util.HashSet) LinkageElementsSet(org.dash.valid.LinkageElementsSet) EnumSet(java.util.EnumSet) HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) HashMap(java.util.HashMap) RelativeFrequencyByRace(org.dash.valid.race.RelativeFrequencyByRace) EnumSet(java.util.EnumSet) RelativeFrequencyByRaceComparator(org.dash.valid.race.RelativeFrequencyByRaceComparator) RelativeFrequencyByRaceSet(org.dash.valid.race.RelativeFrequencyByRaceSet) ArrayList(java.util.ArrayList) LinkageDisequilibriumGenotypeList(org.dash.valid.gl.LinkageDisequilibriumGenotypeList) List(java.util.List) Locus(org.dash.valid.Locus) HashSet(java.util.HashSet)

Example 77 with EnumSet

use of java.util.EnumSet in project elasticsearch by elastic.

the class ClusterState method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    EnumSet<Metric> metrics = Metric.parseString(params.param("metric", "_all"), true);
    if (metrics.contains(Metric.VERSION)) {
        builder.field("version", version);
        builder.field("state_uuid", stateUUID);
    }
    if (metrics.contains(Metric.MASTER_NODE)) {
        builder.field("master_node", nodes().getMasterNodeId());
    }
    if (metrics.contains(Metric.BLOCKS)) {
        builder.startObject("blocks");
        if (!blocks().global().isEmpty()) {
            builder.startObject("global");
            for (ClusterBlock block : blocks().global()) {
                block.toXContent(builder, params);
            }
            builder.endObject();
        }
        if (!blocks().indices().isEmpty()) {
            builder.startObject("indices");
            for (ObjectObjectCursor<String, Set<ClusterBlock>> entry : blocks().indices()) {
                builder.startObject(entry.key);
                for (ClusterBlock block : entry.value) {
                    block.toXContent(builder, params);
                }
                builder.endObject();
            }
            builder.endObject();
        }
        builder.endObject();
    }
    // nodes
    if (metrics.contains(Metric.NODES)) {
        builder.startObject("nodes");
        for (DiscoveryNode node : nodes) {
            node.toXContent(builder, params);
        }
        builder.endObject();
    }
    // meta data
    if (metrics.contains(Metric.METADATA)) {
        builder.startObject("metadata");
        builder.field("cluster_uuid", metaData().clusterUUID());
        builder.startObject("templates");
        for (ObjectCursor<IndexTemplateMetaData> cursor : metaData().templates().values()) {
            IndexTemplateMetaData templateMetaData = cursor.value;
            builder.startObject(templateMetaData.name());
            builder.field("index_patterns", templateMetaData.patterns());
            builder.field("order", templateMetaData.order());
            builder.startObject("settings");
            Settings settings = templateMetaData.settings();
            settings.toXContent(builder, params);
            builder.endObject();
            builder.startObject("mappings");
            for (ObjectObjectCursor<String, CompressedXContent> cursor1 : templateMetaData.mappings()) {
                Map<String, Object> mapping = XContentHelper.convertToMap(new BytesArray(cursor1.value.uncompressed()), false).v2();
                if (mapping.size() == 1 && mapping.containsKey(cursor1.key)) {
                    // the type name is the root value, reduce it
                    mapping = (Map<String, Object>) mapping.get(cursor1.key);
                }
                builder.field(cursor1.key);
                builder.map(mapping);
            }
            builder.endObject();
            builder.endObject();
        }
        builder.endObject();
        builder.startObject("indices");
        for (IndexMetaData indexMetaData : metaData()) {
            builder.startObject(indexMetaData.getIndex().getName());
            builder.field("state", indexMetaData.getState().toString().toLowerCase(Locale.ENGLISH));
            builder.startObject("settings");
            Settings settings = indexMetaData.getSettings();
            settings.toXContent(builder, params);
            builder.endObject();
            builder.startObject("mappings");
            for (ObjectObjectCursor<String, MappingMetaData> cursor : indexMetaData.getMappings()) {
                Map<String, Object> mapping = XContentHelper.convertToMap(new BytesArray(cursor.value.source().uncompressed()), false).v2();
                if (mapping.size() == 1 && mapping.containsKey(cursor.key)) {
                    // the type name is the root value, reduce it
                    mapping = (Map<String, Object>) mapping.get(cursor.key);
                }
                builder.field(cursor.key);
                builder.map(mapping);
            }
            builder.endObject();
            builder.startArray("aliases");
            for (ObjectCursor<String> cursor : indexMetaData.getAliases().keys()) {
                builder.value(cursor.value);
            }
            builder.endArray();
            builder.startObject(IndexMetaData.KEY_PRIMARY_TERMS);
            for (int shard = 0; shard < indexMetaData.getNumberOfShards(); shard++) {
                builder.field(Integer.toString(shard), indexMetaData.primaryTerm(shard));
            }
            builder.endObject();
            builder.startObject(IndexMetaData.KEY_IN_SYNC_ALLOCATIONS);
            for (IntObjectCursor<Set<String>> cursor : indexMetaData.getInSyncAllocationIds()) {
                builder.startArray(String.valueOf(cursor.key));
                for (String allocationId : cursor.value) {
                    builder.value(allocationId);
                }
                builder.endArray();
            }
            builder.endObject();
            // index metadata
            builder.endObject();
        }
        builder.endObject();
        for (ObjectObjectCursor<String, MetaData.Custom> cursor : metaData.customs()) {
            builder.startObject(cursor.key);
            cursor.value.toXContent(builder, params);
            builder.endObject();
        }
        builder.endObject();
    }
    // routing table
    if (metrics.contains(Metric.ROUTING_TABLE)) {
        builder.startObject("routing_table");
        builder.startObject("indices");
        for (IndexRoutingTable indexRoutingTable : routingTable()) {
            builder.startObject(indexRoutingTable.getIndex().getName());
            builder.startObject("shards");
            for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
                builder.startArray(Integer.toString(indexShardRoutingTable.shardId().id()));
                for (ShardRouting shardRouting : indexShardRoutingTable) {
                    shardRouting.toXContent(builder, params);
                }
                builder.endArray();
            }
            builder.endObject();
            builder.endObject();
        }
        builder.endObject();
        builder.endObject();
    }
    // routing nodes
    if (metrics.contains(Metric.ROUTING_NODES)) {
        builder.startObject("routing_nodes");
        builder.startArray("unassigned");
        for (ShardRouting shardRouting : getRoutingNodes().unassigned()) {
            shardRouting.toXContent(builder, params);
        }
        builder.endArray();
        builder.startObject("nodes");
        for (RoutingNode routingNode : getRoutingNodes()) {
            builder.startArray(routingNode.nodeId() == null ? "null" : routingNode.nodeId());
            for (ShardRouting shardRouting : routingNode) {
                shardRouting.toXContent(builder, params);
            }
            builder.endArray();
        }
        builder.endObject();
        builder.endObject();
    }
    if (metrics.contains(Metric.CUSTOMS)) {
        for (ObjectObjectCursor<String, Custom> cursor : customs) {
            builder.startObject(cursor.key);
            cursor.value.toXContent(builder, params);
            builder.endObject();
        }
    }
    return builder;
}
Also used : IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) EnumSet(java.util.EnumSet) Set(java.util.Set) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Settings(org.elasticsearch.common.settings.Settings) BytesArray(org.elasticsearch.common.bytes.BytesArray) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 78 with EnumSet

use of java.util.EnumSet in project buck by facebook.

the class AndroidBinaryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    try (SimplePerfEvent.Scope ignored = SimplePerfEvent.scope(Optional.ofNullable(resolver.getEventBus()), PerfEventId.of("AndroidBinaryDescription"), "target", params.getBuildTarget().toString())) {
        ResourceCompressionMode compressionMode = getCompressionMode(args);
        BuildTarget target = params.getBuildTarget();
        boolean isFlavored = target.isFlavored();
        if (isFlavored) {
            if (target.getFlavors().contains(PACKAGE_STRING_ASSETS_FLAVOR) && !compressionMode.isStoreStringsAsAssets()) {
                throw new HumanReadableException("'package_string_assets' flavor does not exist for %s.", target.getUnflavoredBuildTarget());
            }
            params = params.withBuildTarget(BuildTarget.of(target.getUnflavoredBuildTarget()));
        }
        BuildRule keystore = resolver.getRule(args.keystore);
        if (!(keystore instanceof Keystore)) {
            throw new HumanReadableException("In %s, keystore='%s' must be a keystore() but was %s().", params.getBuildTarget(), keystore.getFullyQualifiedName(), keystore.getType());
        }
        APKModuleGraph apkModuleGraph = new APKModuleGraph(targetGraph, target, Optional.of(args.applicationModuleTargets));
        ProGuardObfuscateStep.SdkProguardType androidSdkProguardConfig = args.androidSdkProguardConfig.orElse(ProGuardObfuscateStep.SdkProguardType.DEFAULT);
        // was not specified, and allow the old form to override the default.
        if (args.useAndroidProguardConfigWithOptimizations.isPresent()) {
            Preconditions.checkArgument(!args.androidSdkProguardConfig.isPresent(), "The deprecated use_android_proguard_config_with_optimizations parameter" + " cannot be used with android_sdk_proguard_config.");
            LOG.error("Target %s specified use_android_proguard_config_with_optimizations, " + "which is deprecated. Use android_sdk_proguard_config.", params.getBuildTarget());
            androidSdkProguardConfig = args.useAndroidProguardConfigWithOptimizations.orElse(false) ? ProGuardObfuscateStep.SdkProguardType.OPTIMIZED : ProGuardObfuscateStep.SdkProguardType.DEFAULT;
        }
        EnumSet<ExopackageMode> exopackageModes = EnumSet.noneOf(ExopackageMode.class);
        if (!args.exopackageModes.isEmpty()) {
            exopackageModes = EnumSet.copyOf(args.exopackageModes);
        } else if (args.exopackage.orElse(false)) {
            LOG.error("Target %s specified exopackage=True, which is deprecated. Use exopackage_modes.", params.getBuildTarget());
            exopackageModes = EnumSet.of(ExopackageMode.SECONDARY_DEX);
        }
        DexSplitMode dexSplitMode = createDexSplitMode(args, exopackageModes);
        PackageType packageType = getPackageType(args);
        boolean shouldPreDex = !args.disablePreDex && PackageType.DEBUG.equals(packageType) && !args.preprocessJavaClassesBash.isPresent();
        ResourceFilter resourceFilter = new ResourceFilter(args.resourceFilter);
        AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(params, resolver, compressionMode, resourceFilter, args.getBannedDuplicateResourceTypes(), args.resourceUnionPackage, addFallbackLocales(args.locales), args.manifest, packageType, ImmutableSet.copyOf(args.cpuFilters), args.buildStringSourceMap, shouldPreDex, AndroidBinary.getPrimaryDexPath(params.getBuildTarget(), params.getProjectFilesystem()), dexSplitMode, ImmutableSet.copyOf(args.noDx.orElse(ImmutableSet.of())), /* resourcesToExclude */
        ImmutableSet.of(), args.skipCrunchPngs, args.includesVectorDrawables, javacOptions, exopackageModes, args.buildConfigValues, args.buildConfigValuesFile, Optional.empty(), args.trimResourceIds, args.keepResourcePattern, nativePlatforms, Optional.of(args.nativeLibraryMergeMap), args.nativeLibraryMergeGlue, args.nativeLibraryMergeCodeGenerator, args.enableRelinker ? RelinkerMode.ENABLED : RelinkerMode.DISABLED, dxExecutorService, args.manifestEntries, cxxBuckConfig, apkModuleGraph, dxConfig);
        AndroidGraphEnhancementResult result = graphEnhancer.createAdditionalBuildables();
        if (target.getFlavors().contains(PACKAGE_STRING_ASSETS_FLAVOR)) {
            Optional<PackageStringAssets> packageStringAssets = result.getPackageStringAssets();
            Preconditions.checkState(packageStringAssets.isPresent());
            return packageStringAssets.get();
        }
        // Build rules added to "no_dx" are only hints, not hard dependencies. Therefore, although a
        // target may be mentioned in that parameter, it may not be present as a build rule.
        ImmutableSortedSet.Builder<BuildRule> builder = ImmutableSortedSet.naturalOrder();
        for (BuildTarget noDxTarget : args.noDx.orElse(ImmutableSet.of())) {
            Optional<BuildRule> ruleOptional = resolver.getRuleOptional(noDxTarget);
            if (ruleOptional.isPresent()) {
                builder.add(ruleOptional.get());
            } else {
                LOG.info("%s: no_dx target not a dependency: %s", target, noDxTarget);
            }
        }
        ImmutableSortedSet<BuildRule> buildRulesToExcludeFromDex = builder.build();
        ImmutableSortedSet<JavaLibrary> rulesToExcludeFromDex = RichStream.from(buildRulesToExcludeFromDex).filter(JavaLibrary.class).collect(MoreCollectors.toImmutableSortedSet(Ordering.natural()));
        SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
        Optional<RedexOptions> redexOptions = getRedexOptions(params, resolver, args);
        ImmutableSortedSet<BuildRule> redexExtraDeps = redexOptions.map(a -> a.getRedexExtraArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).collect(MoreCollectors.toImmutableSortedSet(Ordering.natural()))).orElse(ImmutableSortedSet.of());
        return new AndroidBinary(params.copyReplacingExtraDeps(Suppliers.ofInstance(result.getFinalDeps())).copyAppendingExtraDeps(ruleFinder.filterBuildRuleInputs(result.getPackageableCollection().getProguardConfigs())).copyAppendingExtraDeps(rulesToExcludeFromDex).copyAppendingExtraDeps(redexExtraDeps), ruleFinder, proGuardConfig.getProguardJarOverride(), proGuardConfig.getProguardMaxHeapSize(), Optional.of(args.proguardJvmArgs), proGuardConfig.getProguardAgentPath(), (Keystore) keystore, packageType, dexSplitMode, args.noDx.orElse(ImmutableSet.of()), androidSdkProguardConfig, args.optimizationPasses, args.proguardConfig, args.skipProguard, redexOptions, compressionMode, args.cpuFilters, resourceFilter, exopackageModes, MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver), args.preprocessJavaClassesBash, rulesToExcludeFromDex, result, args.reorderClassesIntraDex, args.dexReorderToolFile, args.dexReorderDataDumpFile, args.xzCompressionLevel, dxExecutorService, args.packageAssetLibraries, args.compressAssetLibraries, args.manifestEntries, javaOptions.getJavaRuntimeLauncher(), dxConfig.getDxMaxHeapSize());
    }
}
Also used : PerfEventId(com.facebook.buck.event.PerfEventId) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) RichStream(com.facebook.buck.util.RichStream) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) HasTests(com.facebook.buck.model.HasTests) ExopackageMode(com.facebook.buck.android.AndroidBinary.ExopackageMode) BuckConfig(com.facebook.buck.cli.BuckConfig) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) Map(java.util.Map) DexSplitStrategy(com.facebook.buck.dalvik.ZipSplitter.DexSplitStrategy) Keystore(com.facebook.buck.jvm.java.Keystore) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) MacroException(com.facebook.buck.model.MacroException) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Collectors(java.util.stream.Collectors) ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) List(java.util.List) PackageType(com.facebook.buck.android.AndroidBinary.PackageType) RelinkerMode(com.facebook.buck.android.AndroidBinary.RelinkerMode) Hint(com.facebook.buck.rules.Hint) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) Description(com.facebook.buck.rules.Description) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) CellPathResolver(com.facebook.buck.rules.CellPathResolver) ResourceCompressionMode(com.facebook.buck.android.ResourcesFilter.ResourceCompressionMode) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) JavaOptions(com.facebook.buck.jvm.java.JavaOptions) SourcePath(com.facebook.buck.rules.SourcePath) Flavored(com.facebook.buck.model.Flavored) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImplicitDepsInferringDescription(com.facebook.buck.rules.ImplicitDepsInferringDescription) BuildConfigFields(com.facebook.buck.rules.coercer.BuildConfigFields) Suppliers(com.google.common.base.Suppliers) RedexOptions(com.facebook.buck.android.redex.RedexOptions) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Logger(com.facebook.buck.log.Logger) MacroArg(com.facebook.buck.rules.args.MacroArg) ManifestEntries(com.facebook.buck.rules.coercer.ManifestEntries) JavacOptions(com.facebook.buck.jvm.java.JavacOptions) HumanReadableException(com.facebook.buck.util.HumanReadableException) PACKAGE_STRING_ASSETS_FLAVOR(com.facebook.buck.android.AndroidBinaryGraphEnhancer.PACKAGE_STRING_ASSETS_FLAVOR) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) Ordering(com.google.common.collect.Ordering) TargetCpuType(com.facebook.buck.android.NdkCxxPlatforms.TargetCpuType) ResourceFilter(com.facebook.buck.android.FilterResourcesStep.ResourceFilter) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) RedexOptions(com.facebook.buck.android.redex.RedexOptions) Keystore(com.facebook.buck.jvm.java.Keystore) ResourceFilter(com.facebook.buck.android.FilterResourcesStep.ResourceFilter) BuildTarget(com.facebook.buck.model.BuildTarget) PackageType(com.facebook.buck.android.AndroidBinary.PackageType) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ResourceCompressionMode(com.facebook.buck.android.ResourcesFilter.ResourceCompressionMode) ExopackageMode(com.facebook.buck.android.AndroidBinary.ExopackageMode) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 79 with EnumSet

use of java.util.EnumSet in project hadoop by apache.

the class TestApplicationMasterService method testResourceTypes.

@Test(timeout = 3000000)
public void testResourceTypes() throws Exception {
    HashMap<YarnConfiguration, EnumSet<SchedulerResourceTypes>> driver = new HashMap<YarnConfiguration, EnumSet<SchedulerResourceTypes>>();
    CapacitySchedulerConfiguration csconf = new CapacitySchedulerConfiguration();
    csconf.setResourceComparator(DominantResourceCalculator.class);
    YarnConfiguration testCapacityDRConf = new YarnConfiguration(csconf);
    testCapacityDRConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class);
    YarnConfiguration testCapacityDefConf = new YarnConfiguration();
    testCapacityDefConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class);
    YarnConfiguration testFairDefConf = new YarnConfiguration();
    testFairDefConf.setClass(YarnConfiguration.RM_SCHEDULER, FairScheduler.class, ResourceScheduler.class);
    driver.put(conf, EnumSet.of(SchedulerResourceTypes.MEMORY));
    driver.put(testCapacityDRConf, EnumSet.of(SchedulerResourceTypes.CPU, SchedulerResourceTypes.MEMORY));
    driver.put(testCapacityDefConf, EnumSet.of(SchedulerResourceTypes.MEMORY));
    driver.put(testFairDefConf, EnumSet.of(SchedulerResourceTypes.MEMORY, SchedulerResourceTypes.CPU));
    for (Map.Entry<YarnConfiguration, EnumSet<SchedulerResourceTypes>> entry : driver.entrySet()) {
        EnumSet<SchedulerResourceTypes> expectedValue = entry.getValue();
        MockRM rm = new MockRM(entry.getKey());
        rm.start();
        MockNM nm1 = rm.registerNode("127.0.0.1:1234", 6 * GB);
        RMApp app1 = rm.submitApp(2048);
        //Wait to make sure the attempt has the right state
        //TODO explore a better way than sleeping for a while (YARN-4929)
        Thread.sleep(1000);
        nm1.nodeHeartbeat(true);
        RMAppAttempt attempt1 = app1.getCurrentAppAttempt();
        MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId());
        RegisterApplicationMasterResponse resp = am1.registerAppAttempt();
        EnumSet<SchedulerResourceTypes> types = resp.getSchedulerResourceTypes();
        LOG.info("types = " + types.toString());
        Assert.assertEquals(expectedValue, types);
        rm.stop();
    }
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMAppAttempt(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt) HashMap(java.util.HashMap) EnumSet(java.util.EnumSet) SchedulerResourceTypes(org.apache.hadoop.yarn.proto.YarnServiceProtos.SchedulerResourceTypes) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) RegisterApplicationMasterResponse(org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse) HashMap(java.util.HashMap) Map(java.util.Map) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Test(org.junit.Test)

Example 80 with EnumSet

use of java.util.EnumSet in project j2objc by google.

the class EnumSetTest method test_containsAll_LCollection.

/**
     * @tests java.util.EnumSet#containsAll(Collection)
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_containsAll_LCollection() {
    EnumSet<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
    Enum[] elements = EnumFoo.class.getEnumConstants();
    for (int i = 0; i < elements.length; i++) {
        set.add((EnumFoo) elements[i]);
    }
    try {
        set.containsAll(null);
        //$NON-NLS-1$
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    EnumSet<EmptyEnum> emptySet = EnumSet.noneOf(EmptyEnum.class);
    elements = EmptyEnum.class.getEnumConstants();
    for (int i = 0; i < elements.length; i++) {
        emptySet.add((EmptyEnum) elements[i]);
    }
    boolean result = set.containsAll(emptySet);
    //$NON-NLS-1$
    assertTrue("Should return true", result);
    Collection rawCollection = new ArrayList();
    result = set.containsAll(rawCollection);
    //$NON-NLS-1$
    assertTrue("Should contain empty collection:", result);
    rawCollection.add(1);
    result = set.containsAll(rawCollection);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    rawCollection.add(EnumWithInnerClass.a);
    result = set.containsAll(rawCollection);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    EnumSet rawSet = EnumSet.noneOf(EnumFoo.class);
    result = set.containsAll(rawSet);
    //$NON-NLS-1$
    assertTrue("Should contain empty set", result);
    emptySet = EnumSet.noneOf(EmptyEnum.class);
    result = set.containsAll(emptySet);
    //$NON-NLS-1$
    assertTrue("No class cast should be performed on empty set", result);
    Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
    collection.add(EnumFoo.a);
    result = set.containsAll(collection);
    //$NON-NLS-1$
    assertTrue("Should contain all elements in collection", result);
    EnumSet<EnumFoo> fooSet = EnumSet.noneOf(EnumFoo.class);
    fooSet.add(EnumFoo.a);
    result = set.containsAll(fooSet);
    //$NON-NLS-1$
    assertTrue("Should return true", result);
    set.clear();
    try {
        set.containsAll(null);
        //$NON-NLS-1$
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    Collection<EnumWithInnerClass> collectionWithSubclass = new ArrayList<EnumWithInnerClass>();
    collectionWithSubclass.add(EnumWithInnerClass.a);
    result = set.containsAll(collectionWithSubclass);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    EnumSet<EnumWithInnerClass> setWithSubclass = EnumSet.noneOf(EnumWithInnerClass.class);
    setWithSubclass.add(EnumWithInnerClass.a);
    result = set.containsAll(setWithSubclass);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    // test enum type with more than 64 elements
    Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
    hugeSet.add(HugeEnum.a);
    hugeSet.add(HugeEnum.b);
    hugeSet.add(HugeEnum.aa);
    hugeSet.add(HugeEnum.bb);
    hugeSet.add(HugeEnum.cc);
    hugeSet.add(HugeEnum.dd);
    Set<HugeEnum> anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
    hugeSet.add(HugeEnum.b);
    hugeSet.add(HugeEnum.cc);
    result = hugeSet.containsAll(anotherHugeSet);
    assertTrue(result);
    try {
        hugeSet.containsAll(null);
        //$NON-NLS-1$
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
    hugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
    hugeSetWithInnerClass.add(HugeEnumWithInnerClass.b);
    result = hugeSetWithInnerClass.containsAll(hugeSetWithInnerClass);
    assertTrue(result);
    result = hugeSet.containsAll(hugeSetWithInnerClass);
    assertFalse(result);
    rawCollection = new ArrayList();
    result = hugeSet.containsAll(rawCollection);
    //$NON-NLS-1$
    assertTrue("Should contain empty collection:", result);
    rawCollection.add(1);
    result = hugeSet.containsAll(rawCollection);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    rawCollection.add(EnumWithInnerClass.a);
    result = set.containsAll(rawCollection);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    rawSet = EnumSet.noneOf(HugeEnum.class);
    result = hugeSet.containsAll(rawSet);
    //$NON-NLS-1$
    assertTrue("Should contain empty set", result);
    EnumSet<HugeEnumWithInnerClass> emptyHugeSet = EnumSet.noneOf(HugeEnumWithInnerClass.class);
    result = hugeSet.containsAll(emptyHugeSet);
    //$NON-NLS-1$
    assertTrue("No class cast should be performed on empty set", result);
    Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
    hugeCollection.add(HugeEnum.a);
    result = hugeSet.containsAll(hugeCollection);
    //$NON-NLS-1$
    assertTrue("Should contain all elements in collection", result);
    hugeSet.clear();
    try {
        hugeSet.containsAll(null);
        //$NON-NLS-1$
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    Collection<HugeEnumWithInnerClass> hugeCollectionWithSubclass = new ArrayList<HugeEnumWithInnerClass>();
    hugeCollectionWithSubclass.add(HugeEnumWithInnerClass.a);
    result = hugeSet.containsAll(hugeCollectionWithSubclass);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    EnumSet<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
    hugeSetWithSubclass.add(HugeEnumWithInnerClass.a);
    result = hugeSet.containsAll(hugeSetWithSubclass);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
}
Also used : EnumSet(java.util.EnumSet) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Aggregations

EnumSet (java.util.EnumSet)151 Set (java.util.Set)44 ArrayList (java.util.ArrayList)43 Map (java.util.Map)30 List (java.util.List)29 HashMap (java.util.HashMap)27 HashSet (java.util.HashSet)27 Collection (java.util.Collection)22 Test (org.junit.Test)20 Collectors (java.util.stream.Collectors)19 IOException (java.io.IOException)16 Collections (java.util.Collections)14 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)13 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)12 TreeSet (java.util.TreeSet)11 File (java.io.File)10 Arrays (java.util.Arrays)10 LinkedHashSet (java.util.LinkedHashSet)10 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)9 TreeMap (java.util.TreeMap)8