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:org.kuali.rice.sql.config.spring.RiceSqlConfig.java
/** * Generates the default mapping of included paths from the given {@code qualifier}, {@code vendor}, and * {@code type}./* w ww .j a v a 2s . c o m*/ * * @param qualifier the prefix to add to the initial resource path * @param vendor the database vendor to include * @param location the location of the data to include * @param type the type of data to include * * @return the map of included paths */ protected Map<MetaInfGroup, String> getDefaultIncludes(String qualifier, String vendor, MetaInfDataLocation location, 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, vendor, location.name().toLowerCase(), type.name().toLowerCase()); String value = StringUtils.join(paths, PATH_SEPARATOR); defaultIncludes.put(MetaInfGroup.SCHEMA, value + PATH_SEPARATOR + SCHEMA_SQL_PATH); defaultIncludes.put(MetaInfGroup.DATA, value + PATH_SEPARATOR + ALL_SQL_PATH); defaultIncludes.put(MetaInfGroup.CONSTRAINTS, value + PATH_SEPARATOR + CONSTRAINTS_SQL_PATH); defaultIncludes.put(MetaInfGroup.OTHER, value + PATH_SEPARATOR + ALL_SQL_PATH); return defaultIncludes; }
From source file:org.moe.designer.configurations.DeviceMenuAction.java
@Override @NotNull/* w ww . j av a2s . co m*/ protected DefaultActionGroup createPopupActionGroup(JComponent button) { 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 = FormFactor.getFormFactor(device).getIcon(); 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; } // final AvdManager avdManager = facet.getAvdManagerSilently(); // if (avdManager != null) { // boolean separatorNeeded = false; // 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 = FormFactor.getFormFactor(device).getIcon(); // group.add(new SetDeviceAction(myRenderContext, avdName, device, icon, selected)); // separatorNeeded = true; // } // } // // if (separatorNeeded) { // group.addSeparator(); // } // } 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); } List<Device> nexus = new ArrayList<Device>(); List<Device> intel = new ArrayList<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) { if (isNexus(device) && !device.getManufacturer().equals(MANUFACTURER_GENERIC)) { nexus.add(device); } else if (isIntelIOSDevice(device) && !device.getManufacturer().equals(MANUFACTURER_GENERIC)) { intel.add(device); } else { deviceMap.get(FormFactor.getFormFactor(device)).add(device); } } } addIntelDeviceSection(group, current, intel); //TODO: add all telephones groups here // group.addSeparator(); // sortNexusList(nexus); // addNexusDeviceSection(group, current, nexus); // group.addSeparator(); // addDeviceSection(group, current, deviceMap, false, FormFactor.WEAR); // group.addSeparator(); // addDeviceSection(group, current, deviceMap, false, FormFactor.TV); // group.addSeparator(); // // DefaultActionGroup genericGroup = new DefaultActionGroup("_Generic Phones and Tablets", true); // addDeviceSection(genericGroup, current, deviceMap, true, FormFactor.MOBILE); // group.add(genericGroup); } // group.add(new RunAndroidAvdManagerAction("Add Device Definition...")); // group.addSeparator(); // if (RenderPreviewMode.getCurrent() != RenderPreviewMode.SCREENS) { // ConfigurationMenuAction.addScreenSizeAction(myRenderContext, group); // } else { // ConfigurationMenuAction.addRemovePreviewsAction(myRenderContext, group); // } return group; }
From source file:org.carrot2.text.linguistic.DefaultLanguageModelFactory.java
/** * Create default tokenizers.// w w w. j a v a 2 s .c o m */ private static EnumMap<LanguageCode, ITokenizerFactory> createDefaultTokenizers() { EnumMap<LanguageCode, ITokenizerFactory> map = Maps.newEnumMap(LanguageCode.class); /* * We use our own analyzer for all languages */ ITokenizerFactory defaultTokenizerFactory = new ExtendedWhitespaceTokenizerFactory(); for (LanguageCode lc : LanguageCode.values()) { map.put(lc, defaultTokenizerFactory); } /* * Chinese is an exception, we use an adapter around a tokenizer from Lucene. */ map.put(LanguageCode.CHINESE_SIMPLIFIED, new ChineseSimplifiedTokenizerFactory()); /* * Check for tokenizer availability and replace with a fallback if not available. */ for (LanguageCode lc : Sets.newTreeSet(map.keySet())) { try { map.get(lc).createInstance().reset(new StringReader("test")); } catch (Throwable t) { map.put(lc, new ExtendedWhitespaceTokenizerFactory()); String message = "Tokenizer 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.google.cloud.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.getRpcOption(), option.getValue()); checkArgument(prev == null, "Duplicate option %s", option); }/*from w w w .j av a 2s .co m*/ return ImmutableMap.copyOf(temp); }
From source file:org.kuali.rice.sql.config.spring.RiceSqlConfig.java
/** * Generates the default mapping of excluded paths from the {@code defaultIncludes} map. * * <p>//from w ww.j a va 2s . c o m * Generally, nothing is excluded, but there is a special case with {@code MetaInfGroup.DATA} where it does not * include either the {@code MetaInfGroup.SCHEMA} or {@code MetaInfGroup.CONSTRAINTS}. * </p> * * @param defaultIncludes the map of included paths * * @return the map of excluded paths */ protected Map<MetaInfGroup, String> getDefaultExcludes(Map<MetaInfGroup, String> defaultIncludes) { Map<MetaInfGroup, String> defaultExcludes = Maps.newEnumMap(MetaInfGroup.class); List<String> dataExcludes = Lists.newArrayList(defaultIncludes.get(MetaInfGroup.SCHEMA), defaultIncludes.get(MetaInfGroup.CONSTRAINTS)); defaultExcludes.put(MetaInfGroup.SCHEMA, NullUtils.NONE); defaultExcludes.put(MetaInfGroup.DATA, StringUtils.join(dataExcludes, ",")); defaultExcludes.put(MetaInfGroup.CONSTRAINTS, NullUtils.NONE); defaultExcludes.put(MetaInfGroup.OTHER, NullUtils.NONE); return defaultExcludes; }
From source file:lombok.ast.javac.JcTreeConverter.java
private Node toTree(JCTree node, FlagKey... keys) { Map<FlagKey, Object> map = Maps.newEnumMap(FlagKey.class); for (FlagKey key : keys) map.put(key, key);/* ww w . ja va 2s .co m*/ return toTree(node, map); }
From source file:org.waveprotocol.box.server.waveserver.QueryHelper.java
/** * Parses the search query.//www. j av a 2 s .com * * @param query the query. * @return the result map with query tokens. Never returns null. * @throws InvalidQueryException if the query contains invalid params. */ public static Map<TokenQueryType, Set<String>> parseQuery(String query) throws InvalidQueryException { Preconditions.checkArgument(query != null); query = query.trim(); // If query is empty - return. if (query.isEmpty()) { return Collections.emptyMap(); } String[] tokens = query.split("\\s+"); Map<TokenQueryType, Set<String>> tokensMap = Maps.newEnumMap(TokenQueryType.class); for (String token : tokens) { String[] pair = token.split(":"); if (pair.length != 2 || !TokenQueryType.hasToken(pair[0])) { String msg = "Invalid query param: " + token; throw new InvalidQueryException(msg); } String tokenValue = pair[1]; TokenQueryType tokenType = TokenQueryType.fromToken(pair[0]); // Verify the orderby param. if (tokenType.equals(TokenQueryType.ORDERBY)) { try { OrderByValueType.fromToken(tokenValue); } catch (IllegalArgumentException e) { String msg = "Invalid orderby query value: " + tokenValue; throw new InvalidQueryException(msg); } } Set<String> valuesPerToken = tokensMap.get(tokenType); if (valuesPerToken == null) { valuesPerToken = Sets.newLinkedHashSet(); tokensMap.put(tokenType, valuesPerToken); } valuesPerToken.add(tokenValue); } return tokensMap; }
From source file:com.google.caliper.util.ShortDuration.java
private static Map<TimeUnit, BigDecimal> createUnitToPicosMap() { Map<TimeUnit, BigDecimal> map = Maps.newEnumMap(TimeUnit.class); for (TimeUnit unit : TimeUnit.values()) { map.put(unit, new BigDecimal(picosIn(unit))); }/*from w w w . ja v a2 s. c om*/ return Collections.unmodifiableMap(map); }
From source file:org.n52.sos.ds.hibernate.cache.base.OfferingCacheUpdateTask.java
protected Map<ProcedureFlag, Set<String>> getProcedureIdentifier(Session session) throws OwsExceptionReport { Set<String> procedures = new HashSet<String>(0); Set<String> hiddenChilds = new HashSet<String>(0); if (obsConstSupported) { if (CollectionHelper.isNotEmpty(observationConstellationInfos)) { procedures.addAll(/* w w w .ja v a2 s. c o m*/ DatasourceCacheUpdateHelper.getAllProcedureIdentifiersFromObservationConstellationInfos( observationConstellationInfos, ProcedureFlag.PARENT)); hiddenChilds.addAll( DatasourceCacheUpdateHelper.getAllProcedureIdentifiersFromObservationConstellationInfos( observationConstellationInfos, ProcedureFlag.HIDDEN_CHILD)); } } else { List<String> list = new ProcedureDAO().getProcedureIdentifiersForOffering(offeringId, session); for (String procedureIdentifier : list) { procedures.add(CacheHelper.addPrefixOrGetProcedureIdentifier(procedureIdentifier)); } } Map<ProcedureFlag, Set<String>> allProcedures = Maps.newEnumMap(ProcedureFlag.class); allProcedures.put(ProcedureFlag.PARENT, procedures); allProcedures.put(ProcedureFlag.HIDDEN_CHILD, hiddenChilds); return allProcedures; }
From source file:lombok.ast.javac.JcTreeConverter.java
private Node toVariableDefinition(java.util.List<JCVariableDecl> decls, FlagKey... keys) { Map<FlagKey, Object> map = Maps.newEnumMap(FlagKey.class); for (FlagKey key : keys) map.put(key, key);// w w w . j a va 2 s . com return toVariableDefinition(decls, map); }