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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
@Beta
public static <K extends Enum<K>, V> ImmutableMap<K, V> immutableEnumMap(Map<K, ? extends V> map) 

Source Link

Document

Returns an immutable map instance containing the given entries.

Usage

From source file:com.google.idea.blaze.base.run.smrunner.BlazeCompositeTestEventsHandler.java

private static ImmutableMap<Kind, BlazeTestEventsHandler> collectHandlers() {
    Map<Kind, BlazeTestEventsHandler> map = new HashMap<>();
    for (BlazeTestEventsHandler handler : BlazeTestEventsHandler.EP_NAME.getExtensions()) {
        if (handler instanceof BlazeCompositeTestEventsHandler) {
            continue;
        }/*from w w w.ja  va2s  .  c  om*/
        for (Kind kind : handler.handledKinds()) {
            // earlier handlers get priority.
            map.putIfAbsent(kind, handler);
        }
    }
    return Maps.immutableEnumMap(map);
}

From source file:com.lyndir.omicron.api.ImmutableResourceCost.java

protected ImmutableResourceCost(final Map<ResourceType, Integer> resourceQuantities) {
    this.resourceQuantities = Maps.immutableEnumMap(resourceQuantities);
}

From source file:org.mondo.collaboration.security.lens.arbiter.AccessControlVerdict.java

private static Map<RuleRights, Map<OperationKind, AccessControlVerdict>> buildRegularInterpretations(
        AccessControlVerdict verdict) {//from w ww .jav  a  2  s .c  o m
    return Maps.immutableEnumMap(ImmutableMap.<RuleRights, Map<OperationKind, AccessControlVerdict>>of(
            RuleRights.READ, Maps.immutableEnumMap(ImmutableMap.of(OperationKind.READ, verdict)),
            RuleRights.WRITE, Maps.immutableEnumMap(ImmutableMap.of(OperationKind.WRITE, verdict)),
            RuleRights.READ_WRITE,
            Maps.immutableEnumMap(ImmutableMap.of(OperationKind.READ, verdict, OperationKind.WRITE, verdict))));
}

From source file:com.torodb.mongodb.repl.ReplMetrics.java

@Inject
public ReplMetrics(ToroMetricRegistry parentRegistry) {
    ToroMetricRegistry registry = parentRegistry.createSubRegistry("Repl");
    memberState = registry.gauge("currentMemberState");
    ImmutableMap.Builder<MemberState, Counter> memberStateCountersBuilder = ImmutableMap.builder();
    for (MemberState memberState : MemberState.values()) {
        memberStateCountersBuilder.put(memberState,
                registry.counter(memberState.name().substring(3).toLowerCase(Locale.US) + "Count"));
    }//from   w w  w. ja  v a 2  s.c  o m
    memberStateCounters = Maps.immutableEnumMap(memberStateCountersBuilder.build());
    lastOpTimeFetched = registry.gauge("lastOpTimeFetched");
    lastOpTimeApplied = registry.gauge("lastOpTimeApplied");
}

From source file:com.torodb.backend.AbstractIdentifierConstraints.java

