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

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

Introduction

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

Prototype

public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(Map<K, ? extends V> map) 

Source Link

Document

Creates an EnumMap with the same mappings as the specified map.

Usage

From source file:org.kuali.rice.xml.config.spring.RiceXmlConfig.java

/**
 * Generates the default mapping of excluded paths.
 *
 * @return the map of excluded paths//from  w w w  .ja  v  a  2s .com
 */
protected Map<MetaInfGroup, String> getDefaultExcludes() {
    Map<MetaInfGroup, String> defaultExcludes = Maps.newEnumMap(MetaInfGroup.class);

    defaultExcludes.put(MetaInfGroup.OTHER, NullUtils.NONE);

    return defaultExcludes;
}

From source file:org.terasology.world.block.internal.BlockBuilder.java

private BlockAppearance createAppearance(BlockShape shape, Map<BlockPart, BlockTile> tiles, Rotation rot) {
    Map<BlockPart, BlockMeshPart> meshParts = Maps.newEnumMap(BlockPart.class);
    Map<BlockPart, Vector2f> textureAtlasPositions = Maps.newEnumMap(BlockPart.class);
    for (BlockPart part : BlockPart.values()) {
        // TODO: Need to be more sensible with the texture atlas. Because things like block particles read from a part that may not exist, we're being fairly lenient
        Vector2f atlasPos;/*from w ww . j  av a  2  s .co m*/
        if (tiles.get(part) == null) {
            atlasPos = new Vector2f();
        } else {
            atlasPos = worldAtlas.getTexCoords(tiles.get(part), shape.getMeshPart(part) != null);
        }
        BlockPart targetPart = part.rotate(rot);
        textureAtlasPositions.put(targetPart, atlasPos);
        if (shape.getMeshPart(part) != null) {
            meshParts.put(targetPart, shape.getMeshPart(part).rotate(rot.getQuat4f()).mapTexCoords(atlasPos,
                    worldAtlas.getRelativeTileSize()));
        }
    }
    return new BlockAppearance(meshParts, textureAtlasPositions);
}

From source file:com.google.gcloud.resourcemanager.ResourceManagerImpl.java

private Map<ResourceManagerRpc.Option, ?> optionMap(Option... options) {
    Map<ResourceManagerRpc.Option, Object> temp = Maps.newEnumMap(ResourceManagerRpc.Option.class);
    for (Option option : options) {
        Object prev = temp.put(option.rpcOption(), option.value());
        checkArgument(prev == null, "Duplicate option %s", option);
    }/*w w  w  .  j  a  v  a  2 s. co  m*/
    return ImmutableMap.copyOf(temp);
}

From source file:org.kiji.commons.FromJson.java

/**
 * Decodes a union from a JSON node./*from   w w  w. j a  v  a  2s . c  o  m*/
 *
 * @param json   JSON node to decode.
 * @param schema Avro schema of the union value to decode.
 * @return the decoded value.
 * @throws IOException on error.
 */
private static Object fromUnionJsonNode(JsonNode json, Schema schema) throws IOException {
    Preconditions.checkArgument(schema.getType() == Schema.Type.UNION);

    try {
        final Schema optionalType = AvroUtils.getOptionalType(schema);
        if (optionalType != null) {
            return json.isNull() ? null : fromJsonNode(json, optionalType);
        }
    } catch (IOException ioe) {
        // Union value may be wrapped, ignore.
    }

    /** Map from Avro schema type to list of schemas of this type in the union. */
    final Map<Schema.Type, List<Schema>> typeMap = Maps.newEnumMap(Schema.Type.class);
    for (Schema type : schema.getTypes()) {
        List<Schema> types = typeMap.get(type.getType());
        if (null == types) {
            types = Lists.newArrayList();
            typeMap.put(type.getType(), types);
        }
        types.add(type);
    }

    if (json.isObject() && (json.size() == 1)) {
        final Map.Entry<String, JsonNode> entry = json.fields().next();
        final String typeName = entry.getKey();
        final JsonNode actualNode = entry.getValue();

        for (Schema type : schema.getTypes()) {
            if (type.getFullName().equals(typeName)) {
                return fromJsonNode(actualNode, type);
            }
        }
    }

    for (Schema type : schema.getTypes()) {
        try {
            return fromJsonNode(json, type);
        } catch (IOException ioe) {
            // Wrong union type case.
        }
    }

    throw new IOException(String.format("Unable to decode JSON '%s' for union '%s'.", json, schema));
}

