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:com.google.caliper.util.ShortDuration.java

private static Map<TimeUnit, Long> createMaxesMap() {
    Map<TimeUnit, Long> map = Maps.newEnumMap(TimeUnit.class);
    for (TimeUnit unit : TimeUnit.values()) {
        // Max is 100 days
        map.put(unit, unit.convert(100L * 24 * 60 * 60, TimeUnit.SECONDS));
    }/*from   w  w  w .j  av  a2  s .com*/
    return Collections.unmodifiableMap(map);
}

From source file:com.google.cloud.dns.DnsImpl.java

static Map<DnsRpc.Option, ?> optionMap(Option... options) {
    Map<DnsRpc.Option, Object> temp = Maps.newEnumMap(DnsRpc.Option.class);
    for (Option option : options) {
        Object prev = temp.put(option.getRpcOption(), option.getValue());
        checkArgument(prev == null, "Duplicate option %s", option);
    }//from  w w  w .j  a va  2 s  . c o  m
    return ImmutableMap.copyOf(temp);
}

From source file:lombok.ast.ecj.EcjTreeConverter.java

private Node toTree(ASTNode node, FlagKey... keys) {
    Map<FlagKey, Object> map = Maps.newEnumMap(FlagKey.class);
    for (FlagKey key : keys)
        map.put(key, key);//from w  w  w.ja  v a  2 s. com
    return toTree(node, map);
}

From source file:com.android.ide.common.res2.AbstractResourceRepository.java

/**
 * Returns the resources values matching a given {@link FolderConfiguration}.
 *
 * @param referenceConfig the configuration that each value must match.
 * @return a map with guaranteed to contain an entry for each {@link ResourceType}
 *//*w w  w  . j a v  a  2  s  .  c o m*/
@NonNull
public Map<ResourceType, Map<String, ResourceValue>> getConfiguredResources(
        @NonNull FolderConfiguration referenceConfig) {
    Map<ResourceType, Map<String, ResourceValue>> map = Maps.newEnumMap(ResourceType.class);

    synchronized (ITEM_MAP_LOCK) {
        Map<ResourceType, ListMultimap<String, ResourceItem>> itemMap = getMap();
        for (ResourceType key : ResourceType.values()) {
            // get the local results and put them in the map
            map.put(key, getConfiguredResources(itemMap, key, referenceConfig));
        }
    }

    return map;
}

From source file:org.terasology.rendering.primitives.ChunkTessellator.java

