List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:Main.java
/** * Extract default values of variables defined in the given string. * Default values are used to populate the variableDefs map. Variables * already defined in this map will NOT be modified. * * @param string string to extract default values from. * @param variableDefs map which default values will be added to. *//*from w w w.j av a2 s .c o m*/ public static void extractVariableDefaultsFromString(String string, Map<String, String> variableDefs) { Matcher variableMatcher = variablePattern.matcher(string); while (variableMatcher.find()) { String varString = variableMatcher.group(1); int eqIdx = varString.indexOf("="); if (eqIdx > -1) { String varName = varString.substring(0, eqIdx).trim(); if (!variableDefs.containsKey(varName)) variableDefs.put(varName, varString.substring(eqIdx + 1, varString.length())); } } }
From source file:com.phoenixnap.oss.ramlapisync.naming.RamlHelper.java
/** * Tree merging algorithm, if a resource already exists it will not overwrite and add all children to the existing resource * @param existing The existing resource in the model * @param resource The resource to merge in * @param addActions If true it will copy all actions even if the resource itself isnt copied *///from w ww .java2 s. co m public static void mergeResources(RamlResource existing, RamlResource resource, boolean addActions) { Map<String, RamlResource> existingChildResources = existing.getResources(); Map<String, RamlResource> newChildResources = resource.getResources(); for (String newChildKey : newChildResources.keySet()) { if (!existingChildResources.containsKey(newChildKey)) { existing.addResource(newChildKey, newChildResources.get(newChildKey)); } else { mergeResources(existingChildResources.get(newChildKey), newChildResources.get(newChildKey), addActions); } } if (addActions) { existing.addActions(resource.getActions()); } }
From source file:org.imsglobal.lti.LTIUtil.java
public static Map<String, List<String>> setParameter(Map<String, List<String>> parameters, String name, String value) {// www .j av a 2 s. c o m if (parameters.containsKey(name)) { List<String> itemList = parameters.get(name); if (itemList.contains(value)) { //no-op } else { itemList.add(value); parameters.put(name, itemList); } } else { List<String> itemList = new ArrayList<String>(); itemList.add(value); parameters.put(name, itemList); } return parameters; }
From source file:com.siblinks.ws.service.impl.VideoSubscriptionsServiceImpl.java
/** * //from www. j a va2 s . c o m * @param map * @param key * @param value * @throws ParseException */ private static void addMapVideo(final Map<String, List<Object>> map, final String key, final Object value) throws ParseException { if (map.containsKey(key)) { List<Object> lst = map.get(key); lst.add(value); } else { List<Object> lst = new ArrayList<Object>(); lst.add(value); map.put(key, lst); } }
From source file:nl.minbzk.dwr.zoeken.enricher.aci.ImportController.java
/** * Split up the query map. Note that this is not a particularly exhaustive implementation. * /*from w w w .ja v a2 s . c om*/ * @param query * @return Map<String, String> * @throws UnsupportedEncodingException */ public static Map<String, String[]> parseQueryString(final String query) throws UnsupportedEncodingException { Map<String, String[]> result = new HashMap<String, String[]>(); for (String param : query.split("&")) if (result.containsKey(param.split("=")[0])) result.put(param.split("=")[0], (String[]) ArrayUtils.addAll( new String[] { URLDecoder.decode(param.split("=")[1], "UTF-8") }, result.get(param.split("=")[0]))); else result.put(param.split("=")[0], new String[] { URLDecoder.decode(param.split("=")[1], "UTF-8") }); return result; }
From source file:bammerbom.ultimatecore.bukkit.configuration.ConfigurationSerialization.java
/** * Attempts to deserialize the given arguments into a new instance of the * given class.//from w w w.jav a2 s . c o m * <p/> * The class must implement {@link ConfigurationSerializable}, including the * extra methods as specified in the javadoc of ConfigurationSerializable. * <p/> * If a new instance could not be made, an example being the class not fully * implementing the interface, null will be returned. * * @param args Arguments for deserialization * @return New instance of the specified class */ public static ConfigurationSerializable deserializeObject(Map<String, ?> args) { Class<? extends ConfigurationSerializable> clazz = null; if (args.containsKey(SERIALIZED_TYPE_KEY)) { try { String alias = (String) args.get(SERIALIZED_TYPE_KEY); if (alias == null) { throw new IllegalArgumentException("Cannot have null alias"); } clazz = getClassByAlias(alias); if (clazz == null) { throw new IllegalArgumentException("Specified class does not exist ('" + alias + "')"); } } catch (ClassCastException ex) { ex.fillInStackTrace(); throw ex; } } else { throw new IllegalArgumentException("Args doesn't contain type key ('" + SERIALIZED_TYPE_KEY + "')"); } return new ConfigurationSerialization(clazz).deserialize(args); }
From source file:azkaban.server.HttpRequestUtils.java
/** * parse a string as number and throws exception if parsed value is not a * valid integer/*from ww w . j a v a 2 s . c om*/ * @param params * @param paramName * @throws ExecutorManagerException if paramName is not a valid integer */ public static boolean validateIntegerParam(Map<String, String> params, String paramName) throws ExecutorManagerException { if (params != null && params.containsKey(paramName) && !StringUtils.isNumeric(params.get(paramName))) { throw new ExecutorManagerException(paramName + " should be an integer"); } return true; }
From source file:org.ebayopensource.twin.TwinConnection.java
@SuppressWarnings("unchecked") private static TwinException deserializeException(TwinError responseCode, Map<String, Object> exception) { TwinException ex = responseCode.create((String) exception.get("message")); ex.className = (String) exception.get("class"); if (exception.containsKey("stackTrace")) { List<?> array = (List<?>) exception.get("stackTrace"); List<StackTraceElement> trace = new ArrayList<StackTraceElement>(); for (Object elt : array) { Map<String, Object> element = (Map<String, Object>) elt; trace.add(new StackTraceElement((String) element.get("className"), (String) element.get("methodName"), (String) element.get("fileName"), (element.containsKey("lineNumber") ? ((Number) element.get("lineNumber")).intValue() : -1)));//w w w . j a v a 2 s .c o m } for (StackTraceElement elt : new Exception().getStackTrace()) { if (TwinConnection.class.getName().equals(elt.getClassName())) continue; if (Application.class.getName().equals(elt.getClassName()) && ("ensureSuccess".equals(elt.getMethodName()) || elt.getMethodName().startsWith("request"))) continue; trace.add(elt); } ex.setStackTrace(trace.toArray(new StackTraceElement[trace.size()])); } if (exception.containsKey("cause") && exception.get("cause") != null) ex.initCause( deserializeException(TwinError.UnknownError, (Map<String, Object>) exception.get("cause"))); return ex; }
From source file:com.tjtolley.roborally.game.BoardDefinition.java
public static BoardDefinition fromSavedBoard(String boardName) { try {//from w w w . j a v a 2 s. c om ObjectMapper mapper = new ObjectMapper(); File file = new File("src/main/resources/assets/boards/" + boardName.toLowerCase() + ".json"); if (!file.exists()) { throw new IllegalArgumentException("File not found"); } Map readValue = mapper.readValue(file, Map.class); int width = (int) readValue.get("width"); int height = (int) readValue.get("height"); List<List<Map<String, Object>>> tiles = (List<List<Map<String, Object>>>) readValue.get("board"); List<List<Tile>> board = Lists.newArrayList(); for (int row = 0; row < width; row++) { board.add(row, Lists.<Tile>newArrayList()); } for (List<Map<String, Object>> list : tiles) { for (Map<String, Object> tileMap : list) { final int x = (int) tileMap.get("x"); List<Tile> column = board.get(x); final int y = (int) tileMap.get("y"); final Direction direction = tileMap.containsKey("rotation") ? Direction.valueOf((String) tileMap.get("rotation")) : Direction.NORTH; final Tile.EdgeType northEdge = tileMap.containsKey("northEdge") ? EdgeType.valueOf((String) tileMap.get("northEdge")) : Tile.EdgeType.EMPTY; final Tile.EdgeType southEdge = tileMap.containsKey("southEdge") ? EdgeType.valueOf((String) tileMap.get("southEdge")) : Tile.EdgeType.EMPTY; final Tile.EdgeType eastEdge = tileMap.containsKey("eastEdge") ? EdgeType.valueOf((String) tileMap.get("eastEdge")) : Tile.EdgeType.EMPTY; final Tile.EdgeType westEdge = tileMap.containsKey("westEdge") ? EdgeType.valueOf((String) tileMap.get("westEdge")) : Tile.EdgeType.EMPTY; column.add(y, new Tile(Tile.TileType.valueOf((String) tileMap.get("tileType")), x, y, direction, northEdge, southEdge, eastEdge, westEdge)); } } return new BoardDefinition((String) readValue.get("name"), board, width, height); } catch (IOException ex) { throw new IllegalStateException("Unable to parse board", ex); } }
From source file:com.pkrete.xrd4j.rest.util.ClientUtil.java
/** * Builds the target URL based on the given based URL and parameters Map. * @param url base URL/*from w w w .jav a 2 s .c om*/ * @param params URL parameters * @return comlete URL containing the base URL with all the parameters * appended */ public static String buildTargetURL(String url, Map<String, String> params) { logger.debug("Target URL : \"{}\".", url); if (params == null || params.isEmpty()) { logger.debug("URL parameters list is null or empty. Nothing to do here. Return target URL."); return url; } if (params.containsKey("resourceId")) { logger.debug("Resource ID found from parameters map. Resource ID value : \"{}\".", params.get("resourceId")); if (!url.endsWith("/")) { url += "/"; } url += params.get("resourceId"); params.remove("resourceId"); logger.debug("Resource ID added to URL : \"{}\".", url); } StringBuilder paramsString = new StringBuilder(); for (String key : params.keySet()) { if (paramsString.length() > 0) { paramsString.append("&"); } paramsString.append(key).append("=").append(params.get(key)); logger.debug("Parameter : \"{}\"=\"{}\"", key, params.get(key)); } if (!url.contains("?") && !params.isEmpty()) { url += "?"; } else if (url.contains("?") && !params.isEmpty()) { if (!url.endsWith("?") && !url.endsWith("&")) { url += "&"; } } url += paramsString.toString(); logger.debug("Request parameters added to URL : \"{}\".", url); return url; }