List of usage examples for java.util HashMap size
int size
To view the source code for java.util HashMap size.
Click Source Link
From source file:Main.java
/** * Method that merges 2 data structures into 1 * /* ww w.jav a 2 s. c o m*/ * @param featureSet: * the structure containing all features * @param featureSet2: * the structure containing Pairwise Correlation features * @return the concatenated data structure */ public static HashMap<Integer, ArrayList<HashMap<String, Double>>> mergeStructures( HashMap<Integer, ArrayList<HashMap<String, Double>>> featureSet, ArrayList<ArrayList<HashMap<String, Double>>> featureSet2) { HashMap<Integer, ArrayList<HashMap<String, Double>>> featureSet_final = new HashMap<Integer, ArrayList<HashMap<String, Double>>>(); for (int i = 0; i < featureSet.size(); i++) { ArrayList<HashMap<String, Double>> featuresPerChann = featureSet.get(i); ArrayList<HashMap<String, Double>> featuresPerChann2 = featureSet2.get(i); if (featuresPerChann2 == null) continue; ArrayList<HashMap<String, Double>> featuresPerChann_final = new ArrayList<HashMap<String, Double>>(); for (int ii = 0; ii < featuresPerChann.size(); ii++) { HashMap<String, Double> h1 = new HashMap<String, Double>(); HashMap<String, Double> h2 = new HashMap<String, Double>(); // System.out.println("s:: "+String.format("%03d", ii)); h1 = featuresPerChann.get(ii); for (int j = 0; j < featuresPerChann2.size(); j++) { h2 = featuresPerChann2.get(j); // System.out.println("h2:"+h2); String s = h2.keySet().toString(); if (s.contains("s" + String.format("%04d", ii))) { // System.out.println("sss"+s.substring(1,14)); String new_s = s.substring(1, 17); if (h2.get(new_s) != null) { double v = h2.get(new_s); HashMap<String, Double> h = new HashMap<String, Double>(); h.put(new_s.substring(0, 11), v); h1.putAll(h); } } } featuresPerChann_final.add(h1); } featureSet_final.put(i, featuresPerChann_final); } return featureSet_final; }
From source file:Main.java
public static final String postData(String url, HashMap<String, String> params) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); String outputString = null;/*w w w . j a v a 2 s. c om*/ try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(params.size()); Iterator it = params.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); nameValuePairs.add(new BasicNameValuePair((String) pair.getKey(), (String) pair.getValue())); System.out.println(pair.getKey() + " = " + pair.getValue()); it.remove(); // avoids a ConcurrentModificationException } httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpURLConnection.HTTP_OK) { byte[] result = EntityUtils.toByteArray(response.getEntity()); outputString = new String(result, "UTF-8"); } } catch (ClientProtocolException e) { Log.i(CLASS_NAME, "Client protocolException happened: " + e.getMessage()); } catch (IOException e) { Log.i(CLASS_NAME, "Client IOException happened: " + e.getMessage()); } catch (NetworkOnMainThreadException e) { Log.i(CLASS_NAME, "Client NetworkOnMainThreadException happened: " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { Log.i(CLASS_NAME, "Unknown exeception: " + e.getMessage()); } return outputString; }
From source file:com.wso2telco.gsma.authenticators.util.USSDOutboundMessage.java
public static String prepare(MessageType messageType, HashMap<String, String> map, String operator) { MobileConnectConfig.OperatorSpecificMessage operatorSpecificMessage = null; String template = ""; Map<String, String> data = new HashMap<String, String>(); // add default map values here // data.put("key", "value"); if (map != null && map.size() > 0) { for (Map.Entry<String, String> entry : map.entrySet()) { data.put(entry.getKey(), entry.getValue()); }/*from www . j a va 2 s . c om*/ } // Load operator specific message from hash map if (operator != null) { operatorSpecificMessage = operatorSpecificMessageMap.get(operator); data.put("operator", operator); } if (operatorSpecificMessage != null) { if (messageType == MessageType.LOGIN) { template = operatorSpecificMessage.getLoginMessage(); } if (messageType == MessageType.REGISTRATION) { template = operatorSpecificMessage.getRegistrationMessage(); } } else { if (messageType == MessageType.LOGIN) { template = ussdConfig.getUssdLoginMessage(); } if (messageType == MessageType.REGISTRATION) { template = ussdConfig.getUssdRegistrationMessage(); } } return StrSubstitutor.replace(template, data); }
From source file:br.edu.ufcg.supervisor.engine.Simulation.java
public static void executeModel(JSONObject r, Automaton model, HashMap<String, Float> map1, HashMap<Integer, Float> map2, String currentState, String recommendation, String logString) throws Exception { ArrayList<String> names = LoadedModel.getNomesVariaveisMonitoradas(); ArrayList<String> arrayMensagens = new ArrayList<String>(); for (int i = 0; i < map1.size(); i++) { currentState = currentState + "- " + names.get(i) + ": " + map1.get(names.get(i)) + ".<br>"; }// w w w.j a va 2 s.c om logString = logString + currentState + " - "; r.put("cur", currentState); State estado = model.buscaEstadoCorrespondente(map2); if (!(estado.getClassificacao() == State.INT_CL_ACEITACAO)) { Search alg = new Search(model); alg.execute(estado); for (State estadoAceito : model.getArrayEstadosAceitos()) { LinkedList<State> caminho = alg.getPath(estadoAceito); if (caminho != null) { for (int j = 0; j < caminho.size() - 1; j++) recommendation += "." + model.getMensagemDasTransicoesEntreDoisEstadosQuaisquer( caminho.get(j), caminho.get(j + 1));//elthon arrayMensagens.add(recommendation); } } recommendation = getShortestPath(arrayMensagens); recommendation = eliminateReplicatedRecommendations(recommendation); if (recommendation.equals(".")) recommendation = "Some variable has not been measured!"; logString = logString + recommendation + "\n"; } else { recommendation = "Keep going!"; logString = logString + "(" + recommendation + ")\n"; } r.put("rec", recommendation); }
From source file:com.chrischurchwell.jukeit.material.blocks.RecordPlayer.java
public static int getRange(Location location, RPNeedle needle) { int range = getRange(); HashMap<BlockFace, Speaker> blocks = getConnectedBlocks(location); if (blocks.size() == 1) { range = range + 20;/*from ww w.j av a2 s. c o m*/ } else if (blocks.size() > 1) { range = range + 40; } Debug.debug("Needle modifier is: ", needle.rangeModifier()); range = range + ((int) Math.floor((double) range * needle.rangeModifier())); return range; }
From source file:edu.utexas.cs.tactex.utils.BrokerUtils.java
public static int extractPredictionRecordLength( HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> result) { Collection<HashMap<TariffSpecification, ShiftedEnergyData>> listOfHashTrf2Engy = result.values(); if (listOfHashTrf2Engy == null || listOfHashTrf2Engy.size() == 0) { log.warn("empty list of mappings of tariff=>energy"); return 0; }//w ww . j a v a2s. c om HashMap<TariffSpecification, ShiftedEnergyData> someHashTrf2Engy = listOfHashTrf2Engy.iterator().next(); if (someHashTrf2Engy == null || someHashTrf2Engy.size() == 0) { log.warn("empty mapping of tariff=>energy"); return 0; } return someHashTrf2Engy.values().iterator().next().getShiftedEnergy().getDimension(); }
From source file:Main.java
/** * Puts the node attributes (if it has any) into HashMap<String,String> * /*from ww w. j a v a2 s.c o m*/ * @param node : XML node to look for its attributes * @return Hashmap<String,String> of the node attributes */ public static HashMap<String, String> getAttributes(Node node) { String attrName = null; String attrValue = null; HashMap<String, String> attributesMap = new HashMap<String, String>(); NamedNodeMap attributes = node.getAttributes(); for (int attrIndex = 0; attributes != null && attrIndex < attributes.getLength(); attrIndex++) { attrName = attributes.item(attrIndex).getNodeName(); attrValue = attributes.item(attrIndex).getNodeValue(); attributesMap.put(attrName, attrValue); } return attributesMap.size() == 0 ? null : attributesMap; }
From source file:de.adesso.referencer.search.helper.ElasticConfig.java
public static String buildSearchQuery(HashMap<String, String> fieldvalue) { String result = null;/*ww w .j ava 2 s .c o m*/ if (fieldvalue == null) return null; if (fieldvalue.size() <= 0) return null; result = "{\"query\": { \"bool\": {\"must\": ["; String matchString = null; for (String s : fieldvalue.keySet()) { matchString = buildMatchString(s, fieldvalue.get(s)); if (matchString != null) result += "\n" + matchString + ","; } result = result.substring(0, result.length() - 1) + "\n"; result += "]}}}"; return result; }
From source file:Main.java
/** * Puts the node attributes (if it has any) into HashMap<String,String> Retrieves only those * attributes that are in attr ArrayList Ignores other attributes values that are in node * //ww w . ja va2 s .co m * @param node : XML node to look for its attributes * @param attrNames : attributes to fetch from node * @return Hashmap<String,String> of the node attributes */ public static HashMap<String, String> getAttributesByName(Node node, ArrayList<String> attrNames) { String attrName = null; String attrValue = null; HashMap<String, String> attributesMap = new HashMap<String, String>(); NamedNodeMap attributes = node.getAttributes(); for (int attrIndex = 0; attrIndex < attributes.getLength(); attrIndex++) { attrName = attributes.item(attrIndex).getNodeName(); attrValue = attributes.item(attrIndex).getNodeValue(); if (attrNames.contains(attrName)) { attributesMap.put(attrName, attrValue); } } return attributesMap.size() == 0 ? null : attributesMap; }
From source file:com.savy3.nonequijoin.MapOutputSampler.java
/** * Write a partition file for the given job, using the Sampler provided. * Queries the sampler for a sample keyset, sorts by the output key * comparator, selects the keys for each rank, and writes to the destination * returned from {@link TotalOrderPartitioner#getPartitionFile}. *///from w w w. j ava2 s . c o m @SuppressWarnings("unchecked") // getInputFormat, getOutputKeyComparator public static <K, V> void writePartitionFile(Job job, Sampler<K, V> sampler) throws IOException, ClassNotFoundException, InterruptedException { Configuration conf = job.getConfiguration(); final InputFormat inf = ReflectionUtils.newInstance(job.getInputFormatClass(), conf); int numPartitions = job.getNumReduceTasks(); HashMap<K, V> samples = (HashMap<K, V>) sampler.getSample(inf, job); LOG.info("Using " + samples.size() + " samples"); // write the input samples in to file <partitionfile>/mapIn Path dstOut = new Path(TotalOrderPartitioner.getPartitionFile(conf)); Path dst = new Path(dstOut, "mapIn"); FileSystem fs = dst.getFileSystem(conf); SequenceFile.Writer sampleWriter = null; for (Map.Entry<K, V> sample : samples.entrySet()) { sampleWriter = SequenceFile.createWriter(fs, conf, dst, sample.getKey().getClass(), sample.getValue().getClass()); break; } for (Map.Entry<K, V> sample : samples.entrySet()) { sampleWriter.append(sample.getKey(), sample.getValue()); } sampleWriter.close(); LOG.info("Sample Input File location " + dst.toString()); // run map reduce on the samples input runMap(job, dst); }