List of usage examples for java.util HashMap get
public V get(Object key)
From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.RemoteParForUtils.java
/** * For remote MR parfor workers./*from www .j a v a 2s . co m*/ * * @param workerID * @param vars * @param resultVars * @param rvarFnames * @param out * @throws DMLRuntimeException * @throws IOException */ public static void exportResultVariables(long workerID, LocalVariableMap vars, ArrayList<String> resultVars, HashMap<String, String> rvarFnames, OutputCollector<Writable, Writable> out) throws DMLRuntimeException, IOException { //create key and value for reuse LongWritable okey = new LongWritable(workerID); Text ovalue = new Text(); //foreach result variables probe if export necessary for (String rvar : resultVars) { Data dat = vars.get(rvar); //export output variable to HDFS (see RunMRJobs) if (dat != null && dat.getDataType() == DataType.MATRIX) { MatrixObject mo = (MatrixObject) dat; if (mo.isDirty()) { if (ParForProgramBlock.ALLOW_REUSE_MR_PAR_WORKER && rvarFnames != null) { String fname = rvarFnames.get(rvar); if (fname != null) mo.setFileName(fname); //export result var (iff actually modified in parfor) mo.exportData(); //note: this is equivalent to doing it in close (currently not required because 1 Task=1Map tasks, hence only one map invocation) rvarFnames.put(rvar, mo.getFileName()); } else { //export result var (iff actually modified in parfor) mo.exportData(); //note: this is equivalent to doing it in close (currently not required because 1 Task=1Map tasks, hence only one map invocation) } //pass output vars (scalars by value, matrix by ref) to result //(only if actually exported, hence in check for dirty, otherwise potential problems in result merge) String datStr = ProgramConverter.serializeDataObject(rvar, mo); ovalue.set(datStr); out.collect(okey, ovalue); } } } }
From source file:dk.statsbiblioteket.doms.licensemodule.validation.LicenseValidator.java
public static ArrayList<ConfiguredDomLicenseGroupType> buildGroups(ArrayList<String> groups) { ArrayList<ConfiguredDomLicenseGroupType> filteredGroups = new ArrayList<ConfiguredDomLicenseGroupType>(); ArrayList<ConfiguredDomLicenseGroupType> configuredGroups = LicenseCache .getConfiguredDomLicenseGroupTypes(); HashMap<String, ConfiguredDomLicenseGroupType> configuredGroupsNamesMap = new HashMap<String, ConfiguredDomLicenseGroupType>(); for (ConfiguredDomLicenseGroupType current : configuredGroups) { configuredGroupsNamesMap.put(current.getKey(), current); }// w w w.j a v a 2s.c o m for (String currentGroup : groups) { if (configuredGroupsNamesMap.containsKey(currentGroup)) { filteredGroups.add(configuredGroupsNamesMap.get(currentGroup)); } else { log.error("Group not found in Group configuration:" + currentGroup); throw new IllegalArgumentException("Unknown group:" + currentGroup); } } return filteredGroups; }
From source file:com.jetyun.pgcd.rpc.reflect.ClassAnalyzer.java
/** * Analyze a class and create a ClassData object containing all of the * public methods (both static and non-static) in the class. * //ww w . ja va 2 s. c o m * @param clazz * class to be analyzed. * * @return a ClassData object containing all the public static and * non-static methods that can be invoked on the class. */ private static ClassData analyzeClass(Class clazz) { log.info("analyzing " + clazz.getName()); Method methods[] = clazz.getMethods(); ClassData cd = new ClassData(); cd.clazz = clazz; // Create temporary method map HashMap staticMethodMap = new HashMap(); HashMap methodMap = new HashMap(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method.getDeclaringClass() == Object.class) { continue; } int mod = methods[i].getModifiers(); if (!Modifier.isPublic(mod)) { continue; } Class param[] = method.getParameterTypes(); // don't count locally resolved args int argCount = 0; for (int n = 0; n < param.length; n++) { if (LocalArgController.isLocalArg(param[n])) { continue; } argCount++; } MethodKey mk = new MethodKey(method.getName(), argCount); ArrayList marr = (ArrayList) methodMap.get(mk); if (marr == null) { marr = new ArrayList(); methodMap.put(mk, marr); } marr.add(method); if (Modifier.isStatic(mod)) { marr = (ArrayList) staticMethodMap.get(mk); if (marr == null) { marr = new ArrayList(); staticMethodMap.put(mk, marr); } marr.add(method); } } cd.methodMap = new HashMap(); cd.staticMethodMap = new HashMap(); // Convert ArrayLists to arrays Iterator i = methodMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); MethodKey mk = (MethodKey) entry.getKey(); ArrayList marr = (ArrayList) entry.getValue(); if (marr.size() == 1) { cd.methodMap.put(mk, marr.get(0)); } else { cd.methodMap.put(mk, marr.toArray(new Method[0])); } } i = staticMethodMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); MethodKey mk = (MethodKey) entry.getKey(); ArrayList marr = (ArrayList) entry.getValue(); if (marr.size() == 1) { cd.staticMethodMap.put(mk, marr.get(0)); } else { cd.staticMethodMap.put(mk, marr.toArray(new Method[0])); } } return cd; }
From source file:fr.lissi.belilif.om2m.rest.WebServiceActions.java
/** * Do get.//w ww . j a va 2 s .c o m * * @param uri * the uri * @param headers * the headers * @return the string * @throws Exception * the exception */ public static String doGet(URI uri, HashMap<String, String> headers) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); String respString = null; try { /* * HttpClient provides URIBuilder utility class to simplify creation and modification of request URIs. * * URI uri = new URIBuilder() .setScheme("http") .setHost("hc.apache.org/") // .setPath("/search") // .setParameter("q", * "httpclient") // .setParameter("btnG", "Google Search") // .setParameter("aq", "f") // .setParameter("oq", "") .build(); */ HttpGet httpGet = new HttpGet(uri); for (String key : headers.keySet()) { httpGet.addHeader(key, headers.get(key)); } CloseableHttpResponse response1 = httpclient.execute(httpGet); // The underlying HTTP connection is still held by the response object // to allow the response content to be streamed directly from the network socket. // In order to ensure correct deallocation of system resources // the user MUST call CloseableHttpResponse#close() from a finally clause. // Please note that if response content is not fully consumed the underlying // connection cannot be safely re-used and will be shut down and discarded // by the connection manager. try { System.out.println(response1.getStatusLine()); HttpEntity entity = response1.getEntity(); // do something useful with the response body if (entity != null) { respString = EntityUtils.toString(entity); } // and ensure it is fully consumed EntityUtils.consume(entity); } finally { response1.close(); } } finally { httpclient.close(); } return respString; }
From source file:LineageSimulator.java
public static void writeVAFsToFile(String fileName, HashMap<Mutation.SNV, double[]> snvToVAFs, HashMap<Mutation.SNV, String> binaryProfiles, int numSamples) { String vafs = ""; vafs += "#chrom\tpos\tdesc"; if (binaryProfiles != null) { vafs += "\tprofile"; }//from w w w.ja v a 2 s. c o m vafs += "\tnormal"; for (int i = 1; i < numSamples; i++) { vafs += "\tsample" + i; } vafs += "\n"; DecimalFormat df = new DecimalFormat("#.####"); for (Mutation.SNV snv : snvToVAFs.keySet()) { String v = (snv.chr + 1) + "\t" + snv.position + "\t" + snv.name; if (binaryProfiles != null) { v += "\t" + binaryProfiles.get(snv); } for (int i = 0; i < numSamples; i++) { v += "\t" + df.format(snvToVAFs.get(snv)[i]); } v += "\n"; vafs += v; } writeOutputFile(fileName, vafs); }
From source file:com.clustercontrol.repository.util.FacilityTreeCache.java
private static HashMap<String, ArrayList<String>> getObjectRoleMap() { List<ObjectPrivilegeInfo> objectPrivilegeEntities = com.clustercontrol.accesscontrol.util.QueryUtil .getAllObjectPrivilegeByFilter(HinemosModuleConstant.PLATFORM_REPOSITORY, null, null, PrivilegeConstant.ObjectPrivilegeMode.READ.toString()); HashMap<String, ArrayList<String>> objectRoleMap = new HashMap<String, ArrayList<String>>(); for (ObjectPrivilegeInfo objectPrivilegeEntity : objectPrivilegeEntities) { String objectId = objectPrivilegeEntity.getId().getObjectId(); ArrayList<String> roleIdList = objectRoleMap.get(objectId); if (roleIdList == null) { roleIdList = new ArrayList<String>(); }//from ww w. j a v a 2 s .c om roleIdList.add(objectPrivilegeEntity.getId().getRoleId()); objectRoleMap.put(objectId, roleIdList); } return objectRoleMap; }
From source file:com.concursive.connect.web.portal.PortalUtils.java
/** * When a form is submitted with enctype="multipart/form-data", then the * parameters and values are placed into a parts HashMap which can now * be auto-populated// w ww.jav a 2s . com * * @param bean * @param parts */ public static void populateObject(Object bean, HashMap parts) { if (parts != null) { Iterator names = parts.keySet().iterator(); while (names.hasNext()) { String paramName = (String) names.next(); Object paramValues = parts.get(paramName); if (paramValues != null && paramValues instanceof String) { ObjectUtils.setParam(bean, paramName, paramValues, "_"); } } } }
From source file:com.act.lcms.db.analysis.IonDetectionAnalysis.java
public static Map<ScanData.KIND, List<LCMSWell>> readInputExperimentalSetup(DB db, File inputFile) throws IOException, SQLException, ClassNotFoundException { TSVParser parser = new TSVParser(); parser.parse(inputFile);/*from w w w . j a v a 2 s .c o m*/ Set<String> headerSet = new HashSet<>(parser.getHeader()); if (!headerSet.equals(ALL_HEADERS)) { throw new RuntimeException(String.format("Invalid header types! The allowed header types are: %s", StringUtils.join(ALL_HEADERS, ","))); } Map<ScanData.KIND, List<LCMSWell>> result = new HashMap<>(); HashMap<String, Plate> plateCache = new HashMap<>(); for (Map<String, String> row : parser.getResults()) { String wellType = row.get(HEADER_WELL_TYPE); String barcode = row.get(HEADER_PLATE_BARCODE); Integer rowCoordinate = Integer.parseInt(row.get(HEADER_WELL_ROW)); Integer columnCoordinate = Integer.parseInt(row.get(HEADER_WELL_COLUMN)); Plate plate = plateCache.get(barcode); if (plate == null) { plate = Plate.getPlateByBarcode(db, barcode); plateCache.put(barcode, plate); } LCMSWell well = LCMSWell.getInstance().getByPlateIdAndCoordinates(db, plate.getId(), rowCoordinate, columnCoordinate); if (well == null) { throw new RuntimeException(String.format("Well plate id %d, row %d and col %d does not exist", plate.getId(), rowCoordinate, columnCoordinate)); } if (wellType.equals("POS")) { List<LCMSWell> values = result.get(ScanData.KIND.POS_SAMPLE); if (values == null) { values = new ArrayList<>(); result.put(ScanData.KIND.POS_SAMPLE, values); } values.add(well); } else { List<LCMSWell> values = result.get(ScanData.KIND.NEG_CONTROL); if (values == null) { values = new ArrayList<>(); result.put(ScanData.KIND.NEG_CONTROL, values); } values.add(well); } } return result; }
From source file:com.ecyrd.jspwiki.ui.TemplateManager.java
/** * Adds a resource request to the current request context. * The content will be added at the resource-type marker * (see IncludeResourcesTag) in WikiJSPFilter. * <p>//from w w w.j ava 2s . c o m * The resources can be of different types. For RESOURCE_SCRIPT and RESOURCE_STYLESHEET * this is an URI path to the resource (a script file or an external stylesheet) * that needs to be included. For RESOURCE_INLINECSS * the resource should be something that can be added between <style></style> in the * header file (commonheader.jsp). For RESOURCE_JSFUNCTION it is the name of the Javascript * function that should be run at page load. * <p> * The IncludeResourceTag inserts code in the template files, which is then filled * by the WikiFilter after the request has been rendered but not yet sent to the recipient. * <p> * Note that ALL resource requests get rendered, so this method does not check if * the request already exists in the resources. Therefore, if you have a plugin which * makes a new resource request every time, you'll end up with multiple resource requests * rendered. It's thus a good idea to make this request only once during the page * life cycle. * * @param ctx The current wiki context * @param type What kind of a request should be added? * @param resource The resource to add. */ @SuppressWarnings("unchecked") public static void addResourceRequest(WikiContext ctx, String type, String resource) { HashMap<String, Vector<String>> resourcemap = (HashMap<String, Vector<String>>) ctx .getVariable(RESOURCE_INCLUDES); if (resourcemap == null) { resourcemap = new HashMap<String, Vector<String>>(); } Vector<String> resources = resourcemap.get(type); if (resources == null) { resources = new Vector<String>(); } String resourceString = null; if (type.equals(RESOURCE_SCRIPT)) { resourceString = "<script type='text/javascript' src='" + resource + "'></script>"; } else if (type.equals(RESOURCE_STYLESHEET)) { resourceString = "<link rel='stylesheet' type='text/css' href='" + resource + "' />"; } else if (type.equals(RESOURCE_INLINECSS)) { resourceString = "<style type='text/css'>\n" + resource + "\n</style>\n"; } else if (type.equals(RESOURCE_JSFUNCTION)) { resourceString = resource; } else if (type.equals(RESOURCE_HTTPHEADER)) { resourceString = resource; } if (resourceString != null) { resources.add(resourceString); } log.debug("Request to add a resource: " + resourceString); resourcemap.put(type, resources); ctx.setVariable(RESOURCE_INCLUDES, resourcemap); }
From source file:es.tena.foundation.util.POIUtil.java
private static void generate(Writer out, ResultSet rset, String encoding) throws Exception { SimpleDateFormat sdfecha = new SimpleDateFormat("dd/MM/yyyy"); SpreadSheetWriter sw = new SpreadSheetWriter(out); sw.beginSheet();/*from w w w.j a v a 2 s . co m*/ ResultSetMetaData rmd = rset.getMetaData(); HashMap<Integer, String> columnas = new HashMap<Integer, String>(); //creamos la cabecera del excel sw.insertRow(0); int numeroColumnas = rmd.getColumnCount(); for (int numeroColumna = 1; numeroColumna <= numeroColumnas; numeroColumna++) { String nombreColumna = rmd.getColumnName(numeroColumna).toUpperCase(); columnas.put(numeroColumna, rmd.getColumnTypeName(numeroColumna)); sw.createCell(numeroColumna - 1, nombreColumna); } sw.endRow(); //creamos los datos del excel int rowNum = 1; while (rset.next()) { sw.insertRow(rowNum); for (int columna = 1; columna <= numeroColumnas; columna++) { if (columnas.get(columna).equals("CHAR") || columnas.get(columna).equals("VARCHAR2")) { String valor = ""; valor = rset.getString(columna); valor = fixPOICellValue(valor, encoding); if (valor == null || valor.toLowerCase().equals("null")) { valor = ""; } sw.createCell(columna - 1, valor); } else if (columnas.get(columna).equals("DATE")) { Date fecha = new Date(); fecha = rset.getDate(columna); String valor = (fecha != null) ? sdfecha.format(fecha) : null; if (valor == null || valor.toLowerCase().equals("null")) { valor = ""; } sw.createCell(columna - 1, valor); } else if (columnas.get(columna).equals("NUMBER")) { String valor = ""; valor = rset.getString(columna); if (valor == null || valor.toLowerCase().equals("null")) { valor = ""; } sw.createCell(columna - 1, valor); } else { String valor = ""; valor = rset.getString(columna); valor = fixPOICellValue(valor, encoding); if (valor == null || valor.toLowerCase().equals("null")) { valor = ""; } sw.createCell(columna - 1, valor); } } sw.endRow(); rowNum++; } sw.endSheet(); }