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.android.tools.idea.rendering.MultiResourceRepository.java

@NonNull
@Override/*w  ww  . j ava  2s.c  om*/
protected Map<ResourceType, ListMultimap<String, ResourceItem>> getMap() {
    if (myItems == null) {
        if (myChildren.size() == 1) {
            myItems = myChildren.get(0).getItems();
        } else {
            Map<ResourceType, ListMultimap<String, ResourceItem>> map = Maps.newEnumMap(ResourceType.class);
            for (ResourceType type : ResourceType.values()) {
                map.put(type, getMap(type, false)); // should pass create is true, but as described below we interpret this differently
            }
            myItems = map;
        }
    }

    return myItems;
}

From source file:de.sanandrew.mods.claysoldiers.item.ItemHorseDoll.java

@Override
@SideOnly(Side.CLIENT)/*from  ww w . ja  va2 s.c  o  m*/
public void registerIcons(IIconRegister iconRegister) {
    Map<String, IIcon> names = Maps.newHashMap();
    this.p_icons = Maps.newEnumMap(EnumHorseType.class);
    for (EnumHorseType type : EnumHorseType.VALUES) {
        if (type.itemData == null) {
            continue;
        }
        if (!names.containsKey(type.itemData.getValue0())) {
            names.put(type.itemData.getValue0(), iconRegister.registerIcon(type.itemData.getValue0()));
        }
        this.p_icons.put(type, names.get(type.itemData.getValue0()));
    }
    this.p_pegasusWings = iconRegister.registerIcon(ClaySoldiersMod.MOD_ID + ":doll_pegasus_wing");
}

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

