List of usage examples for java.util Map putAll
void putAll(Map<? extends K, ? extends V> m);
From source file:Maps.java
public static <K, V> Map<K, V> putAll(Map<K, V> map, Map<K, V> toAdd) { switch (toAdd.size()) { case 0://from w ww . j a va2s . c om // No-op. return map; case 1: { // Add one element. K key = toAdd.keySet().iterator().next(); return put(map, key, toAdd.get(key)); } default: // True list merge, result >= 2. switch (map.size()) { case 0: return new HashMap<K, V>(toAdd); case 1: { HashMap<K, V> result = new HashMap<K, V>(); K key = map.keySet().iterator().next(); result.put(key, map.get(key)); result.putAll(toAdd); return normalize(result); } default: map.putAll(toAdd); return map; } } }
From source file:com.sunchenbin.store.feilong.core.net.ParamUtil.java
/** * parameter array value map.//from w w w. j a va 2 s.c o m * * @param uriString * the uri string * @param queryString * the query * @param arrayValueMap * the name and array value map * @param charsetType * ??, {@link CharsetType}<br> * <span style="color:green">null empty,?,?</span><br> * ??,??,ie?chrome? url ,? * @return the string * @since 1.4.0 */ private static String addParameterArrayValueMap(String uriString, String queryString, Map<String, String[]> arrayValueMap, String charsetType) { Map<String, String[]> singleValueMap = new HashMap<String, String[]>(); singleValueMap.putAll(arrayValueMap); if (Validator.isNotNullOrEmpty(queryString)) { // ? action before ?? // "action": "https://202.6.215.230:8081/purchasing/purchase.do?action=loginRequest", // "fullEncodedUrl":"https://202.6.215.230:8081/purchasing/purchase.do?action=loginRequest?miscFee=0&descp=&klikPayCode=03BELAV220&transactionDate=23%2F03%2F2014+02%3A40%3A19¤cy=IDR", Map<String, String[]> originalMap = toSafeArrayValueMap(queryString, null); singleValueMap.putAll(originalMap); } singleValueMap.putAll(arrayValueMap); return combineUrl(URIUtil.getFullPathWithoutQueryString(uriString), singleValueMap, charsetType); }
From source file:io.fabric8.kubernetes.pipeline.devops.ApplyStepExecution.java
protected static void addPropertiesFileToMap(File file, Map<String, String> answer) throws AbortException { if (file != null && file.isFile() && file.exists()) { try (FileInputStream in = new FileInputStream(file)) { Properties properties = new Properties(); properties.load(in);// w ww . ja v a 2 s . c o m Map<String, String> map = toMap(properties); answer.putAll(map); } catch (IOException e) { throw new AbortException("Failed to load properties file: " + file + ". " + e); } } }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrUtil.java
public static Map<String, Object> jcrObjectAsMap(JcrObject obj) { String nodeName = obj.getNodeName(); String path = obj.getPath();//from ww w . j a v a 2s . c om String identifier = null; try { identifier = obj.getObjectId(); } catch (AccessDeniedException e) { log.debug("Access denied", e); throw new AccessControlException(e.getMessage()); } catch (RepositoryException e) { throw new RuntimeException(e); } String type = obj.getTypeName(); Map<String, Object> props = obj.getProperties(); Map<String, Object> finalProps = new HashMap<>(); if (props != null) { finalProps.putAll(finalProps); } finalProps.put("nodeName", nodeName); if (identifier != null) { finalProps.put("nodeIdentifier", identifier); } finalProps.put("nodePath", path); finalProps.put("nodeType", type); return finalProps; }
From source file:eu.trentorise.smartcampus.protocolcarrier.Communicator.java
private static HttpRequestBase buildRequest(MessageRequest msgRequest, String appToken, String authToken) throws URISyntaxException, UnsupportedEncodingException { String host = msgRequest.getTargetHost(); if (host == null) throw new URISyntaxException(host, "null URI"); if (!host.endsWith("/")) host += '/'; String address = msgRequest.getTargetAddress(); if (address == null) address = ""; if (address.startsWith("/")) address = address.substring(1);/* w w w . j a va 2 s .c o m*/ String uriString = host + address; try { URL url = new URL(uriString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); uriString = uri.toURL().toString(); } catch (MalformedURLException e) { throw new URISyntaxException(uriString, e.getMessage()); } if (msgRequest.getQuery() != null) uriString += "?" + msgRequest.getQuery(); // new URI(uriString); HttpRequestBase request = null; if (msgRequest.getMethod().equals(Method.POST)) { HttpPost post = new HttpPost(uriString); HttpEntity httpEntity = null; if (msgRequest.getRequestParams() != null) { // if body and requestparams are either not null there is an // exception if (msgRequest.getBody() != null && msgRequest != null) { throw new IllegalArgumentException("body and requestParams cannot be either populated"); } httpEntity = new MultipartEntity(); for (RequestParam param : msgRequest.getRequestParams()) { if (param.getParamName() == null || param.getParamName().trim().length() == 0) { throw new IllegalArgumentException("paramName cannot be null or empty"); } if (param instanceof FileRequestParam) { FileRequestParam fileparam = (FileRequestParam) param; ((MultipartEntity) httpEntity).addPart(param.getParamName(), new ByteArrayBody( fileparam.getContent(), fileparam.getContentType(), fileparam.getFilename())); } if (param instanceof ObjectRequestParam) { ObjectRequestParam objectparam = (ObjectRequestParam) param; ((MultipartEntity) httpEntity).addPart(param.getParamName(), new StringBody(convertObject(objectparam.getVars()))); } } // mpe.addPart("file", // new ByteArrayBody(msgRequest.getFileContent(), "")); // post.setEntity(mpe); } if (msgRequest.getBody() != null) { httpEntity = new StringEntity(msgRequest.getBody(), Constants.CHARSET); ((StringEntity) httpEntity).setContentType(msgRequest.getContentType()); } post.setEntity(httpEntity); request = post; } else if (msgRequest.getMethod().equals(Method.PUT)) { HttpPut put = new HttpPut(uriString); if (msgRequest.getBody() != null) { StringEntity se = new StringEntity(msgRequest.getBody(), Constants.CHARSET); se.setContentType(msgRequest.getContentType()); put.setEntity(se); } request = put; } else if (msgRequest.getMethod().equals(Method.DELETE)) { request = new HttpDelete(uriString); } else { // default: GET request = new HttpGet(uriString); } Map<String, String> headers = new HashMap<String, String>(); // default headers if (appToken != null) { headers.put(RequestHeader.APP_TOKEN.toString(), appToken); } if (authToken != null) { // is here for compatibility headers.put(RequestHeader.AUTH_TOKEN.toString(), authToken); headers.put(RequestHeader.AUTHORIZATION.toString(), "Bearer " + authToken); } headers.put(RequestHeader.ACCEPT.toString(), msgRequest.getContentType()); if (msgRequest.getCustomHeaders() != null) { headers.putAll(msgRequest.getCustomHeaders()); } for (String key : headers.keySet()) { request.addHeader(key, headers.get(key)); } return request; }
From source file:com.siemens.sw360.commonIO.TypeMappings.java
@NotNull public static <T, U> Map<U, T> getIdentifierToTypeMapAndWriteMissingToDatabase( LicenseService.Iface licenseClient, InputStream in, Class<T> clazz, Class<U> uClass) throws TException { Map<U, T> typeMap; List<CSVRecord> records = ImportCSV.readAsCSVRecords(in); final List<T> recordsToAdd = simpleConvert(records, clazz); final List<T> fullList = CommonUtils.nullToEmptyList(getAllFromDB(licenseClient, clazz)); typeMap = Maps.newHashMap(Maps.uniqueIndex(fullList, getIdentifier(clazz, uClass))); final ImmutableList<T> filteredList = getElementsWithIdentifiersNotInMap(getIdentifier(clazz, uClass), typeMap, recordsToAdd);/*from ww w . jav a2 s. c om*/ List<T> added = null; if (filteredList.size() > 0) { added = addAlltoDB(licenseClient, clazz, filteredList); } if (added != null) typeMap.putAll(Maps.uniqueIndex(added, getIdentifier(clazz, uClass))); return typeMap; }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrUtil.java
public static Map<String, Object> nodeAsMap(Node obj) throws RepositoryException { try {// w ww . j ava 2s.com String nodeName = obj.getName(); String path = obj.getPath(); String identifier = obj.getIdentifier(); String type = obj.getPrimaryNodeType() != null ? obj.getPrimaryNodeType().getName() : ""; Map<String, Object> props = JcrPropertyUtil.getProperties(obj); Map<String, Object> finalProps = new HashMap<>(); if (props != null) { finalProps.putAll(finalProps); } finalProps.put("nodeName", nodeName); if (identifier != null) { finalProps.put("nodeIdentifier", identifier); } finalProps.put("nodePath", path); finalProps.put("nodeType", type); return finalProps; } catch (AccessDeniedException e) { log.debug("Access denied", e); throw new AccessControlException(e.getMessage()); } }
From source file:io.apiman.cli.util.DeclarativeUtil.java
/** * Load the Declaration from the given Path, using the mapper provided. * * @param path the Path to the declaration * @param mapper the Mapper to use//from ww w. ja v a2 s.co m * @param properties property placeholders to resolve * @return the Declaration */ public static Declaration loadDeclaration(Path path, ObjectMapper mapper, Collection<String> properties) { final Map<String, String> parsedProperties = BeanUtil.parseReplacements(properties); try (InputStream is = Files.newInputStream(path)) { String fileContents = CharStreams.toString(new InputStreamReader(is)); LOGGER.trace("Declaration file raw: {}", fileContents); Declaration declaration = loadDeclaration(mapper, fileContents, parsedProperties); // check for the presence of shared properties in the declaration final Map<String, String> sharedProperties = ofNullable(declaration.getShared()) .map(SharedItems::getProperties).orElse(Collections.emptyMap()); if (sharedProperties.size() > 0) { LOGGER.trace("Resolving {} shared placeholders", sharedProperties.size()); parsedProperties.putAll(sharedProperties); // this is not very efficient, as it requires parsing the declaration twice declaration = loadDeclaration(mapper, fileContents, parsedProperties); } return declaration; } catch (IOException e) { throw new DeclarativeException(e); } }
From source file:com.csc.fi.ioapi.utils.JerseyJsonLDClient.java
public static Response getExportGraph(String graph, boolean raw, String lang, String ctype) { try {//from ww w . j a v a2 s . co m ContentType contentType = ContentType.create(ctype); Lang rdfLang = RDFLanguages.contentTypeToLang(contentType); if (rdfLang == null) { logger.info("Unknown RDF type: " + ctype); return JerseyResponseManager.notFound(); } DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(services.getCoreReadAddress()); Model model = accessor.getModel(graph); OutputStream out = new ByteArrayOutputStream(); Response response = JerseyJsonLDClient.getGraphResponseFromService(graph + "#ExportGraph", services.getCoreReadAddress(), ctype); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { return JerseyResponseManager.unexpected(); } /* TODO: Remove builders */ ResponseBuilder rb; RDFDataMgr.write(out, model, rdfLang); if (rdfLang.equals(Lang.JSONLD)) { Map<String, Object> jsonModel = null; try { jsonModel = (Map<String, Object>) JsonUtils.fromString(out.toString()); } catch (IOException ex) { Logger.getLogger(ExportModel.class.getName()).log(Level.SEVERE, null, ex); return JerseyResponseManager.unexpected(); } Map<String, Object> frame = new HashMap<String, Object>(); //Map<String,Object> frame = (HashMap<String,Object>) LDHelper.getExportContext(); Map<String, Object> context = (Map<String, Object>) jsonModel.get("@context"); context.putAll(LDHelper.CONTEXT_MAP); frame.put("@context", context); frame.put("@type", "owl:Ontology"); Object data; try { data = JsonUtils.fromInputStream(response.readEntity(InputStream.class)); rb = Response.status(response.getStatus()); try { JsonLdOptions options = new JsonLdOptions(); Object framed = JsonLdProcessor.frame(data, frame, options); ObjectMapper mapper = new ObjectMapper(); rb.entity(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(framed)); } catch (NullPointerException ex) { logger.log(Level.WARNING, null, "DEFAULT GRAPH IS NULL!"); return rb.entity(JsonUtils.toString(data)).build(); } catch (JsonLdError ex) { logger.log(Level.SEVERE, null, ex); return JerseyResponseManager.serverError(); } } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); return JerseyResponseManager.serverError(); } } else { rb = Response.status(response.getStatus()); rb.entity(response.readEntity(InputStream.class)); } if (!raw) { rb.type(contentType.getContentType()); } else { rb.type("text/plain"); } return rb.build(); } catch (Exception ex) { logger.log(Level.WARNING, "Expect the unexpected!", ex); return JerseyResponseManager.serverError(); } }
From source file:com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.java
/** * Return a map of all the processors, by processorId under a process group, including all children * * @param group a process group// w w w. ja v a2s . c o m * @return a map of all processors in the group, including all child process groups */ public static Map<String, ProcessorDTO> getProcessorsMap(ProcessGroupDTO group) { Map<String, ProcessorDTO> processors = new HashMap<>(); if (group != null) { if (group.getContents() != null) { for (ProcessorDTO processorDTO : group.getContents().getProcessors()) { processors.put(processorDTO.getId(), processorDTO); } if (group.getContents().getProcessGroups() != null) { for (ProcessGroupDTO groupDTO : group.getContents().getProcessGroups()) { processors.putAll(getProcessorsMap(groupDTO)); } } } } return processors; }