protected AbstractIdentifierConstraints(ImmutableSet<String> restrictedSchemaNames,
        ImmutableSet<String> restrictedColumnNames) {
    this.fieldTypeIdentifiers = Maps
            .immutableEnumMap(ImmutableMap.<FieldType, Character>builder().put(FieldType.BINARY, 'r') // [r]aw bytes
                    .put(FieldType.BOOLEAN, 'b') // [b]oolean
                    .put(FieldType.DOUBLE, 'd') // [d]ouble float
                    .put(FieldType.INSTANT, 't') // [t]imestamp
                    .put(FieldType.INTEGER, 'i') // [i]nteger
                    .put(FieldType.LONG, 'l') // [l]ong
                    .put(FieldType.DECIMAL128, 'q') // [q]uad float
                    .put(FieldType.NULL, 'n') // [n]ull
                    .put(FieldType.STRING, 's') // [s]tring
                    .put(FieldType.CHILD, 'e') // child [e]lement

                    // Mongo types
                    .put(FieldType.MONGO_OBJECT_ID, 'x').put(FieldType.MONGO_TIME_STAMP, 'y')
                    // No-Mongo types
                    .put(FieldType.DATE, 'c') // [c]alendar
                    .put(FieldType.TIME, 'm') // ti[m]e
                    .put(FieldType.JAVASCRIPT, 'j') // [j]avascript
                    .put(FieldType.JAVASCRIPT_WITH_SCOPE, 'w') // javascript [w]ith scope
                    .put(FieldType.MIN_KEY, 'k') //min [k]ey
                    .put(FieldType.MAX_KEY, 'a') //m[a]x key
                    .put(FieldType.UNDEFINED, 'u') //[u]ndefined
                    .put(FieldType.MONGO_REGEX, 'g') //Re[g]Ex
                    .put(FieldType.MONGO_DB_POINTER, 'p') //DB [p]ointer
                    .put(FieldType.DEPRECATED, 'z') //running out of available chars; z means "the last".
                    .build());/*from w  w w  .j av  a 2  s .c o m*/
    //Letters left: f h o v
    ImmutableMap.Builder<FieldType, String> scalarFieldTypeIdentifiersBuilder = ImmutableMap
            .<FieldType, String>builder();
    Set<Character> fieldTypeIdentifierSet = new HashSet<>();
    for (FieldType fieldType : FieldType.values()) {
        if (!this.fieldTypeIdentifiers.containsKey(fieldType)) {
            throw new SystemException("FieldType " + fieldType + " has not been mapped to an identifier.");
        }

        char identifier = this.fieldTypeIdentifiers.get(fieldType);

        if ((identifier < 'a' || identifier > 'z') && (identifier < '0' || identifier > '9')) {
            throw new SystemException("FieldType " + fieldType + " has an unallowed identifier " + identifier);
        }

        if (fieldTypeIdentifierSet.contains(identifier)) {
            throw new SystemException(
                    "FieldType " + fieldType + " identifier " + identifier + " was used by another FieldType.");
        }

        fieldTypeIdentifierSet.add(identifier);

        scalarFieldTypeIdentifiersBuilder.put(fieldType,
                DocPartTableFields.SCALAR.fieldName + SEPARATOR + identifier);
    }

    this.scalarFieldTypeIdentifiers = Maps.immutableEnumMap(scalarFieldTypeIdentifiersBuilder.build());

    this.restrictedSchemaNames = ImmutableSet.<String>builder().add(TorodbSchema.IDENTIFIER)
            .addAll(restrictedSchemaNames).build();

    this.restrictedColumnNames = ImmutableSet.<String>builder().add(DocPartTableFields.DID.fieldName)
            .add(DocPartTableFields.RID.fieldName).add(DocPartTableFields.PID.fieldName)
            .add(DocPartTableFields.SEQ.fieldName).addAll(scalarFieldTypeIdentifiers.values())
            .addAll(restrictedColumnNames).build();
}

From source file:fr.javatronic.damapping.toolkit.enums.StringEnumMapperMaps.java

/**
 * Creates a new instance of StringEnumMapperMaps which backing maps will be populated from the result of the
 * specified BijectiveTransformer.//from ww w.  j a  va2  s. c  o  m
 *
 * @param clazz                an enum type class
 * @param bijectiveTransformer a {@link fr.javatronic.damapping.toolkit.enums.BijectiveTransformer}
 */
public StringEnumMapperMaps(@Nonnull Class<E> clazz, @Nonnull BijectiveTransformer<E> bijectiveTransformer) {
    EnumMap<E, String> enumStrMap = Maps.newEnumMap(clazz);
    ImmutableMap.Builder<String, E> strEnumBuilder = ImmutableMap.builder();
    for (E enumConstant : clazz.getEnumConstants()) {
        String str = requireNonNull(bijectiveTransformer.apply(enumConstant),
                "String representation of value " + enumConstant + " can not be null");
        enumStrMap.put(enumConstant, str);
        strEnumBuilder.put(str, enumConstant);
    }
    this.enumToString = Maps.immutableEnumMap(enumStrMap);
    this.stringToEnum = strEnumBuilder.build();
}

From source file:fr.javatronic.damapping.toolkit.enums.StringEnumMapperMaps.java

@Nonnull
private ImmutableMap<E, String> exceptEnumMap(E enumValue, @Nullable String str) {
    EnumMap<E, String> enumMap = Maps.newEnumMap(this.enumToString);
    if (str == null) {
        enumMap.remove(enumValue);/*ww w.j a  v  a2 s  .  c  o  m*/
    } else {
        enumMap.put(enumValue, str);
    }
    return Maps.immutableEnumMap(enumMap);
}

From source file:com.linecorp.armeria.server.thrift.THttpService.java

private static Map<SerializationFormat, ThreadLocalTProtocol> createFormatToThreadLocalTProtocolMap() {
    return Maps.immutableEnumMap(SerializationFormat.ofThrift().stream().collect(Collectors
            .toMap(Function.identity(), f -> new ThreadLocalTProtocol(ThriftProtocolFactories.get(f)))));
}