List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:ucigame.tile80.Sprite80UciGame.java
/** * /*from ww w . j ava2 s . c om*/ * @param host * @param json * @return */ public static Map<String, Sprite80UciGame> makeSpriteFactoryUciGame(Ucigame host, String json) { ImmutableMap.Builder<String, Sprite80UciGame> mapSpriteBuilder = ImmutableMap.builder(); Map<String, Object> spriteSheetStructure = new Gson().fromJson(json, Map.class); int w = ((Double) spriteSheetStructure.get("w")).intValue(); int h = ((Double) spriteSheetStructure.get("h")).intValue(); Image spriteSheetImage = host.getImage(spriteSheetStructure.get("file").toString()); for (Map<String, Object> frameStructure : (Collection<Map>) spriteSheetStructure.get("sheet")) { mapSpriteBuilder.put(frameStructure.get("name").toString(), new Sprite80UciGame(spriteSheetImage, host, frameStructure.get("name").toString(), w, h, ((Double) frameStructure.get("x")).intValue(), ((Double) frameStructure.get("y")).intValue())); } return mapSpriteBuilder.build(); }
From source file:org.mayocat.store.rdbms.dbi.mapper.EntityAndCountsJoinRowMapper.java
@Override protected EntityAndCountsJoinRow mapInternal(int index, final Map<String, Object> rowData) { EntityAndCountsJoinRow row = new EntityAndCountsJoinRow(); ImmutableMap.Builder dataBuilder = new ImmutableMap.Builder<String, Object>(); ImmutableMap.Builder countBuilder = new ImmutableMap.Builder<String, Long>(); for (String key : rowData.keySet()) { if (isCountKey(key)) { // This is a count row; countBuilder.put(key, (Long) rowData.get(key)); } else if (rowData.get(key) != null) { dataBuilder.put(key, rowData.get(key)); }//from w w w .java 2 s. c o m } row.setCounts(countBuilder.build()); row.setEntityData(dataBuilder.build()); return row; }
From source file:com.helion3.bedrock.commands.BedrockCommands.java
public static CommandSpec getCommand() { ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap .<List<String>, CommandCallable>builder(); builder.put(ImmutableList.of("reload"), ReloadCommand.getCommand()); return CommandSpec.builder().executor((src, args) -> { src.sendMessage(Text.of(Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi.\n"), TextColors.GRAY, "IRC: ", TextColors.WHITE, "irc.esper.net #prism")); return CommandResult.empty(); }).children(builder.build()).build(); }
From source file:com.cloudera.gertrude.server.HttpServletExperimentStateImpl.java
private static Map<Integer, String> indexDiversionCookies(List<String> diversionCookies, Cookie[] cookies) { ImmutableMap.Builder<Integer, String> b = ImmutableMap.builder(); for (int i = 0; i < diversionCookies.size(); i++) { String cookieName = diversionCookies.get(i); for (Cookie c : cookies) { if (cookieName.equals(c.getName())) { b.put(i, c.getValue());/* w ww. j av a 2 s.co m*/ break; } } } return b.build(); }
From source file:com.vertixtech.antiquity.graph.ElementUtils.java
/** * Returns {@link Element}'s properties as an immutable map. * // www.j av a2 s . co m * @return An immutable map of the specified {@link Element} properties exlcuding the specified keys */ public static Map<String, Object> getPropertiesAsMap(Element element, Set<String> excludedKeys) { Builder<String, Object> props = ImmutableMap.builder(); for (String key : element.getPropertyKeys()) { if ((excludedKeys != null) && excludedKeys.contains(key)) continue; props.put(key, element.getProperty(key)); } return props.build(); }
From source file:org.jmingo.parser.xml.dom.util.DomUtil.java
/** * Transform node attributes to map.//ww w .ja va 2 s . c om * * @param node the node {@link Node} * @return map : key - attribute name; value - attribute value */ public static Map<String, String> getAttributes(Node node) { Map<String, String> attributes = ImmutableMap.of(); if (node.hasAttributes()) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); // get attributes names and values NamedNodeMap nodeMap = node.getAttributes(); for (int i = 0; i < nodeMap.getLength(); i++) { Node currentNode = nodeMap.item(i); builder.put(currentNode.getNodeName(), currentNode.getNodeValue()); } attributes = builder.build(); } return attributes; }
From source file:org.jclouds.util.Maps2.java
/** * change the keys but keep the values in-tact. * /*from ww w . j a v a 2s .c om*/ * @param <K1> * input key type * @param <K2> * output key type * @param <V> * value type * @param in * input map to transform * @param fn * how to transform the values * @return immutableMap with the new keys. */ public static <K1, K2, V> Map<K2, V> transformKeys(Map<K1, V> in, Function<K1, K2> fn) { checkNotNull(in, "input map"); checkNotNull(fn, "function"); Builder<K2, V> returnVal = ImmutableMap.builder(); for (Entry<K1, V> entry : in.entrySet()) returnVal.put(fn.apply(entry.getKey()), entry.getValue()); return returnVal.build(); }
From source file:ninja.leaping.permissionsex.backend.file.FileOptionSubjectData.java
static FileOptionSubjectData fromNode(ConfigurationNode node) throws ObjectMappingException, PermissionsLoadingException { ImmutableMap.Builder<Set<Entry<String, String>>, DataEntry> map = ImmutableMap.builder(); if (node.hasListChildren()) { for (ConfigurationNode child : node.getChildrenList()) { if (!child.hasMapChildren()) { throw new PermissionsLoadingException(_( "Each context section must be of map type! Check that no duplicate nesting has occurred.")); }/*from w w w. j av a 2 s.c o m*/ Set<Entry<String, String>> contexts = contextsFrom(child); DataEntry value = MAPPER.bindToNew().populate(child); map.put(contexts, value); } } return new FileOptionSubjectData(map.build()); }
From source file:infowall.web.spring.ControllerDsl.java
public static ModelAndView render(String viewName, Errors errors, Map<String, Object> modelMap) { Map<String, Object> actualModel; if (errors.haveOccurred()) { actualModel = new ImmutableMap.Builder<String, Object>().putAll(modelMap) .put("errors", errors.getMessages()).build(); } else {/*from w w w .j a v a 2 s .c om*/ actualModel = modelMap; } return new ModelAndView(viewName, actualModel); }
From source file:com.yahoo.yqlplus.engine.java.SourceNamedBindingModule.java
@SuppressWarnings("unchecked") public SourceNamedBindingModule(Object... kvPairs) { ImmutableMap.Builder<String, Class<? extends Source>> sources = ImmutableMap.builder(); for (int i = 0; i < kvPairs.length; i += 2) { sources.put((String) kvPairs[i], (Class<? extends Source>) kvPairs[i + 1]); }/*from w w w .j a va 2s . co m*/ this.sources = sources.build(); }