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:eagle.security.auditlog.timer.IPZonePollingJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
    try {//from   ww w .  java 2 s.com
        List<IPZoneEntity> ipZones = load(jobDataMap);
        if (ipZones == null) {
            LOG.warn("Ipzone information is empty");
            return;
        }
        Map<String, IPZoneEntity> map = Maps.uniqueIndex(ipZones, new Function<IPZoneEntity, String>() {
            @Override
            public String apply(IPZoneEntity input) {
                return input.getTags().get("iphost");
            }
        });
        ExternalDataCache.getInstance().setJobResult(getClass(), map);
    } catch (Exception ex) {
        LOG.error("Fail loading ip zones data", ex);
    }
}

From source file:org.jclouds.cloudstack.suppliers.NetworksForCurrentUser.java

@Override
public Map<String, Network> get() {
    User currentUser = currentUserSupplier.get();
    NetworkClient networkClient = client.getNetworkClient();
    return Maps.uniqueIndex(
            networkClient.listNetworks(accountInDomain(currentUser.getAccount(), currentUser.getDomainId())),
            new Function<Network, String>() {

                @Override/*from  www.j  ava2 s .  c  o m*/
                public String apply(Network arg0) {
                    return arg0.getId();
                }
            });
}

From source file:ru.org.linux.poll.PollPrepareService.java

public PreparedPoll preparePollPreview(Poll newPoll) {
    final Map<Integer, PollVariantResult> currentMap;

    if (newPoll.getId() > 0) {
        currentMap = Maps.uniqueIndex(pollDao.getPollVariants(newPoll),
                new Function<PollVariantResult, Integer>() {
                    @Override/*from w w w  .ja  v a  2 s  .c  o  m*/
                    public Integer apply(PollVariantResult input) {
                        return input.getId();
                    }
                });
    } else {
        currentMap = ImmutableSortedMap.of();
    }

    List<PollVariantResult> variants = Lists.transform(newPoll.getVariants(),
            new Function<PollVariant, PollVariantResult>() {
                @Override
                public PollVariantResult apply(PollVariant input) {
                    PollVariantResult pollVariant = currentMap.get(input.getId());

                    if (pollVariant != null) {
                        return new PollVariantResult(input.getId(), input.getLabel(), pollVariant.getVotes(),
                                pollVariant.getUserVoted());
                    } else {
                        return new PollVariantResult(input.getId(), input.getLabel(), 0, false);
                    }
                }
            });

    return new PreparedPoll(newPoll, 0, variants);
}

From source file:org.opentestsystem.authoring.testauth.service.impl.SegmentHelper.java

protected static Map<String, Segment> createSegmentIdKeyMap(final List<Segment> segmentList) {
    return Maps.uniqueIndex(segmentList, new Function<Segment, String>() {
        @Override/*w  ww  .ja  v a2  s  . c  o  m*/
        public String apply(final Segment input) {
            return input.getId();
        }
    });
}

From source file:eagle.security.auditlog.timer.FileSensitivityPollingJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
    try {//from   ww  w .ja va  2s.  co m
        List<FileSensitivityAPIEntity> ipZones = load(jobDataMap);
        if (ipZones == null) {
            LOG.warn("File sensitivity information is empty");
            return;
        }
        Map<String, FileSensitivityAPIEntity> map = Maps.uniqueIndex(ipZones,
                new Function<FileSensitivityAPIEntity, String>() {
                    @Override
                    public String apply(FileSensitivityAPIEntity input) {
                        return input.getTags().get("filedir");
                    }
                });
        ExternalDataCache.getInstance().setJobResult(getClass(), map);
    } catch (Exception ex) {
        LOG.error("Fail loading file sensitivity data", ex);
    }
}

From source file:org.apache.aurora.scheduler.http.LeaderHealth.java

private static String generateHelpText() {
    Map<Integer, String> details = Maps
            .transformValues(Maps.uniqueIndex(RESPONSE_CODES.values(), Pair::getFirst), Pair::getSecond);

    return "This endpoint can indicate to a load balancer which among a group of schedulers "
            + "is leading.\n\nThe response codes are:\n"
            + Joiner.on("\n").withKeyValueSeparator(": ").join(details);
}

