Example usage for com.google.common.collect Maps uniqueIndex

List of usage examples for com.google.common.collect Maps uniqueIndex

Introduction

In this page you can find the example usage for com.google.common.collect Maps uniqueIndex.

Prototype

public static <K, V> ImmutableMap<K, V> uniqueIndex(Iterator<V> values, Function<? super V, K> keyFunction) 

Source Link

Document

Returns a map with the given values , indexed by keys derived from those values.

Usage

From source file:org.apache.eagle.security.oozie.parse.sensitivity.OozieResourceSensitivityPollingJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
    try {//  ww  w  .  ja va2s .  c om
        List<OozieResourceSensitivityAPIEntity> oozieResourceSensitivity = load(jobDataMap,
                "OozieResourceSensitivityService");
        if (oozieResourceSensitivity == null) {
            LOG.warn("Oozie resource sensitivity information is empty");
            return;
        }
        Map<String, OozieResourceSensitivityAPIEntity> map = Maps.uniqueIndex(oozieResourceSensitivity,
                new Function<OozieResourceSensitivityAPIEntity, String>() {
                    @Override
                    public String apply(OozieResourceSensitivityAPIEntity input) {
                        return input.getTags().get("oozieResource");
                    }
                });
        ExternalDataCache.getInstance().setJobResult(getClass(), map);
    } catch (Exception ex) {
        LOG.error("Fail to load oozie resource sensitivity data", ex);
    }
}

From source file:org.jclouds.elasticstack.functions.MapToDevices.java

public Map<String, ? extends Device> apply(Map<String, String> from) {
    Builder<Device> devices = ImmutableSet.builder();
    addIDEDevices(from, devices);//from w  w  w .  j a  va  2s. co  m
    addSCSIDevices(from, devices);
    addBlockDevices(from, devices);

    return Maps.uniqueIndex(devices.build(), deviceToId);
}

From source file:org.ow2.authzforce.core.pdp.api.BasePdpExtensionRegistry.java

@SuppressWarnings("unchecked")
private static <E extends PdpExtension> Map<String, E> newImmutableMap(final Set<E> extensions) {
    return Maps.uniqueIndex(extensions, (Function<E, String>) EXTENSION_TO_ID_FUNCTION);
}

From source file:kuona.jenkins.analyser.JenkinsProcessor.java

/**
 * Get a list of all the defined jobs on the server (at the summary level)
 *
 * @return list of defined jobs (summary level, for details @see Job#details
 * @throws IOException//w ww  .j  a  va 2s.c o m
 */
public Map<String, Job> getJobs() throws IOException {
    List<Job> jobs = client.get("/", MainView.class).getJobs();
    return Maps.uniqueIndex(jobs, job -> {
        job.setClient(client);
        return job.getName().toLowerCase();
    });
}

From source file:fr.xebia.workshop.monitoring.InfrastructureTopologyScanner.java

public Collection<TeamInfrastructure> scan() {
    Filter filter = new Filter("tag:Workshop", newArrayList("monitoring"));
    List<Reservation> reservations = ec2.describeInstances(new DescribeInstancesRequest().withFilters(filter))
            .getReservations();//from  w  w  w . j av  a 2 s.  co m

    Iterable<Instance> instances = AmazonAwsUtils.toEc2Instances(reservations);

    Iterable<Instance> runningInstances = Iterables.filter(instances,
            AmazonAwsUtils.PREDICATE_RUNNING_OR_PENDING_INSTANCE);
    runningInstances = AmazonAwsUtils.awaitForEc2Instances(runningInstances, ec2);

    Map<String, Instance> runningInstancesByInstanceId = Maps.uniqueIndex(runningInstances,
            AmazonAwsFunctions.EC2_INSTANCE_TO_INSTANCE_ID);

    List<String> runningInstanceIds = newArrayList(
            Iterables.transform(runningInstances, AmazonAwsFunctions.EC2_INSTANCE_TO_INSTANCE_ID));

    List<TagDescription> tags = ec2
            .describeTags(new DescribeTagsRequest().withFilters(new Filter("resource-id", runningInstanceIds)))
            .getTags();
    Map<String, Map<String, String>> tagsByInstanceId = new MapMaker()
            .makeComputingMap(new Function<String, Map<String, String>>() {
                @Override
                public Map<String, String> apply(String instanceId) {
                    return Maps.newHashMap();
                }
            });

    for (TagDescription tag : tags) {
        tagsByInstanceId.get(tag.getResourceId()).put(tag.getKey(), tag.getValue());
    }

    Map<String, TeamInfrastructure> teamInfrastructureByTeamIdentifier = new MapMaker()
            .makeComputingMap(new Function<String, TeamInfrastructure>() {
                @Override
                public TeamInfrastructure apply(String teamIdentifier) {
                    return new TeamInfrastructure(workshopInfrastructure, teamIdentifier);
                }
            });

    Instance nexusServer = null;

    for (Map.Entry<String, Map<String, String>> entry : tagsByInstanceId.entrySet()) {
        Map<String, String> instanceTags = entry.getValue();
        String instanceId = entry.getKey();
        Instance instance = runningInstancesByInstanceId.get(instanceId);
        String teamIdentifier = instanceTags.get("TeamIdentifier");

        if (teamIdentifier == null) {

            // not a per team server (e.g. Nexus server)

        } else {

            TeamInfrastructure teamInfrastructure = teamInfrastructureByTeamIdentifier.get(teamIdentifier);
            teamInfrastructure.addInstance(instance, instanceTags);
        }
    }
    Collection<TeamInfrastructure> teamInfrastructures = teamInfrastructureByTeamIdentifier.values();
    return teamInfrastructures;
}