From source file:com.moz.fiji.schema.util.FromJson.java

/**
 * Decodes a union from a JSON node./*from   w w  w .j a  v a  2s . co m*/
 *
 * @param json JSON node to decode.
 * @param schema Avro schema of the union value to decode.
 * @return the decoded value.
 * @throws IOException on error.
 */
private static Object fromUnionJsonNode(JsonNode json, Schema schema) throws IOException {
    Preconditions.checkArgument(schema.getType() == Schema.Type.UNION);

    try {
        final Schema optionalType = AvroUtils.getOptionalType(schema);
        if (optionalType != null) {
            return json.isNull() ? null : fromJsonNode(json, optionalType);
        }
    } catch (IOException ioe) {
        // Union value may be wrapped, ignore.
    }

    /** Map from Avro schema type to list of schemas of this type in the union. */
    final Map<Schema.Type, List<Schema>> typeMap = Maps.newEnumMap(Schema.Type.class);
    for (Schema type : schema.getTypes()) {
        List<Schema> types = typeMap.get(type.getType());
        if (null == types) {
            types = Lists.newArrayList();
            typeMap.put(type.getType(), types);
        }
        types.add(type);
    }

    if (json.isObject() && (json.size() == 1)) {
        final Map.Entry<String, JsonNode> entry = json.getFields().next();
        final String typeName = entry.getKey();
        final JsonNode actualNode = entry.getValue();

        for (Schema type : schema.getTypes()) {
            if (type.getFullName().equals(typeName)) {
                return fromJsonNode(actualNode, type);
            }
        }
    }

    for (Schema type : schema.getTypes()) {
        try {
            return fromJsonNode(json, type);
        } catch (IOException ioe) {
            // Wrong union type case.
        }
    }

    throw new IOException(String.format("Unable to decode JSON '%s' for union '%s'.", json, schema));
}

From source file:cpw.mods.fml.common.network.NetworkRegistry.java

/**
 * INTERNAL Create a new channel pair with the specified name and channel handlers.
 * This is used internally in forge and FML
 *
 * @param container The container to associate the channel with
 * @param name The name for the channel/*w ww.  j av  a  2  s  .  c om*/
 * @param handlers Some {@link ChannelHandler} for the channel
 * @return an {@link EnumMap} of the pair of channels. keys are {@link Side}. There will always be two entries.
 */
public EnumMap<Side, FMLEmbeddedChannel> newChannel(ModContainer container, String name,
        ChannelHandler... handlers) {
    if (channels.containsKey(name) || name.startsWith("MC|") || name.startsWith("\u0001")
            || (name.startsWith("FML") && !("FML".equals(container.getModId())))) {
        throw new RuntimeException("That channel is already registered");
    }
    EnumMap<Side, FMLEmbeddedChannel> result = Maps.newEnumMap(Side.class);

    for (Side side : Side.values()) {
        FMLEmbeddedChannel channel = new FMLEmbeddedChannel(container, name, side, handlers);
        channels.get(side).put(name, channel);
        result.put(side, channel);
    }
    return result;
}

From source file:net.minecraftforge.fml.common.network.NetworkRegistry.java

/**
 * INTERNAL Create a new channel pair with the specified name and channel handlers.
 * This is used internally in forge and FML
 *
 * @param container The container to associate the channel with
 * @param name The name for the channel/*from   www.  j av a  2  s  . c o m*/
 * @param handlers Some {@link ChannelHandler} for the channel
 * @return an {@link EnumMap} of the pair of channels. keys are {@link Side}. There will always be two entries.
 */
public EnumMap<Side, FMLEmbeddedChannel> newChannel(ModContainer container, String name,
        ChannelHandler... handlers) {
    if (channels.get(Side.CLIENT).containsKey(name) || channels.get(Side.SERVER).containsKey(name)
            || name.startsWith("MC|") || name.startsWith("\u0001")
            || (name.startsWith("FML") && !("FML".equals(container.getModId())))) {
        throw new RuntimeException("That channel is already registered");
    }
    EnumMap<Side, FMLEmbeddedChannel> result = Maps.newEnumMap(Side.class);

    for (Side side : Side.values()) {
        FMLEmbeddedChannel channel = new FMLEmbeddedChannel(container, name, side, handlers);
        channels.get(side).put(name, channel);
        result.put(side, channel);
    }
    return result;
}

From source file:org.terasology.world.block.loader.BlockLoader.java