From source file:org.caleydo.view.bicluster.sorting.BandSortingStrategy.java

@Override
public List<IntFloat> apply(List<IntFloat> list) {
    List<Collection<Integer>> nonEmptyDimBands = new ArrayList<>();
    for (Edge edge : cluster.getOverlappingEdges(dim)) {
        nonEmptyDimBands.add(edge.getOverlapIndices(dim));
    }/*from  w ww  . j a  va 2s .c  o  m*/
    if (nonEmptyDimBands.isEmpty()) // early abort no bands nothing todo
        return list;

    BandSorting dimConflicts = new BandSorting(nonEmptyDimBands);

    Set<IntFloat> finalDimSorting = new LinkedHashSet<IntFloat>();

    ImmutableMap<Integer, IntFloat> byIndex = Maps.uniqueIndex(list, IntFloat.TO_INDEX);
    for (Integer i : dimConflicts) {
        finalDimSorting.add(byIndex.get(i));
    }
    // fill up rest
    finalDimSorting.addAll(list);
    return new ArrayList<>(finalDimSorting);
}

From source file:com.siemens.sw360.portal.users.UserCache.java

public UserCache() {
    // Initialize user loader
    UserLoader loader = new UserLoader();

    List<User> allUsers;/*from  w w  w.  ja v a 2 s.  c  om*/
    try {
        allUsers = loader.getAllUsers();
    } catch (TException ignored) {
        allUsers = Collections.emptyList();
    }

    // Initialize user cache
    cache = CacheBuilder.newBuilder().maximumSize(allUsers.size() + 100).expireAfterWrite(1, TimeUnit.DAYS)
            .build(loader);

    if (allUsers.size() > 0) {
        cache.putAll(Maps.uniqueIndex(allUsers, new Function<User, String>() {
            @Override
            public String apply(User input) {
                return input.getEmail();
            }
        }));
    }
}

From source file:org.gradle.model.internal.manage.schema.AbstractStructSchema.java

public AbstractStructSchema(ModelType<T> type, Iterable<ModelProperty<?>> properties,
        Iterable<WeaklyTypeReferencingMethod<?, ?>> nonPropertyMethods, Iterable<ModelSchemaAspect> aspects) {
    super(type);/*from www.  j  a  va  2  s  .c  o  m*/
    ImmutableSortedMap.Builder<String, ModelProperty<?>> builder = ImmutableSortedMap.naturalOrder();
    for (ModelProperty<?> property : properties) {
        builder.put(property.getName(), property);
    }
    this.properties = builder.build();
    this.nonPropertyMethods = ImmutableSet.copyOf(nonPropertyMethods);
    this.aspects = Maps.uniqueIndex(aspects,
            new Function<ModelSchemaAspect, Class<? extends ModelSchemaAspect>>() {
                @Override
                public Class<? extends ModelSchemaAspect> apply(ModelSchemaAspect aspect) {
                    return aspect.getClass();
                }
            });
}

From source file:org.apache.eagle.security.hbase.sensitivity.HbaseResourceSensitivityPollingJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
    try {/*from  w ww.ja  v  a 2 s  .  com*/
        List<HbaseResourceSensitivityAPIEntity> hbaseResourceSensitivity = load(jobDataMap,
                "HbaseResourceSensitivityService");
        if (hbaseResourceSensitivity == null) {
            LOG.warn("Hbase resource sensitivity information is empty");
            return;
        }
        Map<String, HbaseResourceSensitivityAPIEntity> map = Maps.uniqueIndex(hbaseResourceSensitivity,
                new Function<HbaseResourceSensitivityAPIEntity, String>() {
                    @Override
                    public String apply(HbaseResourceSensitivityAPIEntity input) {
                        return input.getTags().get("hbaseResource");
                    }
                });
        ExternalDataCache.getInstance().setJobResult(getClass(), map);
    } catch (Exception ex) {
        LOG.error("Fail to load hbase resource sensitivity data", ex);
    }
}