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.torodb.torod.db.backends.mysql.converters.json.MySQLValueToJsonConverterProvider.java

private MySQLValueToJsonConverterProvider() {
    converters = Maps.newEnumMap(ScalarType.class);
    converters.put(ScalarType.ARRAY,//from   ww w  .  ja  v a  2 s  .  c  o m
            new ArrayValueToJsonConverter(MySQLValueToArrayConverterProvider.getInstance()));
    converters.put(ScalarType.BOOLEAN, new BooleanValueToJsonConverter());
    converters.put(ScalarType.DATE, new DateValueToJsonConverter());
    converters.put(ScalarType.INSTANT, new InstantValueToJsonConverter());
    converters.put(ScalarType.DOUBLE, new DoubleValueToJsonConverter());
    converters.put(ScalarType.INTEGER, new IntegerValueToJsonConverter());
    converters.put(ScalarType.LONG, new LongValueToJsonConverter());
    converters.put(ScalarType.NULL, new NullValueToJsonConverter());
    converters.put(ScalarType.STRING, new StringValueToJsonConverter());
    converters.put(ScalarType.TIME, new TimeValueToJsonConverter());
    converters.put(ScalarType.MONGO_OBJECT_ID, new MongoObjectIdValueToJsonConverter());
    converters.put(ScalarType.MONGO_TIMESTAMP, new MongoTimestampValueToJsonConverter());
    converters.put(ScalarType.BINARY, new BinaryValueToJsonConverter());

    SetView<ScalarType> withoutConverter = Sets.difference(converters.keySet(), SUPPORTED_TYPES);
    if (!withoutConverter.isEmpty()) {
        throw new AssertionError("It is not defined how to convert from the following scalar "
                + "types to json: " + withoutConverter);
    }
}

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

public SectionDefinitionData() {
    colorSources = Maps.newEnumMap(BlockPart.class);
    colorOffsets = Maps.newEnumMap(BlockPart.class);
    for (BlockPart part : BlockPart.values()) {
        colorSources.put(part, DefaultColorSource.DEFAULT);
        colorOffsets.put(part, new Vector4f(1, 1, 1, 1));
    }/*from w w  w.j  a  v  a 2  s. co m*/
}

From source file:org.eclipse.xtext.xbase.typesystem.internal.FeatureScopeTracker.java

@Override
public void addExpressionScope(ResolvedTypes current, EObject context, IFeatureScopeSession session,
        Anchor anchor) {//ww  w .j  av a 2  s  .c o m
    EnumMap<Anchor, ExpressionScope> recordedScopes = featureScopeSessions.get(context);
    if (recordedScopes == null) {
        recordedScopes = Maps.newEnumMap(Anchor.class);
        featureScopeSessions.put(context, recordedScopes);
    }
    ExpressionScope scope = recordedScopes.get(anchor);
    if (scope == null) {
        scope = new ExpressionScope(current.getResolver().getFeatureScopes(), context, anchor,
                current.getReferenceOwner());
        recordedScopes.put(anchor, scope);
    }
    scope.addData(session, current.withFlattenedReassignedTypes());
}

From source file:org.diorite.impl.connection.EnumProtocol.java

EnumProtocol(final String name, final int status) {
    this.packetsMap = Maps.newEnumMap(EnumProtocolDirection.class);
    this.packetsSupplierMap = Maps.newEnumMap(EnumProtocolDirection.class);
    this.name = name;
    this.status = status;
}

From source file:io.techcode.logbulk.pipeline.input.SyslogInput.java

@Override
protected void onStart() {
    // Setup mapping
    JsonObject map = config.getJsonObject(CONF_MAPPING, new JsonObject());
    mapping = Maps.newEnumMap(SyslogHeader.class);
    for (String entry : map.fieldNames()) {
        mapping.put(SyslogHeader.byName(entry), map.getString(entry));
    }//from  ww  w  . ja  va2  s.  c  om
    skipStructuredData = config.getBoolean("skipStructuredData", false);
}

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

