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:edu.wisc.hr.dm.person.AbstractPersonInformation.java

public final Map<Integer, Job> getJobMap() {
    final List<Job> jobs = getJobs();
    return Maps.uniqueIndex(jobs, new Function<Job, Integer>() {
        public Integer apply(Job input) {
            return input.getId();
        }//from w  w  w  .  j  a v  a  2  s . c o m
    });
}

From source file:org.mule.raml.impl.v08.model.MimeTypeImpl.java

@Override
public Map<String, TypeFieldDefinition> getFormParameters() {

    return Maps.uniqueIndex(Lists.transform(bodyLike.formParameters(),
            new Function<org.raml.v2.api.model.v08.parameters.Parameter, TypeFieldDefinition>() {
                @Nullable/*from   w  w  w. j av a  2 s  .c om*/
                @Override
                public TypeFieldDefinition apply(
                        @Nullable org.raml.v2.api.model.v08.parameters.Parameter input) {
                    return new ParameterImpl(input);
                }
            }), new Function<TypeFieldDefinition, String>() {
                @Nullable
                @Override
                public String apply(@Nullable TypeFieldDefinition input) {
                    return input.getName();
                }
            });
}

From source file:org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotterRegistry.java

public DefaultFileCollectionSnapshotterRegistry(Collection<FileCollectionSnapshotter> snapshotters) {
    this.snapshotters = ImmutableMap
            .copyOf(Maps.uniqueIndex(snapshotters, new Function<FileCollectionSnapshotter, Class<?>>() {
                @Override/*from  w w w. j  av  a 2 s.c  o  m*/
                public Class<?> apply(FileCollectionSnapshotter snapshotter) {
                    Class<? extends FileCollectionSnapshotter> registeredType = snapshotter.getRegisteredType();
                    Class<? extends FileCollectionSnapshotter> type = snapshotter.getClass();
                    if (!registeredType.isAssignableFrom(type)) {
                        throw new IllegalArgumentException(String.format(
                                "Snapshotter registered type '%s' must be a super-type of the actual snapshotter type '%s'",
                                registeredType.getName(), type.getName()));
                    }
                    return registeredType;
                }
            }));
}

From source file:com.atlassian.jira.functest.framework.backdoor.LicenseRoleControl.java

public Map<String, LicenseRoleBean> getRolesMap() {
    return Maps.uniqueIndex(getRoles(), LicenseRoleBean.GET_ID);
}

From source file:de.brands4friends.daleq.core.ImmutableRowData.java

public ImmutableRowData(final List<FieldData> fields) {
    this.fields = ImmutableList.copyOf(Preconditions.checkNotNull(fields));
    this.index = Maps.uniqueIndex(this.fields, new Function<FieldData, String>() {
        @Override/*w  w w.  j  a  v a 2 s.  c o  m*/
        public String apply(@Nullable final FieldData field) {
            if (field == null) {
                return null;
            }
            return field.getName();
        }
    });
}

From source file:org.apache.aurora.common.args.parsers.UnitParser.java

public UnitParser() {
    unitValues = Maps.uniqueIndex(
            ImmutableList.<Unit<?>>builder().add(Time.values()).add(Data.values()).build(),
            Functions.toStringFunction());
}

From source file:org.gradle.internal.fingerprint.impl.DefaultFileCollectionFingerprinterRegistry.java

public DefaultFileCollectionFingerprinterRegistry(Collection<FileCollectionFingerprinter> fingerprinters) {
    this.fingerprinters = ImmutableMap.copyOf(Maps.uniqueIndex(fingerprinters,
            new Function<FileCollectionFingerprinter, Class<? extends FileNormalizer>>() {
                @Override//  w ww . j a va 2 s  .c o m
                public Class<? extends FileNormalizer> apply(FileCollectionFingerprinter fingerprinter) {
                    return fingerprinter.getRegisteredType();
                }
            }));
}

From source file:de.brands4friends.daleq.core.internal.types.TableTypeImpl.java

TableTypeImpl(final String name, final List<FieldType> fields) {
    this.name = name;
    this.fields = fields;
    this.lookupByDef = Maps.uniqueIndex(fields, new Function<FieldType, FieldTypeReference>() {
        @Override/*w ww . j av a 2s  .com*/
        public FieldTypeReference apply(@Nullable final FieldType input) {
            if (input == null) {
                throw new IllegalArgumentException("input");
            }
            return input.getOrigin();
        }
    });
}

From source file:org.obm.push.utils.index.IndexUtils.java

public static <T extends Number, I extends Indexed<T>, C extends Collection<I>> Map<T, I> mapByIndexes(
        C objects) {/*w w  w  . j  a v a2  s  . co  m*/

    return Maps.uniqueIndex(objects, new Function<I, T>() {

        @Override
        public T apply(I input) {
            return input.getIndex();
        }
    });
}

From source file:at.ac.univie.isc.asio.engine.FixedSelection.java

private FixedSelection(final Iterable<Engine> engines) {
    candidates = Maps.uniqueIndex(engines, GET_LANGUAGE);
}