List of usage examples for com.google.common.collect Maps newEnumMap
public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(Map<K, ? extends V> map)
From source file:com.ardor3d.input.MouseButton.java
public static EnumMap<MouseButton, ButtonState> makeMap(final ButtonState left, final ButtonState right, final ButtonState middle) { if (left == null) { throw new NullPointerException("left"); }/*from w w w.j a va2s . c o m*/ if (right == null) { throw new NullPointerException("right"); } if (middle == null) { throw new NullPointerException("middle"); } final EnumMap<MouseButton, ButtonState> map = Maps.newEnumMap(MouseButton.class); map.put(LEFT, left); map.put(RIGHT, right); map.put(MIDDLE, middle); return map; }
From source file:javastory.game.Effectiveness.java
public static EnumMap<AttackNature, Effectiveness> fromString(final String attributes) { final EnumMap<AttackNature, Effectiveness> map = Maps.newEnumMap(AttackNature.class); for (int i = 0; i < attributes.length(); i += 2) { final char elementChar = attributes.charAt(i); final AttackNature element = AttackNature.fromCharacter(elementChar); final int effectivenessId = attributes.charAt(i + 1) - '0'; final Effectiveness effectiveness = Effectiveness.fromNumber(effectivenessId); map.put(element, effectiveness); }/* w w w. j av a2s .com*/ return map; }
From source file:edu.ucsc.twitter.ResultPackage.java
public static ResultPackage emptyPackage(Kind kind) { final Map<Kind, List<Object>> seed = Maps.newEnumMap(Kind.class); seed.put(kind, Lists.<Object>newArrayList()); return new ResultPackage(seed); }
From source file:com.github.fge.jackson.SampleNodeProvider.java
public static Iterator<Object[]> getSamples(final EnumSet<NodeType> types) { final Map<NodeType, JsonNode> map = Maps.newEnumMap(SAMPLE_DATA); map.keySet().retainAll(types);//w ww . j ava2s .c o m return FluentIterable.from(map.values()).transform(new Function<JsonNode, Object[]>() { @Override public Object[] apply(final JsonNode input) { return new Object[] { input }; } }).iterator(); }
From source file:org.terasology.world.block.BlockAppearance.java
public BlockAppearance() { blockParts = Maps.newEnumMap(BlockPart.class); textureAtlasPos = Maps.newEnumMap(BlockPart.class); for (BlockPart part : BlockPart.values()) { textureAtlasPos.put(part, new Vector2f()); }/*w ww .j ava 2 s .c om*/ }
From source file:com.worldcretornica.plotme_core.api.event.eventbus.HandlerCache.java
HandlerCache(List<MethodEventHandler> registrations) { this.handlers = Lists.newArrayList(); for (MethodEventHandler reg : registrations) { this.handlers.add(reg); }/*from w ww .j av a 2s . c om*/ this.orderGrouped = Maps.newEnumMap(Order.class); for (Order order : Order.values()) { this.orderGrouped.put(order, new ArrayList<MethodEventHandler>()); } for (MethodEventHandler reg : registrations) { this.orderGrouped.get(reg.getPriority()).add(reg); } }
From source file:org.carrot2.workbench.core.preferences.PreferenceInitializer.java
public void initializeDefaultPreferences() { final IPreferenceStore store = WorkbenchCorePlugin.getDefault().getPreferenceStore(); /*/*from w w w .ja v a 2 s . co m*/ * Default editor panels. */ final EnumMap<SearchEditor.PanelName, SearchEditor.PanelState> globals = Maps .newEnumMap(SearchEditor.PanelName.class); globals.put(PanelName.CLUSTERS, createPanelState(1, true)); globals.put(PanelName.DOCUMENTS, createPanelState(2, true)); globals.put(PanelName.ATTRIBUTES, createPanelState(1, false)); SearchEditor.saveGlobalPanelsState(globals); /* * Auto-update. */ store.setDefault(PreferenceConstants.AUTO_UPDATE, true); store.setDefault(PreferenceConstants.AUTO_UPDATE_DELAY, 1000); /* * Attribute grouping. */ store.setDefault(PreferenceConstants.GROUPING_ATTRIBUTE_VIEW, GroupingMethod.GROUP.name()); /* * SearchInputView */ store.setDefault(PreferenceConstants.SHOW_OPTIONAL, true); store.setDefault(PreferenceConstants.GROUPING_INPUT_VIEW, GroupingMethod.LEVEL.name()); /* * SearchEditor */ store.setDefault(PreferenceConstants.GROUPING_EDITOR_PANEL, GroupingMethod.GROUP.name()); /* * Automatically show attribute info in the view. */ store.setDefault(PreferenceConstants.ATTRIBUTE_INFO_SYNC, true); /* * Truncate long snippets and titles after this many characters. */ store.setDefault(PreferenceConstants.MAX_FIELD_LENGTH, 280); }
From source file:org.carrot2.text.linguistic.DefaultStemmerFactory.java
/** * Create default stemmer factories.//from w w w. j av a2 s. c om */ private static EnumMap<LanguageCode, IFactory<IStemmer>> createDefaultStemmers() { final IFactory<IStemmer> identity = new SingletonFactory<IStemmer>(new IdentityStemmer()); final EnumMap<LanguageCode, IFactory<IStemmer>> map = Maps.newEnumMap(LanguageCode.class); // Adapters to third-party libraries. map.put(LanguageCode.POLISH, new NewClassInstanceFactory<IStemmer>(MorfologikStemmerAdapter.class)); map.put(LanguageCode.ARABIC, new NewClassInstanceFactory<IStemmer>(ArabicStemmerAdapter.class)); // Adapters to snowball. 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")); // Identity stemming for Chinese. map.put(LanguageCode.CHINESE_SIMPLIFIED, identity); // Specialized stemming for Hindi (ported from Lucene) map.put(LanguageCode.HINDI, new NewClassInstanceFactory<IStemmer>(HindiStemmerAdapter.class)); // Decorate everything with a fallback identity stemmer. for (LanguageCode lc : LanguageCode.values()) { if (map.containsKey(lc)) { IFactory<IStemmer> factory = map.get(lc); if (factory != identity) { factory = new FallbackFactory<IStemmer>(factory, identity, stemmerVerifier, logger, "Stemmer for " + lc.toString() + " (" + lc.getIsoCode() + ") is not available." + " This may degrade clustering quality of " + lc.toString() + " content. Cause: {}"); map.put(lc, factory); } } else { map.put(lc, identity); } } return map; }
From source file:org.terasology.world.block.family.AlignToSurfaceFamilyFactory.java
@Override public BlockFamily createBlockFamily(BlockBuilderHelper blockBuilder, AssetUri blockDefUri, BlockDefinition blockDefinition, JsonObject blockDefJson) { Map<Side, Block> blockMap = Maps.newEnumMap(Side.class); BlockDefinition topDef = blockBuilder.getBlockDefinitionForSection(blockDefJson, TOP); if (topDef != null) { Block block = blockBuilder.constructSimpleBlock(blockDefUri, topDef); block.setDirection(Side.TOP);/*www. j a v a 2s . co m*/ blockMap.put(Side.TOP, block); } BlockDefinition sideDef = blockBuilder.getBlockDefinitionForSection(blockDefJson, SIDES); if (sideDef != null) { blockMap.putAll(blockBuilder.constructHorizontalRotatedBlocks(blockDefUri, sideDef)); } BlockDefinition bottomDef = blockBuilder.getBlockDefinitionForSection(blockDefJson, BOTTOM); if (bottomDef != null) { Block block = blockBuilder.constructSimpleBlock(blockDefUri, bottomDef); block.setDirection(Side.BOTTOM); blockMap.put(Side.BOTTOM, block); } return new AlignToSurfaceFamily(new BlockUri(blockDefUri.getModuleName(), blockDefUri.getAssetName()), blockMap, blockDefinition.categories); }
From source file:org.carrot2.text.linguistic.DefaultTokenizerFactory.java
/** * Create default tokenizer factories./*from w w w.j a v a2 s . c om*/ */ private static EnumMap<LanguageCode, IFactory<ITokenizer>> createDefaultTokenizers() { EnumMap<LanguageCode, IFactory<ITokenizer>> map = Maps.newEnumMap(LanguageCode.class); // By default, we use our own tokenizer for all languages. IFactory<ITokenizer> whitespaceTokenizerFactory = new NewClassInstanceFactory<ITokenizer>( ExtendedWhitespaceTokenizer.class); for (LanguageCode lc : LanguageCode.values()) { map.put(lc, whitespaceTokenizerFactory); } // Chinese and Thai are exceptions, we use adapters around tokenizers from Lucene. map.put(LanguageCode.CHINESE_SIMPLIFIED, new NewClassInstanceFactory<ITokenizer>(ChineseTokenizerAdapter.class)); map.put(LanguageCode.THAI, new NewClassInstanceFactory<ITokenizer>(ThaiTokenizerAdapter.class)); // Japanese is currently not supported. TODO: CARROT-903 map.put(LanguageCode.JAPANESE, new JapaneseUnsupportedStub()); // Decorate everything with a fallback tokenizer. for (LanguageCode lc : LanguageCode.values()) { if (map.containsKey(lc)) { IFactory<ITokenizer> factory = map.get(lc); if (factory != whitespaceTokenizerFactory) { map.put(lc, new FallbackFactory<ITokenizer>(factory, whitespaceTokenizerFactory, tokenizerVerifier, logger, "Tokenizer for " + lc.toString() + " (" + lc.getIsoCode() + ") is not available." + " This may degrade clustering quality of " + lc.toString() + " content. Cause: {}")); } } else { map.put(lc, whitespaceTokenizerFactory); } } return map; }