@Override
public void generateChunkMesh(ChunkView view, ChunkMesh chunkMesh, int x, int y, int z) {
    Biome selfBiome = view.getBiome(x, y, z);
    Block selfBlock = view.getBlock(x, y, z);

    // TODO: Needs review - too much hardcoded special cases and corner cases resulting from this.
    ChunkVertexFlag vertexFlag = ChunkVertexFlag.NORMAL;
    if (selfBlock.isWater()) {
        if (view.getBlock(x, y + 1, z).isWater()) {
            vertexFlag = ChunkVertexFlag.WATER;
        } else {/*  ww w.j  ava  2 s  . c  o m*/
            vertexFlag = ChunkVertexFlag.WATER_SURFACE;
        }
    } else if (selfBlock.isLava()) {
        vertexFlag = ChunkVertexFlag.LAVA;
    } else if (selfBlock.isWaving() && selfBlock.isDoubleSided()) {
        vertexFlag = ChunkVertexFlag.WAVING;
    } else if (selfBlock.isWaving()) {
        vertexFlag = ChunkVertexFlag.WAVING_BLOCK;
    }

    // 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 = selfBlock.getAppearance(adjacentBlocks);

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

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

    if (blockAppearance.getPart(BlockPart.CENTER) != null) {
        Vector4f colorOffset = selfBlock.calcColorOffsetFor(BlockPart.CENTER, selfBiome);
        blockAppearance.getPart(BlockPart.CENTER).appendTo(chunkMesh, 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), selfBlock, side);
    }

    // If the selfBlock is lowered, some more faces may have to be drawn
    if (selfBlock.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, selfBlock, side)
                    && !isSideVisibleForBlockTypes(bottomBlock, adjacent, side.reverse()));
            drawDir[side.ordinal()] |= visible;
        }

        // Draw the top if below a non-lowered selfBlock
        // TODO: Don't need to render the top if each side and the selfBlock 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.getMeshGenerator() == null) {
            for (Side dir : Side.values()) {
                if (drawDir[dir.ordinal()]) {
                    Vector4f colorOffset = selfBlock.calcColorOffsetFor(BlockPart.fromSide(dir), selfBiome);
                    selfBlock.getLoweredLiquidMesh(dir).appendTo(chunkMesh, x, y, z, colorOffset, renderType,
                            vertexFlag);
                }
            }
            return;
        }
    }

    for (Side dir : Side.values()) {
        if (drawDir[dir.ordinal()]) {
            Vector4f colorOffset = selfBlock.calcColorOffsetFor(BlockPart.fromSide(dir), selfBiome);
            // TODO: Needs review since the new per-vertex flags introduce a lot of special scenarios - probably a per-side setting?
            if (selfBlock.isGrass() && dir != Side.TOP && dir != Side.BOTTOM) {
                blockAppearance.getPart(BlockPart.fromSide(dir)).appendTo(chunkMesh, x, y, z, colorOffset,
                        renderType, ChunkVertexFlag.COLOR_MASK);
            } else {
                //if(dir == Side.TOP) logger.info("Generating: " + (new Vector3i(x, y, z)).toString() + " " + view.getChunkRegion().toString() + " " + dir.toString());

                if (blockAppearance.getPart(BlockPart.fromSide(dir)) == null) {
                    // TODO: This would catch something like water blocks attempting to render with a "fixed" trimmedLoweredCube shape
                    // That shape has its top trimmed down a bit to let water sit slightly lower than land, however, underwater this shouldn't show
                    // Normally we would configure that shape with CENTER instead of TOP, that way the trimmed part wouldn't occlude in a stack
                    // But with that handling you don't get water blocks occluding tops underwater... and there's no TOP to retrieve below -> NPE
                    logger.debug(
                            "Cannot render side '{}' for a block - no stored block appearance for it. renderType {}, vertexFlag {}",
                            dir, renderType, vertexFlag);
                } else {
                    blockAppearance.getPart(BlockPart.fromSide(dir)).appendTo(chunkMesh, x, y, z, colorOffset,
                            renderType, vertexFlag);
                }
            }
        }
    }
}

From source file:com.torodb.torod.db.postgresql.converters.jsonb.ValueToJsonbConverterProvider.java

private ValueToJsonbConverterProvider() {
    arrayConverter = new ArrayValueToJsonbConverter();
    booleanConverter = new BooleanValueToJsonbConverter();
    dateConverter = new DateValueToJsonbConverter();
    dateTimeConverter = new DateTimeValueToJsonbConverter();
    doubleConverter = new DoubleValueToJsonbConverter();
    integerConverter = new IntegerValueToJsonbConverter();
    longConverter = new LongValueToJsonbConverter();
    nullConverter = new NullValueToJsonbConverter();
    stringConverter = new StringValueToJsonbConverter();
    timeConverter = new TimeValueToJsonbConverter();
    twelveBytesConverter = new TwelveBytesValueToJsonbConverter();

    converters = Maps.newEnumMap(BasicType.class);
    converters.put(BasicType.ARRAY, arrayConverter);
    converters.put(BasicType.BOOLEAN, booleanConverter);
    converters.put(BasicType.DATE, dateConverter);
    converters.put(BasicType.DATETIME, dateTimeConverter);
    converters.put(BasicType.DOUBLE, doubleConverter);
    converters.put(BasicType.INTEGER, integerConverter);
    converters.put(BasicType.LONG, longConverter);
    converters.put(BasicType.NULL, nullConverter);
    converters.put(BasicType.STRING, stringConverter);
    converters.put(BasicType.TIME, timeConverter);
    converters.put(BasicType.TWELVE_BYTES, twelveBytesConverter);

}