From source file:org.jclouds.loadbalancer.config.BaseLoadBalancerServiceContextModule.java

@Provides
@Singleton/*from  w ww. ja va2  s  .c om*/
protected Supplier<Map<String, ? extends Location>> provideLocationMap(
        @Memoized Supplier<Set<? extends Location>> locations) {
    return Suppliers.compose(new Function<Set<? extends Location>, Map<String, ? extends Location>>() {

        @Override
        public Map<String, ? extends Location> apply(Set<? extends Location> from) {
            return Maps.uniqueIndex(from, new Function<Location, String>() {

                @Override
                public String apply(Location from) {
                    return from.getId();
                }

            });
        }

    }, locations);
}

From source file:li.klass.fhem.service.room.group.GroupProvider.java

@Inject
public GroupProvider(Set<DeviceGroupProvider> deviceGroupProviders) {
    this.providerMap = Maps.uniqueIndex(deviceGroupProviders, TO_KEY);
}

From source file:org.apache.eagle.security.hive.sensitivity.HiveResourceSensitivityPollingJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
    try {/*  w w w .j  av  a  2 s.  c  om*/
        List<HiveResourceSensitivityAPIEntity> hiveResourceSensitivity = load(jobDataMap);
        if (hiveResourceSensitivity == null) {
            LOG.warn("Hive resource sensitivity information is empty");
            return;
        }
        Map<String, HiveResourceSensitivityAPIEntity> map = Maps.uniqueIndex(hiveResourceSensitivity,
                new Function<HiveResourceSensitivityAPIEntity, String>() {
                    @Override
                    public String apply(HiveResourceSensitivityAPIEntity input) {
                        return input.getTags().get("hiveResource");
                    }
                });
        ExternalDataCache.getInstance().setJobResult(getClass(), map);
    } catch (Exception ex) {
        LOG.error("Fail to load hive resource sensitivity data", ex);
    }
}

From source file:models.Manifest.java

/**
 * Converts the manifest to a {@link Map}.
 *
 * @return a map of the manifest//from   www  .  ja v  a  2  s. c  om
 */
public Map<String, PackageVersion> asPackageMap() {
    return Maps.uniqueIndex(getPackages(), new Function<PackageVersion, String>() {
        @Nullable
        @Override
        public String apply(final PackageVersion input) {
            return input.getPkg().getName();
        }
    });
}

From source file:org.eclipse.sw360.datahandler.entitlement.LicenseModerator.java

public License updateLicenseFromModerationRequest(License license, License licenseAdditions,
        License licenseDeletions, String department) {
    Map<String, Todo> actualTodoMap = Maps.uniqueIndex(nullToEmptyList(license.getTodos()), Todo::getId);

    for (Todo added : nullToEmptyList(licenseAdditions.getTodos())) {
        if (!added.isSetId()) {
            log.error("Todo id not set in licenseAdditions.");
            continue;
        }/*w  w  w  .  j av a2s. c o m*/
        if (isTemporaryTodo(added)) {
            if (!license.isSetTodos()) {
                license.setTodos(new ArrayList<>());
            }
            license.getTodos().add(added);
        } else {
            Todo actual = actualTodoMap.get(added.getId());
            if (added.isSetWhitelist() && added.getWhitelist().contains(department)) {
                if (!actual.isSetWhitelist()) {
                    actual.setWhitelist(new HashSet<>());
                }
                actual.getWhitelist().add(department);
            }
        }
    }
    for (Todo deleted : nullToEmptyList(licenseDeletions.getTodos())) {
        if (!deleted.isSetId()) {
            log.error("Todo id is not set in licenseDeletions.");
            continue;
        }
        Todo actual = actualTodoMap.get(deleted.getId());
        if (actual == null) {
            log.info("Todo from licenseDeletions does not exist (any more) in license.");
            continue;
        }
        if (deleted.isSetWhitelist() && deleted.getWhitelist().contains(department)) {
            if (actual.isSetWhitelist() && actual.getWhitelist().contains(department)) {
                actual.getWhitelist().remove(department);
            }
        }
    }
    return license;
}