private void generateBlockVertices(ChunkView view, ChunkMesh mesh, int x, int y, int z, Biome biome) {
    Block block = view.getBlock(x, y, z);

    // TODO: Needs review - too much hardcoded special cases and corner cases resulting from this.
    ChunkVertexFlag vertexFlag = ChunkVertexFlag.NORMAL;
    if (block.isWater()) {
        vertexFlag = ChunkVertexFlag.WATER;
    } else if (block.isLava()) {
        vertexFlag = ChunkVertexFlag.LAVA;
    } else if (block.isWaving() && block.isDoubleSided()) {
        vertexFlag = ChunkVertexFlag.WAVING;
    } else if (block.isWaving()) {
        vertexFlag = ChunkVertexFlag.WAVING_BLOCK;
    }/*from w w w  . ja  va  2 s .c o  m*/

    // Gather adjacent blocks
    Map<Side, Block> adjacentBlocks = Maps.newEnumMap(Side.class);
    for (Side side : Side.values()) {
        Vector3i offset = side.getVector3i();
        Block blockToCheck = view.getBlock(x + offset.x, y + offset.y, z + offset.z);
        adjacentBlocks.put(side, blockToCheck);
    }

    BlockAppearance blockAppearance = block.getAppearance(adjacentBlocks);

    /*
     * Determine the render process.
     */
    ChunkMesh.RenderType renderType = ChunkMesh.RenderType.TRANSLUCENT;

    if (!block.isTranslucent()) {
        renderType = ChunkMesh.RenderType.OPAQUE;
    }
    // TODO: Review special case, or alternatively compare uris.
    if (block.isWater() || block.isIce()) {
        renderType = ChunkMesh.RenderType.WATER_AND_ICE;
    }
    if (block.isDoubleSided()) {
        renderType = ChunkMesh.RenderType.BILLBOARD;
    }

    if (blockAppearance.getPart(BlockPart.CENTER) != null) {
        Vector4f colorOffset = block.calcColorOffsetFor(BlockPart.CENTER, biome);
        blockAppearance.getPart(BlockPart.CENTER).appendTo(mesh, x, y, z, colorOffset, renderType, vertexFlag);
    }

    boolean[] drawDir = new boolean[6];

    for (Side side : Side.values()) {
        drawDir[side.ordinal()] = blockAppearance.getPart(BlockPart.fromSide(side)) != null
                && isSideVisibleForBlockTypes(adjacentBlocks.get(side), block, side);
    }

    // If the block is lowered, some more faces may have to be drawn
    if (block.isLiquid()) {
        Block bottomBlock = adjacentBlocks.get(Side.BOTTOM);
        // Draw horizontal sides if visible from below
        for (Side side : Side.horizontalSides()) {
            Vector3i offset = side.getVector3i();
            Block adjacentBelow = view.getBlock(x + offset.x, y - 1, z + offset.z);
            Block adjacent = adjacentBlocks.get(side);

            boolean visible = (blockAppearance.getPart(BlockPart.fromSide(side)) != null
                    && isSideVisibleForBlockTypes(adjacentBelow, block, side)
                    && !isSideVisibleForBlockTypes(bottomBlock, adjacent, side.reverse()));
            drawDir[side.ordinal()] |= visible;
        }

        // Draw the top if below a non-lowered block
        // TODO: Don't need to render the top if each side and the block above each side are either liquid or opaque solids.
        Block blockToCheck = adjacentBlocks.get(Side.TOP);
        drawDir[Side.TOP.ordinal()] |= !blockToCheck.isLiquid();

        if (bottomBlock.isLiquid() || bottomBlock.isInvisible()) {
            for (Side dir : Side.values()) {
                if (drawDir[dir.ordinal()]) {
                    Vector4f colorOffset = block.calcColorOffsetFor(BlockPart.fromSide(dir), biome);
                    block.getLoweredLiquidMesh(dir).appendTo(mesh, x, y, z, colorOffset, renderType,
                            vertexFlag);
                }
            }
            return;
        }
    }

    for (Side dir : Side.values()) {
        if (drawDir[dir.ordinal()]) {
            Vector4f colorOffset = block.calcColorOffsetFor(BlockPart.fromSide(dir), biome);
            // TODO: Needs review since the new per-vertex flags introduce a lot of special scenarios - probably a per-side setting?
            if (block.isGrass() && dir != Side.TOP && dir != Side.BOTTOM) {
                blockAppearance.getPart(BlockPart.fromSide(dir)).appendTo(mesh, x, y, z, colorOffset,
                        renderType, ChunkVertexFlag.COLOR_MASK);
            } else {
                blockAppearance.getPart(BlockPart.fromSide(dir)).appendTo(mesh, x, y, z, colorOffset,
                        renderType, vertexFlag);
            }
        }
    }
}

From source file:lombok.ast.ecj.EcjTreeConverter.java

private void fillList(ASTNode[] nodes, RawListAccessor<?, ?> list, FlagKey... keys) {
    Map<FlagKey, Object> map = Maps.newEnumMap(FlagKey.class);
    for (FlagKey key : keys)
        map.put(key, key);//from w w w.  ja  v a  2 s.  co  m
    fillList(nodes, list, map);
}

From source file:com.techcavern.pircbotz.UserChannelDao.java