From source file:datamine.storage.recordbuffers.example.data.FirstLevelNestedTableTestData.java

public static List<EnumMap<FirstLevelNestedTableMetadata, Object>> createInputData(int num) {
    List<EnumMap<FirstLevelNestedTableMetadata, Object>> dataList = Lists.newArrayList();
    for (int i = 0; i < num; ++i) {
        EnumMap<FirstLevelNestedTableMetadata, Object> dataMap = Maps
                .newEnumMap(FirstLevelNestedTableMetadata.class);

        {//from  www  .  ja  va  2  s  . c o  m
            Object val = RandomValueGenerator
                    .getValueOf(((PrimitiveFieldType) FirstLevelNestedTableMetadata.INT_REQUIRED_COLUMN
                            .getField().getType()).getPrimitiveType());
            if (val != null) {
                dataMap.put(FirstLevelNestedTableMetadata.INT_REQUIRED_COLUMN, val);
            }
        }

        {
            Object val = SecondLevelNestedTableTestData.createInputData(3);
            if (val != null && !((List) val).isEmpty()) {
                dataMap.put(FirstLevelNestedTableMetadata.NESTED_TABLE_COLUMN, val);
            }
        }

        if (!dataMap.isEmpty()) {
            dataList.add(dataMap);
        }
    }
    return dataList;
}

From source file:com.torodb.torod.db.backends.converters.json.ValueToJsonConverterProvider.java

private ValueToJsonConverterProvider() {
    arrayConverter = new ArrayValueToJsonConverter();
    booleanConverter = new BooleanValueToJsonConverter();
    dateConverter = new DateValueToJsonConverter();
    dateTimeConverter = new DateTimeValueToJsonConverter();
    doubleConverter = new DoubleValueToJsonConverter();
    integerConverter = new IntegerValueToJsonConverter();
    longConverter = new LongValueToJsonConverter();
    nullConverter = new NullValueToJsonConverter();
    stringConverter = new StringValueToJsonConverter();
    timeConverter = new TimeValueToJsonConverter();
    twelveBytesConverter = new TwelveBytesValueToJsonConverter();
    posixPatternConverter = new PosixPatternValueToJsonConverter();

    converters = Maps.newEnumMap(BasicType.class);
    converters.put(BasicType.ARRAY, arrayConverter);
    converters.put(BasicType.BOOLEAN, booleanConverter);
    converters.put(BasicType.DATE, dateConverter);
    converters.put(BasicType.DATETIME, dateTimeConverter);
    converters.put(BasicType.DOUBLE, doubleConverter);
    converters.put(BasicType.INTEGER, integerConverter);
    converters.put(BasicType.LONG, longConverter);
    converters.put(BasicType.NULL, nullConverter);
    converters.put(BasicType.STRING, stringConverter);
    converters.put(BasicType.TIME, timeConverter);
    converters.put(BasicType.TWELVE_BYTES, twelveBytesConverter);
    converters.put(BasicType.PATTERN, posixPatternConverter);

}

From source file:com.torodb.torod.db.backends.greenplum.converters.json.GreenplumValueToJsonConverterProvider.java

private GreenplumValueToJsonConverterProvider() {
    converters = Maps.newEnumMap(ScalarType.class);
    converters.put(ScalarType.ARRAY,/*from w ww. j  a  v  a2 s.  co  m*/
            new ArrayValueToJsonConverter(GreenplumValueToArrayConverterProvider.getInstance()));
    converters.put(ScalarType.BOOLEAN, new BooleanValueToJsonConverter());
    converters.put(ScalarType.DATE, new DateValueToJsonConverter());
    converters.put(ScalarType.INSTANT, new InstantValueToJsonConverter());
    converters.put(ScalarType.DOUBLE, new DoubleValueToJsonConverter());
    converters.put(ScalarType.INTEGER, new IntegerValueToJsonConverter());
    converters.put(ScalarType.LONG, new LongValueToJsonConverter());
    converters.put(ScalarType.NULL, new NullValueToJsonConverter());
    converters.put(ScalarType.STRING, new StringValueToJsonConverter());
    converters.put(ScalarType.TIME, new TimeValueToJsonConverter());
    converters.put(ScalarType.MONGO_OBJECT_ID, new MongoObjectIdValueToJsonConverter());
    converters.put(ScalarType.MONGO_TIMESTAMP, new MongoTimestampValueToJsonConverter());
    converters.put(ScalarType.BINARY, new BinaryValueToJsonConverter());

    SetView<ScalarType> withoutConverter = Sets.difference(converters.keySet(), SUPPORTED_TYPES);
    if (!withoutConverter.isEmpty()) {
        throw new AssertionError("It is not defined how to convert from the following scalar "
                + "types to json: " + withoutConverter);
    }
}