List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:com.pinterest.rocksplicator.controller.config.ConfigParser.java
/** * Convert cluster config data into a {@link ClusterBean}. * * @param clusterName name of the cluster * @param content binary config data// w w w. j a v a 2 s .c o m * @return ClusterBean or null if parsing failed */ @SuppressWarnings("unchecked") public static ClusterBean parseClusterConfig(String clusterName, byte[] content) { try { Map<String, Object> segmentMap = OBJECT_MAPPER.readValue(new String(content, UTF_8), HashMap.class); final List<SegmentBean> segments = new ArrayList<>(); for (Map.Entry<String, Object> entry : segmentMap.entrySet()) { Map<String, Object> segmentInfo = (Map<String, Object>) entry.getValue(); // num_leaf_segments must exist so that we can proceed if (!segmentInfo.containsKey(NUM_SHARDS)) { return null; } final SegmentBean segment = new SegmentBean().setName(entry.getKey()) .setNumShards((Integer) segmentInfo.get(NUM_SHARDS)); final List<HostBean> hosts = new ArrayList<>(); for (Map.Entry<String, Object> entry2 : segmentInfo.entrySet()) { // skip num_leaf_segments in shard map if (entry2.getKey().equals(NUM_SHARDS)) { continue; } HostBean host = parseHost(entry2.getKey()); List<String> shardList = (List<String>) entry2.getValue(); List<ShardBean> shards = shardList.stream().map(ConfigParser::parseShard) .collect(Collectors.toList()); host.setShards(shards); hosts.add(host); } segment.setHosts(hosts); segments.add(segment); } return new ClusterBean().setName(clusterName).setSegments(segments); } catch (IOException | IllegalArgumentException e) { LOG.error("Failed to parse cluster config.", e); return null; } }
From source file:fr.esiea.windmeal.fill.database.OwnerAndProviderImportationTest.java
private static Set<Comment> getCommentsFromMap(Map<String, String> dataMap) throws ServiceException, DaoException { int acc = 1;//from ww w.j a v a 2 s. co m Set<Comment> comments = new HashSet<Comment>(); while (dataMap.containsKey("commentemail" + acc)) { User user = getUser(dataMap.get("commentemail" + acc), dataMap.get("commentpassword" + acc), Profile.USER); userService.save(user); Comment comment = getComment(user, dataMap.get("commenttext" + acc), Integer.valueOf(dataMap.get("commentrate" + acc))); comments.add(comment); acc++; } return comments; }
From source file:org.craftercms.studio.impl.v1.web.http.MultiReadHttpServletRequestWrapper.java
public static void toMap(Iterable<NameValuePair> inputParams, Map<String, String[]> toMap) { for (NameValuePair e : inputParams) { String key = e.getName(); String value = e.getValue(); if (toMap.containsKey(key)) { String[] newValue = ArrayUtils.addAll(toMap.get(key), value); toMap.remove(key);// ww w . ja v a 2 s . c om toMap.put(key, newValue); } else { toMap.put(key, new String[] { value }); } } }
From source file:com.huawei.streaming.config.ConfVariable.java
private static String getConfValue(String name, Map<String, Object> conf, Map<String, String> userConf) throws StreamingException { if (userConf != null && userConf.containsKey(name)) { return userConf.get(name); }/* w ww .ja v a 2 s.c o m*/ if (conf != null && conf.containsKey(name)) { return conf.get(name).toString(); } StreamingException exception = new StreamingException(ErrorCode.CONFIG_NOT_FOUND, name); LOG.error(exception.getMessage(), exception); throw exception; }
From source file:io.cloudslang.lang.runtime.steps.AbstractExecutionData.java
protected static boolean handleEndLoopCondition(RunEnvironment runEnv, ExecutionRuntimeServices executionRuntimeServices, Long previousStepId, List<String> breakOn, String nodeName, Context flowContext, ReturnValues executableReturnValues, Map<String, Value> outputsBindingContext, Map<String, Value> publishValues, Map<String, Value> langVariables) { if (langVariables.containsKey(LoopCondition.LOOP_CONDITION_KEY)) { LoopCondition loopCondition = (LoopCondition) langVariables.get(LoopCondition.LOOP_CONDITION_KEY).get(); if (!shouldBreakLoop(breakOn, executableReturnValues) && loopCondition.hasMore()) { runEnv.putNextStepPosition(previousStepId); runEnv.getStack().pushContext(flowContext); throwEventOutputEnd(runEnv, executionRuntimeServices, nodeName, publishValues, previousStepId, new ReturnValues(publishValues, executableReturnValues.getResult()), outputsBindingContext); runEnv.getExecutionPath().forward(); return true; } else {//from w w w .j ava 2s . co m flowContext.removeLanguageVariable(LoopCondition.LOOP_CONDITION_KEY); } } return false; }
From source file:Maps.java
public static <K, V> Map<K, V> put(Map<K, V> map, K key, V value) { switch (map.size()) { case 0://w w w. j ava2s . co m // Empty -> Singleton return Collections.singletonMap(key, value); case 1: { if (map.containsKey(key)) { return create(key, value); } // Singleton -> HashMap Map<K, V> result = new HashMap<K, V>(); result.put(map.keySet().iterator().next(), map.values().iterator().next()); result.put(key, value); return result; } default: // HashMap map.put(key, value); return map; } }
From source file:org.jboss.tools.livereload.core.internal.util.ReloadCommandGenerator.java
/** * Generates the LiveReload command(s) for the given files. * /* ww w .java 2s . c o m*/ * @param files * @return the Livereload command(s) * @throws URISyntaxException * @throws IOException * @throws JsonMappingException * @throws JsonGenerationException */ public static List<String> generateReloadCommands(final List<IResource> files) throws IOException, URISyntaxException { final Map<String, List<IResource>> dispatchedFiles = dispatch(files); final List<String> commands = new ArrayList<String>(); // if HTML files changed, only generate command for those ones if (dispatchedFiles.containsKey("html")) { for (IResource file : dispatchedFiles.get("html")) { commands.add(buildRefreshCommand(file.getLocation().toOSString(), true)); } return commands; } // generate command for all changes files if those are only css files for (Entry<String, List<IResource>> entry : dispatchedFiles.entrySet()) { for (IResource file : entry.getValue()) { commands.add(buildRefreshCommand(file.getLocation().toOSString(), true)); } } return commands; }
From source file:com.erudika.para.security.FacebookAuthFilter.java
@SuppressWarnings("unchecked") private static String getPicture(String fbId, Map<String, Object> pic) { if (pic != null) { Map<String, Object> data = (Map<String, Object>) pic.get("data"); // try to get the direct url to the profile pic if (data != null && data.containsKey("url")) { return (String) data.get("url"); } else {//from w w w. java2 s . com return "http://graph.facebook.com/" + fbId + "/picture?width=400&height=400&type=square"; } } return null; }
From source file:io.cloudslang.content.database.utils.SQLUtils.java
@NotNull public static List<String> getRowsFromGlobalSessionMap( @NotNull final GlobalSessionObject<Map<String, Object>> globalSessionObject, @NotNull final String aKey) { final Map<String, Object> globalMap = globalSessionObject.get(); if (globalMap.containsKey(aKey)) { try {//w w w . ja v a 2 s .c o m return (List<String>) globalMap.get(aKey); } catch (Exception e) { globalMap.remove(aKey); globalSessionObject.setResource(new SQLSessionResource(globalMap)); } } return new ArrayList<>(); }
From source file:io.cloudslang.content.database.utils.SQLUtils.java
@NotNull public static String getStrColumns(@NotNull final GlobalSessionObject<Map<String, Object>> globalSessionObject, @NotNull final String strKeyCol) { final Map<String, Object> globalMap = globalSessionObject.get(); if (globalMap.containsKey(strKeyCol) && globalMap.get(strKeyCol) instanceof String) { try {//from w w w. j a v a 2s .c o m return (String) globalMap.get(strKeyCol); } catch (Exception e) { globalMap.remove(strKeyCol); globalSessionObject.setResource(new SQLSessionResource(globalMap)); } } return EMPTY; }