@Synchronized("accessLock")
public UserChannelDaoSnapshot createSnapshot() {
    //Create snapshots of all users and channels
    ImmutableMap.Builder<U, UserSnapshot> userSnapshotBuilder = ImmutableMap.builder();
    for (U curUser : userNickMap.values())
        userSnapshotBuilder.put(curUser, curUser.createSnapshot());
    ImmutableMap<U, UserSnapshot> userSnapshotMap = userSnapshotBuilder.build();
    ImmutableMap.Builder<C, ChannelSnapshot> channelSnapshotBuilder = ImmutableMap.builder();
    for (C curChannel : channelNameMap.values())
        channelSnapshotBuilder.put(curChannel, curChannel.createSnapshot());
    ImmutableMap<C, ChannelSnapshot> channelSnapshotMap = channelSnapshotBuilder.build();

    //Make snapshots of the relationship maps using the above user and channel snapshots
    UserChannelMapSnapshot mainMapSnapshot = mainMap.createSnapshot(userSnapshotMap, channelSnapshotMap);
    EnumMap<UserLevel, UserChannelMap<UserSnapshot, ChannelSnapshot>> levelsMapSnapshot = Maps
            .newEnumMap(UserLevel.class);
    for (Map.Entry<UserLevel, UserChannelMap<U, C>> curLevel : levelsMap.entrySet())
        levelsMapSnapshot.put(curLevel.getKey(),
                curLevel.getValue().createSnapshot(userSnapshotMap, channelSnapshotMap));
    ImmutableBiMap.Builder<String, UserSnapshot> userNickMapSnapshotBuilder = ImmutableBiMap.builder();
    for (Map.Entry<String, U> curNick : userNickMap.entrySet())
        userNickMapSnapshotBuilder.put(curNick.getKey(), curNick.getValue().createSnapshot());
    ImmutableBiMap.Builder<String, ChannelSnapshot> channelNameMapSnapshotBuilder = ImmutableBiMap.builder();
    for (Map.Entry<String, C> curName : channelNameMap.entrySet())
        channelNameMapSnapshotBuilder.put(curName.getKey(), curName.getValue().createSnapshot());
    ImmutableSortedSet.Builder<UserSnapshot> privateUserSnapshotBuilder = ImmutableSortedSet.naturalOrder();
    for (User curUser : privateUsers)
        privateUserSnapshotBuilder.add(curUser.createSnapshot());

    //Finally can create the snapshot object
    UserChannelDaoSnapshot daoSnapshot = new UserChannelDaoSnapshot(bot, locale, mainMapSnapshot,
            levelsMapSnapshot, userNickMapSnapshotBuilder.build(), channelNameMapSnapshotBuilder.build(),
            privateUserSnapshotBuilder.build());

    //Tell UserSnapshots and ChannelSnapshots what the new backing dao is
    for (UserSnapshot curUserSnapshot : userSnapshotMap.values())
        curUserSnapshot.setDao(daoSnapshot);
    for (ChannelSnapshot curChannelSnapshot : channelSnapshotMap.values())
        curChannelSnapshot.setDao(daoSnapshot);

    //Finally//ww w. ja v a 2  s  . c o m
    return daoSnapshot;
}

From source file:org.n52.sos.encode.WmlTDREncoderv20.java

/**
 * Create a SOS DataRecord object from SOS observation and encode to
 * XmlBeans object/* w  w  w  .  j a v a2s. co m*/
 * 
 * @param sosObservation
 *            SOS observation
 * @return XML DataRecord object
 * @throws OwsExceptionReport
 *             If an error occurs
 */