/**
 * Create a new synchronous message channel pair based on netty.
 *
 * There are two preconstructed models available:
 * <ul>/* w  ww . j  a  v a2  s  .  co m*/
 * <li> {@link #newSimpleChannel(String)} provides {@link SimpleNetworkWrapper}, a simple implementation of a netty handler, suitable for those who don't
 * wish to dive too deeply into netty.
 * <li> {@link #newEventChannel(String)} provides {@link FMLEventChannel} an event driven implementation, with lower level
 * access to the network data stream, for those with advanced bitbanging needs that don't wish to poke netty too hard.
 * <li> Alternatively, simply use the netty features provided here and implement the full power of the netty stack.
 * </ul>
 *
 * There are two channels created : one for each logical side (considered as the source of an outbound message)
 * The returned map will contain a value for each logical side, though both will only be working in the
 * integrated server case.
 *
 * The channel expects to read and write using {@link FMLProxyPacket}. All operation is synchronous, as the
 * asynchronous behaviour occurs at a lower level in netty.
 *
 * The first handler in the pipeline is special and should not be removed or moved from the head - it transforms
 * packets from the outbound of this pipeline into custom packets, based on the current {@link AttributeKey} value
 * {@link NetworkRegistry#FML_MESSAGETARGET} and {@link NetworkRegistry#FML_MESSAGETARGETARGS} set on the channel.
 * For the client to server channel (source side : CLIENT) this is fixed as "TOSERVER". For SERVER to CLIENT packets,
 * several possible values exist.
 *
 * Mod Messages should be transformed using a something akin to a {@link MessageToMessageCodec}. FML provides
 * a utility codec, {@link FMLIndexedMessageToMessageCodec} that transforms from {@link FMLProxyPacket} to a mod
 * message using a message discriminator byte. This is optional, but highly recommended for use.
 *
 * Note also that the handlers supplied need to be {@link ChannelHandler.Shareable} - they are injected into two
 * channels.
 *
 * @param name
 * @param handlers
 * @return
 */
public EnumMap<Side, FMLEmbeddedChannel> newChannel(String name, ChannelHandler... handlers) {
    if (channels.containsKey(name) || name.startsWith("MC|") || name.startsWith("\u0001")
            || name.startsWith("FML")) {
        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(name, side, handlers);
        channels.get(side).put(name, channel);
        result.put(side, channel);
    }
    return result;
}

From source file:org.cordovastudio.actions.DeviceMenuAction.java

@Override
@NotNull//  www .  ja  va  2  s.c  om
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
    DefaultActionGroup group = new DefaultActionGroup(null, true);
    RenderConfiguration configuration = myRenderContext.getConfiguration();
    if (configuration == null) {
        return group;
    }
    Device current = configuration.getDevice();
    RenderConfigurationManager configurationManager = configuration.getConfigurationManager();
    List<Device> deviceList = configurationManager.getDevices();

    if (LIST_RECENT_DEVICES) {
        List<Device> recent = configurationManager.getDevices();
        if (recent.size() > 1) {
            boolean separatorNeeded = false;
            for (Device device : recent) {
                String label = device.getDisplayName();
                Icon icon = IconLoader.getIcon(device.getArtwork().getIcon().getPath());
                group.add(new SetDeviceAction(myRenderContext, label, device, icon, device == current));
                separatorNeeded = true;
            }
            if (separatorNeeded) {
                group.addSeparator();
            }
        }
    }

    CordovaFacet facet = CordovaFacet.getInstance(configurationManager.getModule());
    if (facet == null) {
        // Unlikely, but has happened - see http://b.android.com/68091
        return group;
    }

    if (!deviceList.isEmpty()) {
        Map<String, List<Device>> manufacturers = new TreeMap<String, List<Device>>();
        for (Device device : deviceList) {
            List<Device> devices;
            if (manufacturers.containsKey(device.getManufacturer())) {
                devices = manufacturers.get(device.getManufacturer());
            } else {
                devices = new ArrayList<Device>();
                manufacturers.put(device.getManufacturer(), devices);
            }
            devices.add(device);
        }

        Map<FormFactor, List<Device>> deviceMap = Maps.newEnumMap(FormFactor.class);
        for (FormFactor factor : FormFactor.values()) {
            deviceMap.put(factor, Lists.<Device>newArrayList());
        }
        for (List<Device> devices : manufacturers.values()) {
            for (Device device : devices) {

                deviceMap.get(device.getFormFactor()).add(device);

            }
        }

        DefaultActionGroup genericGroup = new DefaultActionGroup("_Generic Phones and Tablets", true);
        addDeviceSection(genericGroup, current, deviceMap, true, FormFactor.MOBILE);
        group.add(genericGroup);
    }

    return group;
}

From source file:edu.udo.scaffoldhunter.view.scaffoldtree.config.MappingDialog.java

private void setConfig() {
    Map<VisualFeature, ConfigMapping> ms = Maps.newEnumMap(VisualFeature.class);
    for (ConfigMapping m : mappings.values()) {
        if (m.getProperty(profile.getCurrentSession().getDataset()) != null)
            ms.put(m.getVisualFeature(), m);
    }//from ww  w. java  2s  .  c o m
    config.setMappings(ms);
}

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

/**
 * Create a new synchronous message channel pair based on netty.
 *
 * There are two preconstructed models available:
 * <ul>// w ww  . j  a  v a  2 s  .  co  m
 * <li> {@link #newSimpleChannel(String)} provides {@link SimpleNetworkWrapper}, a simple implementation of a netty handler, suitable for those who don't
 * wish to dive too deeply into netty.
 * <li> {@link #newEventChannel(String)} provides {@link FMLEventChannel} an event driven implementation, with lower level
 * access to the network data stream, for those with advanced bitbanging needs that don't wish to poke netty too hard.
 * <li> Alternatively, simply use the netty features provided here and implement the full power of the netty stack.
 * </ul>
 *
 * There are two channels created : one for each logical side (considered as the source of an outbound message)
 * The returned map will contain a value for each logical side, though both will only be working in the
 * integrated server case.
 *
 * The channel expects to read and write using {@link FMLProxyPacket}. All operation is synchronous, as the
 * asynchronous behaviour occurs at a lower level in netty.
 *
 * The first handler in the pipeline is special and should not be removed or moved from the head - it transforms
 * packets from the outbound of this pipeline into custom packets, based on the current {@link AttributeKey} value
 * {@link NetworkRegistry#FML_MESSAGETARGET} and {@link NetworkRegistry#FML_MESSAGETARGETARGS} set on the channel.
 * For the client to server channel (source side : CLIENT) this is fixed as "TOSERVER". For SERVER to CLIENT packets,
 * several possible values exist.
 *
 * Mod Messages should be transformed using a something akin to a {@link MessageToMessageCodec}. FML provides
 * a utility codec, {@link FMLIndexedMessageToMessageCodec} that transforms from {@link FMLProxyPacket} to a mod
 * message using a message discriminator byte. This is optional, but highly recommended for use.
 *
 * Note also that the handlers supplied need to be {@link ChannelHandler.Shareable} - they are injected into two
 * channels.
 *
 * @param name
 * @param handlers
 * @return
 */
public EnumMap<Side, FMLEmbeddedChannel> newChannel(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")) {
        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(name, side, handlers);
        channels.get(side).put(name, channel);
        result.put(side, channel);
    }
    return result;
}

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

/**
 * Generates the default mapping of included paths from the given {@code qualifier} and {@code type}.
 *
 * @param qualifier the prefix to add to the initial resource path
 * @param type the type of data to include
 *
 * @return the map of included paths//from   w w  w .ja v  a 2s . co  m
 */
protected Map<MetaInfGroup, String> getDefaultIncludes(String qualifier, MetaInfDataType type) {
    Map<MetaInfGroup, String> defaultIncludes = Maps.newEnumMap(MetaInfGroup.class);

    String resourcePath = ProjectUtils.getResourcePath(project.getGroupId(), project.getArtifactId());
    List<String> paths = Lists.newArrayList(resourcePath, qualifier, type.name().toLowerCase(), ALL_XML_PATH);

    defaultIncludes.put(MetaInfGroup.OTHER, StringUtils.join(paths, PATH_SEPARATOR));

    return defaultIncludes;
}

From source file:org.carrot2.text.linguistic.DefaultLanguageModelFactory.java

/**
 * Create default stemmer factories.//from   ww  w .  java2  s  .  co m
 */
private static EnumMap<LanguageCode, IStemmerFactory> createDefaultStemmers() {
    EnumMap<LanguageCode, IStemmerFactory> map = Maps.newEnumMap(LanguageCode.class);

    map.put(LanguageCode.POLISH, new PolishStemmerFactory());
    map.put(LanguageCode.ARABIC, new ArabicStemmerFactory());

    map.put(LanguageCode.DANISH, new SnowballStemmerFactory("org.tartarus.snowball.ext.DanishStemmer"));
    map.put(LanguageCode.DUTCH, new SnowballStemmerFactory("org.tartarus.snowball.ext.DutchStemmer"));
    map.put(LanguageCode.ENGLISH, new SnowballStemmerFactory("org.tartarus.snowball.ext.EnglishStemmer"));
    map.put(LanguageCode.FINNISH, new SnowballStemmerFactory("org.tartarus.snowball.ext.FinnishStemmer"));
    map.put(LanguageCode.FRENCH, new SnowballStemmerFactory("org.tartarus.snowball.ext.FrenchStemmer"));
    map.put(LanguageCode.GERMAN, new SnowballStemmerFactory("org.tartarus.snowball.ext.GermanStemmer"));
    map.put(LanguageCode.HUNGARIAN, new SnowballStemmerFactory("org.tartarus.snowball.ext.HungarianStemmer"));
    map.put(LanguageCode.ITALIAN, new SnowballStemmerFactory("org.tartarus.snowball.ext.ItalianStemmer"));
    map.put(LanguageCode.NORWEGIAN, new SnowballStemmerFactory("org.tartarus.snowball.ext.NorwegianStemmer"));
    map.put(LanguageCode.PORTUGUESE, new SnowballStemmerFactory("org.tartarus.snowball.ext.PortugueseStemmer"));
    map.put(LanguageCode.ROMANIAN, new SnowballStemmerFactory("org.tartarus.snowball.ext.RomanianStemmer"));
    map.put(LanguageCode.RUSSIAN, new SnowballStemmerFactory("org.tartarus.snowball.ext.RussianStemmer"));
    map.put(LanguageCode.SPANISH, new SnowballStemmerFactory("org.tartarus.snowball.ext.SpanishStemmer"));
    map.put(LanguageCode.SWEDISH, new SnowballStemmerFactory("org.tartarus.snowball.ext.SwedishStemmer"));
    map.put(LanguageCode.TURKISH, new SnowballStemmerFactory("org.tartarus.snowball.ext.TurkishStemmer"));

    /*
     * Chinese uses identity stemmer.
     */
    map.put(LanguageCode.CHINESE_SIMPLIFIED, new IdentityStemmerFactory());

    /*
     * Check for stemmer availability and replace with a fallback if not available.
     */
    for (LanguageCode lc : Sets.newTreeSet(map.keySet())) {
        try {
            map.get(lc).createInstance().stem("test");
        } catch (Throwable t) {
            map.put(lc, new IdentityStemmerFactory());

            String message = "Stemmer for " + lc.toString() + " (" + lc.getIsoCode() + ") is not available."
                    + " This may degrade clustering quality of " + lc.toString() + " content.";

            logger.warn(message);
        }
    }

    return map;
}

From source file:com.android.tools.idea.configurations.DeviceMenuAction.java

@Override
@NotNull//from ww  w .j  a va2s  . com
protected DefaultActionGroup createPopupActionGroup() {
    DefaultActionGroup group = new DefaultActionGroup(null, true);
    Configuration configuration = myRenderContext.getConfiguration();
    if (configuration == null) {
        return group;
    }
    Device current = configuration.getDevice();
    ConfigurationManager configurationManager = configuration.getConfigurationManager();
    List<Device> deviceList = configurationManager.getDevices();

    if (LIST_RECENT_DEVICES) {
        List<Device> recent = configurationManager.getDevices();
        if (recent.size() > 1) {
            boolean separatorNeeded = false;
            for (Device device : recent) {
                String label = getLabel(device, isNexus(device));
                Icon icon = getDeviceClassIcon(device);
                group.add(new SetDeviceAction(myRenderContext, label, device, icon, device == current));
                separatorNeeded = true;
            }
            if (separatorNeeded) {
                group.addSeparator();
            }
        }
    }

    AndroidFacet facet = AndroidFacet.getInstance(configurationManager.getModule());
    if (facet == null) {
        // Unlikely, but has happened - see http://b.android.com/68091
        return group;
    }

    if (!deviceList.isEmpty()) {
        Map<String, List<Device>> manufacturers = new TreeMap<>();
        for (Device device : deviceList) {
            List<Device> devices;
            if (manufacturers.containsKey(device.getManufacturer())) {
                devices = manufacturers.get(device.getManufacturer());
            } else {
                devices = new ArrayList<>();
                manufacturers.put(device.getManufacturer(), devices);
            }
            devices.add(device);
        }
        List<Device> nexus = new ArrayList<>();
        Map<FormFactor, List<Device>> deviceMap = Maps.newEnumMap(FormFactor.class);
        for (FormFactor factor : FormFactor.values()) {
            deviceMap.put(factor, Lists.newArrayList());
        }
        for (List<Device> devices : manufacturers.values()) {
            for (Device device : devices) {
                if (isNexus(device) && !device.getManufacturer().equals(MANUFACTURER_GENERIC) && !isWear(device)
                        && !isTv(device)) {
                    nexus.add(device);
                } else {
                    deviceMap.get(FormFactor.getFormFactor(device)).add(device);
                }
            }
        }

        sortDevicesByScreenSize(nexus);
        for (List<Device> list : splitDevicesByScreenSize(nexus)) {
            addNexusDeviceSection(group, current, list);
            group.addSeparator();
        }
        addDeviceSection(group, current, deviceMap, false, FormFactor.WEAR);
        group.addSeparator();
        addDeviceSection(group, current, deviceMap, false, FormFactor.TV);
        group.addSeparator();

        final AvdManager avdManager = facet.getAvdManagerSilently();
        if (avdManager != null) {
            boolean separatorNeeded = false;
            boolean first = true;
            for (AvdInfo avd : avdManager.getValidAvds()) {
                Device device = configurationManager.createDeviceForAvd(avd);
                if (device != null) {
                    String avdName = "AVD: " + avd.getName();
                    boolean selected = current != null
                            && (current.getDisplayName().equals(avdName) || current.getId().equals(avdName));
                    Icon icon = first ? getDeviceClassIcon(device) : null;
                    group.add(new SetDeviceAction(myRenderContext, avdName, device, icon, selected));
                    first = false;
                    separatorNeeded = true;
                }
            }

            if (separatorNeeded) {
                group.addSeparator();
            }
        }

        DefaultActionGroup genericGroup = new DefaultActionGroup("_Generic Phones and Tablets", true);
        sortDevicesByScreenSize(deviceMap.get(FormFactor.MOBILE));
        addDeviceSection(genericGroup, current, deviceMap, true, FormFactor.MOBILE);
        group.add(genericGroup);
    }

    group.add(new RunAndroidAvdManagerAction("Add Device Definition..."));

    return group;
}

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

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

        {// www .  j a  v a2  s.  co  m
            Object val = RandomValueGenerator.getValueOf(
                    ((PrimitiveFieldType) MainTableMetadata.LONG_REQUIRED_COLUMN.getField().getType())
                            .getPrimitiveType());
            if (val != null) {
                dataMap.put(MainTableMetadata.LONG_REQUIRED_COLUMN, val);
            }
        }

        {
            Object val = RandomValueGenerator
                    .getValueOf(((PrimitiveFieldType) MainTableMetadata.INT_SORTED_COLUMN.getField().getType())
                            .getPrimitiveType());
            if (val != null) {
                dataMap.put(MainTableMetadata.INT_SORTED_COLUMN, val);
            }
        }

        {
            Object val = RandomValueGenerator
                    .getValueOf(((PrimitiveFieldType) MainTableMetadata.BYTE_COLUMN.getField().getType())
                            .getPrimitiveType());
            if (val != null) {
                dataMap.put(MainTableMetadata.BYTE_COLUMN, val);
            }
        }

        {
            Object val = RandomValueGenerator
                    .getValueOf(((PrimitiveFieldType) MainTableMetadata.BOOLEAN_COLUMN.getField().getType())
                            .getPrimitiveType());
            if (val != null) {
                dataMap.put(MainTableMetadata.BOOLEAN_COLUMN, val);
            }
        }

        {
            Object val = RandomValueGenerator
                    .getValueOf(((PrimitiveFieldType) MainTableMetadata.SHORT_COLUMN.getField().getType())
                            .getPrimitiveType());
            if (val != null) {
                dataMap.put(MainTableMetadata.SHORT_COLUMN, val);
            }
        }

        {
            Object val = RandomValueGenerator
                    .getValueOf(((PrimitiveFieldType) MainTableMetadata.FLOAT_COLUMN.getField().getType())
                            .getPrimitiveType());
            if (val != null) {
                dataMap.put(MainTableMetadata.FLOAT_COLUMN, val);
            }
        }

        {
            Object val = RandomValueGenerator
                    .getValueOf(((PrimitiveFieldType) MainTableMetadata.DOUBLE_COLUMN.getField().getType())
                            .getPrimitiveType());
            if (val != null) {
                dataMap.put(MainTableMetadata.DOUBLE_COLUMN, val);
            }
        }

        {
            Object val = RandomValueGenerator
                    .getValueOf(((PrimitiveFieldType) MainTableMetadata.STRING_COLUMN.getField().getType())
                            .getPrimitiveType());
            if (val != null) {
                dataMap.put(MainTableMetadata.STRING_COLUMN, val);
            }
        }

        {
            Object val = RandomValueGenerator
                    .getValueOf(((PrimitiveFieldType) MainTableMetadata.BINARY_COLUMN.getField().getType())
                            .getPrimitiveType());
            if (val != null) {
                dataMap.put(MainTableMetadata.BINARY_COLUMN, val);
            }
        }

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

        {
            Object val = StructTableTestData.createInputData(1);
            if (val != null && !((List) val).isEmpty()) {
                dataMap.put(MainTableMetadata.STRUCT_COLUMN, val);
            }
        }

        {
            Object val = RandomValueGenerator.getValueArrayOf(
                    ((PrimitiveFieldType) ((CollectionFieldType) MainTableMetadata.INT_LIST_COLUMN.getField()
                            .getType()).getElementType()).getPrimitiveType(),
                    num);
            if (val != null && !((List) val).isEmpty()) {
                dataMap.put(MainTableMetadata.INT_LIST_COLUMN, val);
            }
        }

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