List of usage examples for java.util Map remove
V remove(Object key);
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceProfile.java
private static Path takeTempPath(DirectDataSourceProfile profile, Map<String, String> attributes, Configuration conf, Path fsPath) { assert attributes != null; assert conf != null; assert fsPath != null; String tempPathString = attributes.remove(KEY_TEMP); Path tempPath;/*from w ww . j a v a2 s.c om*/ if (tempPathString != null) { tempPath = new Path(tempPathString); } else { tempPath = new Path(fsPath, DEFAULT_TEMP_SUFFIX); } return tempPath; }
From source file:com.palantir.ptoss.cinch.core.BindingContext.java
private static Map<String, ObjectFieldMethod> indexMethods(List<ObjectFieldMethod> methods) throws IllegalArgumentException { Map<String, ObjectFieldMethod> map = Maps.newHashMap(); Set<String> ambiguousNames = Sets.newHashSet(); for (ObjectFieldMethod ofm : methods) { Method method = ofm.getMethod(); String blindKey = method.getName(); if (!ambiguousNames.contains(blindKey)) { if (map.containsKey(blindKey)) { map.remove(blindKey); ambiguousNames.add(blindKey); } else { map.put(blindKey, ofm);//w ww .j a v a 2 s . co m } } String fieldName = ofm.getField() == null ? "this" : ofm.getField().getName(); String qualifiedKey = fieldName + "." + blindKey; map.put(qualifiedKey, ofm); } return map; }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceProfile.java
private static long takeMinFragment(DirectDataSourceProfile profile, Map<String, String> attributes, Configuration conf) throws IOException { assert profile != null; assert attributes != null; assert conf != null; String string = attributes.remove(KEY_MIN_FRAGMENT); if (string == null) { return DEFAULT_MIN_FRAGMENT; }// w ww .j a v a2 s . c om try { long value = Long.parseLong(string); if (value == 0) { throw new IOException(MessageFormat.format("Minimum fragment size must not be zero: {0}", fqn(profile, KEY_MIN_FRAGMENT))); } return value; } catch (NumberFormatException e) { throw new IOException(MessageFormat.format("Minimum fragment size must be integer: {0}={1}", fqn(profile, KEY_MIN_FRAGMENT), string)); } }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceProfile.java
private static long takePrefFragment(DirectDataSourceProfile profile, Map<String, String> attributes, Configuration conf) throws IOException { assert profile != null; assert attributes != null; assert conf != null; String string = attributes.remove(KEY_PREF_FRAGMENT); if (string == null) { return DEFAULT_PREF_FRAGMENT; }/*from ww w . j ava2 s.c o m*/ try { long value = Long.parseLong(string); if (value <= 0) { throw new IOException(MessageFormat.format("Preferred fragment size must be > 0: {0}={1}", fqn(profile, KEY_PREF_FRAGMENT), string)); } return value; } catch (NumberFormatException e) { throw new IOException(MessageFormat.format("Preferred fragment size must be integer: {0}={1}", fqn(profile, KEY_PREF_FRAGMENT), string)); } }
From source file:cop.raml.processor.RestApi.java
@NotNull private static Resource add(@NotNull Map<String, Resource> resources, @NotNull String path) { path = path.startsWith("/") ? path : '/' + path; for (Resource resource : resources.values()) { String basePath = resource.getPath(); if (basePath.equals(path)) return resource; if (path.startsWith(basePath + '/')) return add(resource.children, StringUtils.removeStart(path, basePath)); String commonPath = findLongestPrefix(basePath, path); if (commonPath.isEmpty()) continue; Resource parent = new Resource(commonPath, resource); resources.remove(basePath); resources.put(parent.getPath(), parent); resource.removePathPrefix(commonPath); resource.removeUriParameters(/*from w w w . j av a 2s. co m*/ parent.getUriParameters().stream().map(Parameter::getName).collect(Collectors.toList())); parent.children.put(resource.getPath(), resource); String suffix = StringUtils.removeStart(path, commonPath); if (StringUtils.isBlank(suffix)) return parent; return add(parent.children, StringUtils.removeStart(path, commonPath)); } Resource resource = new Resource(path); resources.put(resource.getPath(), resource); return resource; }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceProfile.java
private static boolean takeBoolean(DirectDataSourceProfile profile, Map<String, String> attributes, String key, boolean defaultValue) throws IOException { assert profile != null; assert attributes != null; assert key != null; String string = attributes.remove(key); if (string == null) { return defaultValue; }//from w ww. j a v a2 s. co m if (string.equalsIgnoreCase("true")) { //$NON-NLS-1$ return true; } else if (string.equalsIgnoreCase("false")) { //$NON-NLS-1$ return false; } else { throw new IOException(MessageFormat.format("\"{0}\" must be boolean: {1}", fqn(profile, key), string)); } }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceProfile.java
private static int takePositive(DirectDataSourceProfile profile, Map<String, String> attributes, String key, int defaultValue) throws IOException { assert profile != null; assert attributes != null; assert key != null; String string = attributes.remove(key); if (string == null) { return defaultValue; }//from w ww.j a v a 2 s .c o m try { int result = Integer.parseInt(string.trim()); if (result < 0) { throw new IOException( MessageFormat.format("\"{0}\" must be positive integer: {1}", fqn(profile, key), string)); } return result; } catch (NumberFormatException e) { throw new IOException( MessageFormat.format("\"{0}\" must be positive integer: {1}", fqn(profile, key), string), e); } }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceProfile.java
private static long takePositive(DirectDataSourceProfile profile, Map<String, String> attributes, String key, long defaultValue) throws IOException { assert profile != null; assert attributes != null; assert key != null; String string = attributes.remove(key); if (string == null) { return defaultValue; }/*from w ww .j ava 2 s . co m*/ try { long result = Integer.parseInt(string.trim()); if (result < 0) { throw new IOException( MessageFormat.format("\"{0}\" must be positive integer: {1}", fqn(profile, key), string)); } return result; } catch (NumberFormatException e) { throw new IOException( MessageFormat.format("\"{0}\" must be positive integer: {1}", fqn(profile, key), string), e); } }
From source file:com.baidu.rigel.biplatform.ac.util.HttpRequest.java
/** * ?URL??POST//from ww w.j av a 2 s. com * * @param client httpclient * @param url ??URL * @param param ?? name1=value1&name2=value2 ? * @return URL ?? */ public static String sendPost(HttpClient client, String url, Map<String, String> params) { if (client == null) { throw new IllegalArgumentException("client is null"); } if (params == null) { params = new HashMap<String, String>(1); } String requestUrl = processPlaceHolder(url, params); String cookie = params.remove(COOKIE_PARAM_NAME); if (requestUrl.contains("?")) { String[] urls = requestUrl.split("?"); requestUrl = urls[0]; String[] urlParams = urls[1].split("&"); for (String param : urlParams) { String[] paramSplit = param.split("="); params.put(paramSplit[0], paramSplit[1]); } } List<NameValuePair> nameValues = new ArrayList<NameValuePair>(); params.forEach((k, v) -> { NameValuePair nameValuePair = new BasicNameValuePair(k, v); nameValues.add(nameValuePair); }); String prefix = "", suffix = ""; String[] addresses = new String[] { requestUrl }; if (requestUrl.contains("[") && requestUrl.contains("]")) { addresses = requestUrl.substring(requestUrl.indexOf("[") + 1, requestUrl.indexOf("]")).split(" "); prefix = requestUrl.substring(0, requestUrl.indexOf("[")); suffix = requestUrl.substring(requestUrl.indexOf("]") + 1); } LOGGER.info("start to send post:" + requestUrl); long current = System.currentTimeMillis(); for (String address : addresses) { String postUrl = prefix + address + suffix; LOGGER.info("post url is : " + postUrl); try { HttpUriRequest request = RequestBuilder.post().setUri(postUrl) // .addParameters(nameValues.toArray(new NameValuePair[0])) .setEntity(new UrlEncodedFormEntity(nameValues, "utf-8")).build(); if (StringUtils.isNotBlank(cookie)) { // ?cookie request.addHeader(new BasicHeader(COOKIE_PARAM_NAME, cookie)); } // client. HttpResponse response = client.execute(request); String content = processHttpResponse(client, response, params, false); StringBuilder sb = new StringBuilder(); sb.append("end send post :").append(postUrl).append(" params:").append(nameValues).append(" cost:") .append(System.currentTimeMillis() - current); LOGGER.info(sb.toString()); return content; } catch (Exception e) { LOGGER.warn("send post error " + requestUrl + ",retry next one", e); } } throw new RuntimeException("send post failed[" + requestUrl + "]. params :" + nameValues); }
From source file:com.clican.pluto.common.type.Type.java
public static Type decodeProperty(String description) { Map<String, String> properties = new HashMap<String, String>(); for (String s : description.split(";")) { String[] entry = s.split("="); if (entry.length == 1) { properties.put(entry[0], null); } else {/*w w w . j a va 2s .c o m*/ properties.put(entry[0], entry[1]); } } Type tepe = null; if (properties.get("class") != null) { try { tepe = (Type) Class.forName(properties.get("class")).newInstance(); } catch (Exception e) { throw new PlutoException(e); } } else { throw new PlutoException("Cannot get class property from dymanic property's control annotation."); } properties.remove("class"); for (String key : properties.keySet()) { String value = properties.get(key); if (org.apache.commons.lang.StringUtils.isEmpty(value)) { continue; } try { org.apache.commons.beanutils.BeanUtils.setProperty(tepe, key, value); } catch (Exception e) { List<String> listValue = StringUtils.getListFromSymbolSplitString(value, ","); try { org.apache.commons.beanutils.BeanUtils.setProperty(tepe, key, listValue); } catch (Exception ex) { throw new PlutoException(ex); } } } return tepe; }