private XmlObject createDataRecord(OmObservation sosObservation) throws OwsExceptionReport {
    AbstractPhenomenon observableProperty = sosObservation.getObservationConstellation()
            .getObservableProperty();
    SweDataRecord dataRecord = new SweDataRecord();
    dataRecord.setIdentifier("datarecord_" + sosObservation.getObservationID());
    SweQuantity quantity = new SweQuantity();
    quantity.setDefinition(observableProperty.getIdentifier());
    quantity.setDescription(observableProperty.getDescription());
    if (observableProperty instanceof OmObservableProperty
            && ((OmObservableProperty) observableProperty).isSetUnit()) {
        quantity.setUom(((OmObservableProperty) observableProperty).getUnit());
    }
    SweField field = new SweField("observed_value", quantity);
    dataRecord.addField(field);
    Map<HelperValues, String> additionalValues = Maps.newEnumMap(HelperValues.class);
    additionalValues.put(HelperValues.FOR_OBSERVATION, null);
    return CodingHelper.encodeObjectToXml(SweConstants.NS_SWE_20, dataRecord, additionalValues);
}

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

private List<BlockFamily> processMultiBlockFamily(AssetUri blockDefUri, BlockDefinition blockDef) {
    List<BlockFamily> result = Lists.newArrayList();
    for (String shapeString : blockDef.shapes) {
        AssetUri shapeUri = new AssetUri(AssetType.SHAPE, shapeString);
        BlockShape shape = (BlockShape) Assets.get(shapeUri);
        if (shape != null) {
            BlockUri familyUri;/*from   www . ja v a2 s .  c om*/
            if (shape.equals(cubeShape)) {
                familyUri = new BlockUri(blockDefUri.getPackage(), blockDefUri.getAssetName());
            } else {
                familyUri = new BlockUri(blockDefUri.getPackage(), blockDefUri.getAssetName(),
                        shapeUri.getPackage(), shapeUri.getAssetName());
            }
            blockDef.shape = shapeString;
            if (shape.isCollisionSymmetric()) {
                Block block = constructSingleBlock(blockDefUri, blockDef);
                result.add(new SymmetricFamily(familyUri, block, getCategories(blockDef)));
            } else {
                Map<Side, Block> blockMap = Maps.newEnumMap(Side.class);
                constructHorizontalBlocks(blockDefUri, blockDef, blockMap);
                result.add(new HorizontalBlockFamily(familyUri, blockMap, getCategories(blockDef)));
            }
        }
    }
    return result;
}

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

private BlockFamily processAlignToSurfaceFamily(AssetUri blockDefUri, JsonObject blockDefJson) {
    Map<Side, Block> blockMap = Maps.newEnumMap(Side.class);
    String[] categories = new String[0];
    if (blockDefJson.has("top")) {
        JsonObject topDefJson = blockDefJson.getAsJsonObject("top");
        blockDefJson.remove("top");
        mergeJsonInto(blockDefJson, topDefJson);
        BlockDefinition topDef = loadBlockDefinition(topDefJson);
        Block block = constructSingleBlock(blockDefUri, topDef);
        block.setDirection(Side.TOP);// w ww. j a va 2s  .  c o m
        blockMap.put(Side.TOP, block);
        categories = getCategories(topDef);
    }
    if (blockDefJson.has("sides")) {
        JsonObject sideDefJson = blockDefJson.getAsJsonObject("sides");
        blockDefJson.remove("sides");
        mergeJsonInto(blockDefJson, sideDefJson);
        BlockDefinition sideDef = loadBlockDefinition(sideDefJson);
        constructHorizontalBlocks(blockDefUri, sideDef, blockMap);
        categories = getCategories(sideDef);
    }
    if (blockDefJson.has("bottom")) {
        JsonObject bottomDefJson = blockDefJson.getAsJsonObject("bottom");
        blockDefJson.remove("bottom");
        mergeJsonInto(blockDefJson, bottomDefJson);
        BlockDefinition bottomDef = loadBlockDefinition(bottomDefJson);
        Block block = constructSingleBlock(blockDefUri, bottomDef);
        block.setDirection(Side.BOTTOM);
        blockMap.put(Side.BOTTOM, block);
        categories = getCategories(bottomDef);
    }
    return new AlignToSurfaceFamily(new BlockUri(blockDefUri.getPackage(), blockDefUri.getAssetName()),
            blockMap, categories);
}