public BlockFamily loadWithShape(BlockUri uri) {
    BlockShape shape = cubeShape;//from   www.  j  a va 2  s.c  o m
    if (uri.hasShape()) {
        AssetUri shapeUri = uri.getShapeUri();
        if (!shapeUri.isValid()) {
            return null;
        }
        shape = (BlockShape) Assets.get(shapeUri);
        if (shape == null) {
            return null;
        }
    }
    AssetUri blockDefUri = new AssetUri(AssetType.BLOCK_DEFINITION, uri.getPackage(), uri.getFamily());
    BlockDefinition def;
    if (AssetManager.getInstance().getAssetURLs(blockDefUri).isEmpty()) {
        // An auto-block
        def = new BlockDefinition();
    } else {
        def = loadBlockDefinition(inheritData(blockDefUri, readJson(blockDefUri).getAsJsonObject()));
    }

    def.shape = (shape.getURI().getSimpleString());
    if (shape.isCollisionSymmetric()) {
        Block block = constructSingleBlock(blockDefUri, def);
        return new SymmetricFamily(uri, block, getCategories(def));
    } else {
        Map<Side, Block> blockMap = Maps.newEnumMap(Side.class);
        constructHorizontalBlocks(blockDefUri, def, blockMap);
        return new HorizontalBlockFamily(uri, blockMap, getCategories(def));
    }
}

From source file:se.toxbee.sleepfighter.model.challenge.ChallengeConfigSet.java

/**
 * Constructs a config set with no challenges initially put in.<br/>
 * It is expected that every ChallengeConfigSet will bind all ChallengeType:s to a corresponding ChallengeConfig,<br/>
 * this constructor must be therefore be followed by a series of {@link #putChallenge(ChallengeConfig)} calls.
 *///ww w . ja  v a 2 s  .c o  m
public ChallengeConfigSet() {
    this.challenges = Maps.newEnumMap(ChallengeType.class);
}

From source file:org.apache.hadoop.hdfs.server.namenode.AclTransformation.java

/**
 * Completely replaces the ACL with the entries of the ACL spec.  If
 * necessary, recalculates the mask entries.  If necessary, default entries
 * are inferred by copying the permissions of the corresponding access
 * entries.  Replacement occurs separately for each of the access ACL and the
 * default ACL.  If the ACL spec contains only access entries, then the
 * existing default entries are retained.  If the ACL spec contains only
 * default entries, then the existing access entries are retained.  If the ACL
 * spec contains both access and default entries, then both are replaced.
 *
 * @param existingAcl List<AclEntry> existing ACL
 * @param inAclSpec List<AclEntry> ACL spec containing replacement entries
 * @return List<AclEntry> new ACL/* w w w. j a v  a2 s .c  o m*/
 * @throws AclException if validation fails
 */
public static List<AclEntry> replaceAclEntries(List<AclEntry> existingAcl, List<AclEntry> inAclSpec)
        throws AclException {
    ValidatedAclSpec aclSpec = new ValidatedAclSpec(inAclSpec);
    ArrayList<AclEntry> aclBuilder = Lists.newArrayListWithCapacity(MAX_ENTRIES);
    // Replacement is done separately for each scope: access and default.
    EnumMap<AclEntryScope, AclEntry> providedMask = Maps.newEnumMap(AclEntryScope.class);
    EnumSet<AclEntryScope> maskDirty = EnumSet.noneOf(AclEntryScope.class);
    EnumSet<AclEntryScope> scopeDirty = EnumSet.noneOf(AclEntryScope.class);
    for (AclEntry aclSpecEntry : aclSpec) {
        scopeDirty.add(aclSpecEntry.getScope());
        if (aclSpecEntry.getType() == MASK) {
            providedMask.put(aclSpecEntry.getScope(), aclSpecEntry);
            maskDirty.add(aclSpecEntry.getScope());
        } else {
            aclBuilder.add(aclSpecEntry);
        }
    }
    // Copy existing entries if the scope was not replaced.
    for (AclEntry existingEntry : existingAcl) {
        if (!scopeDirty.contains(existingEntry.getScope())) {
            if (existingEntry.getType() == MASK) {
                providedMask.put(existingEntry.getScope(), existingEntry);
            } else {
                aclBuilder.add(existingEntry);
            }
        }
    }
    copyDefaultsIfNeeded(aclBuilder);
    calculateMasks(aclBuilder, providedMask, maskDirty, scopeDirty);
    return buildAndValidateAcl(aclBuilder);
}