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:ExcelFx.FXMLDocumentController.java
private void printXls(String patch, HashMap<String, HashSet<CountedMap>> result) throws IOException { System.out.println("printXls was started"); System.out.println("patch name:" + patch); System.out.println("result size: " + result.size()); try (Workbook wb = new XSSFWorkbook()) { Integer yStart = null;/* w w w .j a va 2s. c o m*/ Integer yEnd = null; for (Map.Entry<String, HashSet<CountedMap>> entry : result.entrySet()) { Sheet sheet = wb.createSheet(entry.getKey()); Map<String, CellStyle> styles = createStyles(wb); Row row; Cell cell; row = sheet.createRow(0); cell = row.createCell(0); cell.setCellValue("???"); cell.setCellStyle(styles.get("header")); for (int i = 0; i < list.get(0).size(); i++) { if (list.get(0).get(i).equals(initaldata.getYStart())) { yStart = i; } if (list.get(0).get(i).equals(initaldata.getYEnd())) { yEnd = i; } } for (int i = yStart; i <= yEnd; i++) { cell = row.createCell((i - yStart) + 1); cell.setCellValue(list.get(0).get(i)); cell.setCellStyle(styles.get("header")); } int i = 1; Iterator<CountedMap> itr = entry.getValue().iterator(); while (itr.hasNext()) { CountedMap next = itr.next(); row = sheet.createRow(i); cell = row.createCell(0); cell.setCellValue(next.getName().substring(0, 1).toUpperCase() + next.getName().substring(1)); cell.setCellStyle(styles.get("total")); for (int j = 0; j < next.getNeededStaff().size(); j++) { cell = row.createCell(j + 1);// //System.out.println(next.getNeededStaff().get(j)); cell.setCellValue(Double.parseDouble(next.getNeededStaff().get(j))); cell.setCellStyle(styles.get("total")); } Iterator<String> itrWay = next.getEdWay().iterator(); while (itrWay.hasNext()) { i++; String next1 = itrWay.next(); row = sheet.createRow(i); cell = row.createCell(0); cell.setCellValue(next1.substring(0, 1).toUpperCase() + next1.substring(1)); cell.setCellStyle(styles.get("normal")); for (int j = 0; j < next.getNeededStaff().size(); j++) { cell = row.createCell(j + 1);// //System.out.println(next.getNeededStaff().get(j)); cell.setCellValue( Double.parseDouble(next.getNeededStaff().get(j)) / next.getEdWay().size()); cell.setCellStyle(styles.get("normal")); } } i++; } } wb.write(new FileOutputStream(patch + ".xlsx")); System.out.println("File saved"); } System.out.println("printXlsx finished"); }
From source file:FormatStorage1.IRecord.java
private void setFieldTypes(HashMap<Integer, IFType> fieldtypes) { this.fieldTypes = fieldtypes; this.fieldnum = fieldtypes.size(); this.bitSet = new FixedBitSet(fieldnum); this.fieldValues = new ArrayList<IFValue>(fieldnum); for (int i = 0; i < fieldnum; i++) { this.fieldValues.add(null); }//from w ww .j a va2 s . com this.bytes = new DataOutputBuffer(); idx2bitsetpos = new HashMap<Integer, Integer>(fieldnum); idxs = new int[fieldnum]; int i = 0, idx = 0; while (i < fieldnum) { if (fieldtypes.containsKey(idx++)) { idxs[i] = idx - 1; idx2bitsetpos.put(idx - 1, i++); if (fieldtypes.get(idx - 1).type == ConstVar.FieldType_String) { this.fixlenmode = false; } } } }
From source file:com.cesnet.pki.DigicertConnector.java
/** * load generated data of organization ids and validation dates * //from ww w . j av a 2s. c o m * @return generated data if exists. Else returns new empty HashMap */ private HashMap<Integer, CertificateData> loadGeneratedData() { HashMap<Integer, CertificateData> data = new HashMap<>(); try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("data.properties"))) { Object readMap = ois.readObject(); if (readMap != null && readMap instanceof HashMap) { data.putAll((Map<? extends Integer, ? extends CertificateData>) readMap); } System.out.println(ANSI_GREEN + "Great :) Data already exist. The size is " + data.size()); } catch (IOException | ClassNotFoundException e) { // data do not exist yet System.out.println(ANSI_RED + "Data do not exist yet..."); } return data; }
From source file:com.thoughtworks.go.domain.materials.svn.SvnCommandTest.java
@Test public void shouldGetSvnInfoForMultipleMaterialsAndReturnMapOfUrlToUUID() { final SvnMaterial svnMaterial1 = mock(SvnMaterial.class); when(svnMaterial1.getUrl()).thenReturn("http://localhost/svn/project1"); final SvnMaterial svnMaterial2 = mock(SvnMaterial.class); when(svnMaterial2.getUrl()).thenReturn("http://foo.bar"); final HashSet<SvnMaterial> svnMaterials = new HashSet<>(); svnMaterials.add(svnMaterial1);// w w w . ja v a 2s.c om svnMaterials.add(svnMaterial2); final SvnCommand spy = spy(subversion); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { final ConsoleResult consoleResult = mock(ConsoleResult.class); when(consoleResult.outputAsString()).thenReturn(svnInfoOutput); final CommandLine commandLine = (CommandLine) invocation.getArguments()[0]; if (commandLine.toString().contains("http://localhost/svn/project1")) { return consoleResult; } else { throw new RuntimeException("Some thing crapped out"); } } }).when(spy).executeCommand(any(CommandLine.class)); HashMap<String, String> urlToRemoteUUIDMap = null; try { urlToRemoteUUIDMap = spy.createUrlToRemoteUUIDMap(svnMaterials); } catch (Exception e) { fail("Should not have failed although exception was thrown " + e); } assertThat(urlToRemoteUUIDMap.size(), is(1)); assertThat(urlToRemoteUUIDMap.get("http://localhost/svn/project1"), is("b51fe673-20c0-4205-a07b-5deb54bb09f3")); verify(spy, times(2)).executeCommand(any(CommandLine.class)); }
From source file:com.proctorcam.proctorserv.ProctorservApi.java
/** * Takes the passed HashMap and spits out an array that acts * as a token template //from w ww. j a v a 2s. c o m */ protected String[] createTokenArray(HashMap<String, Object> options) { String[] token = new String[options.size()]; int i = 0; for (String key : options.keySet()) { String value = String.valueOf(options.get(key)); token[i] = key + "%3D" + value; i++; } return token; }
From source file:com.akop.bach.parser.PsnParser.java
protected ArrayList<HashMap<String, String>> parsePairsInSimpleXml(String document, String nodeName) { Pattern outerNode = Pattern.compile("<" + nodeName + "(?:\\s+[^>]*)?>(.*?)</" + nodeName + ">", Pattern.DOTALL);//from www. j a va 2s . c o m Pattern innerNode = Pattern.compile("<(\\w+)[^>]*>([^<]*)</\\1>"); ArrayList<HashMap<String, String>> kvpList = new ArrayList<HashMap<String, String>>(); Matcher nodeMatcher = outerNode.matcher(document); while (nodeMatcher.find()) { String content = nodeMatcher.group(1); Matcher m = innerNode.matcher(content); HashMap<String, String> items = new HashMap<String, String>(); while (m.find()) { String innerNodeName = m.group(1); if (items.containsKey(innerNodeName)) continue; items.put(innerNodeName, m.group(2)); } if (items.size() > 0) kvpList.add(items); } return kvpList; }
From source file:de.unioninvestment.portal.explorer.view.vfs.VFSMainView.java
public void scanDirectory(FileSystemManager fsManager, FileSystemOptions opts, String ftpconn) throws IOException { try {/*from ww w .ja v a 2 s . c o m*/ FileObject fileObject = fsManager.resolveFile(ftpconn, opts); FileObject[] files = fileObject.findFiles(new FileTypeSelector(FileType.FOLDER)); HashMap<String, String> parentMap = new HashMap<String, String>(); for (FileObject fo : files) { String objectName = fo.getName().toString(); tree.addItem(objectName); tree.setItemIcon(objectName, FOLDER); if (fo.getParent() != null) { String parentName = fo.getParent().getName().toString(); parentMap.put(objectName, parentName); } else tree.setItemCaption(objectName, "/"); } // set parents logger.log(Level.INFO, "parentMap " + parentMap.size()); if (parentMap.size() > 0) { Iterator<Map.Entry<String, String>> it = parentMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pairs = it.next(); tree.setParent(pairs.getKey(), pairs.getValue()); String caption = pairs.getKey().toString().substring(pairs.getValue().toString().length()); tree.setItemCaption(pairs.getKey(), removeSlash(caption)); it.remove(); } } } catch (FileSystemException e) { e.printStackTrace(); } }
From source file:hms.hwestra.interactionrebuttal2.InteractionRebuttal2.java
private void mergeMetaFiles(String[] files, String[] fileNames, String out, String annot, double threshold) throws IOException { TextFile tf1 = new TextFile(annot, TextFile.R); Map<String, String> ilmnToArr = tf1.readAsHashMap(0, 1); tf1.close();//from w w w. ja va 2s.c o m ArrayList<HashMap<String, Double>> eqtls = new ArrayList<HashMap<String, Double>>(); HashSet<String> uniqueEQTLs = new HashSet<String>(); for (String file : files) { HashMap<String, Double> eqtl = loadInteractionMetaTableZScoreBlaat(file); Set<String> keyset = eqtl.keySet(); for (String key : keyset) { uniqueEQTLs.add(key); } System.out.println(eqtl.size() + " loaded from " + file); eqtls.add(eqtl); } System.out.println(uniqueEQTLs.size() + " unique eQTLs"); TextFile outfile = new TextFile(out, TextFile.W); String header = "SNP\tProbe\tGene"; for (int i = 0; i < files.length; i++) { header += "\tZ-" + fileNames[i] + "\tP-" + fileNames[i]; } outfile.writeln(header); int[] nrEQTLsBelowThreshold = new int[files.length]; int[] nrTotalEQTLs = new int[files.length]; for (String eqtl : uniqueEQTLs) { String[] eqtlelems = eqtl.split("-"); String outln = eqtlelems[0] + "\t" + eqtlelems[1] + "\t" + ilmnToArr.get(eqtlelems[1]); for (int i = 0; i < files.length; i++) { HashMap<String, Double> map = eqtls.get(i); Double z = map.get(eqtl); if (z != null && !Double.isNaN(z)) { double p = ZScores.zToP(z); if (p < threshold) { nrEQTLsBelowThreshold[i]++; } nrTotalEQTLs[i]++; outln += "\t" + z + "\t" + p; } else { outln += "\tNaN\tNaN"; } } outfile.writeln(outln); } outfile.close(); System.out.println("pvals below threshold:"); for (int i = 0; i < files.length; i++) { System.out.println(fileNames[i] + "\t" + nrEQTLsBelowThreshold[i] + "\t" + nrTotalEQTLs[i]); } }
From source file:eu.stratosphere.pact.runtime.task.CombineTaskExternalITCase.java
@Test public void testMultiLevelMergeCombineTask() { int keyCnt = 32768; int valCnt = 8; super.initEnvironment(3 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1); super.addOutput(this.outList); CombineTask<PactRecord> testTask = new CombineTask<PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.COMBININGSORT); super.getTaskConfig().setMemorySize(3 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(2); final int[] keyPos = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos, keyClasses); super.registerTask(testTask, MockCombiningReduceStub.class); try {//w ww . ja v a2 s. c om testTask.invoke(); } catch (Exception e) { LOG.debug(e); Assert.fail("Invoke method caused exception."); } int expSum = 0; for (int i = 1; i < valCnt; i++) { expSum += i; } // wee need to do the final aggregation manually in the test, because the // combiner is not guaranteed to do that HashMap<PactInteger, PactInteger> aggMap = new HashMap<PactInteger, PactInteger>(); for (PactRecord record : this.outList) { PactInteger key = new PactInteger(); PactInteger value = new PactInteger(); record.getField(0, key); record.getField(1, value); PactInteger prevVal = aggMap.get(key); if (prevVal != null) { aggMap.put(key, new PactInteger(prevVal.getValue() + value.getValue())); } else { aggMap.put(key, value); } } Assert.assertTrue("Resultset size was " + aggMap.size() + ". Expected was " + keyCnt, aggMap.size() == keyCnt); for (PactInteger integer : aggMap.values()) { Assert.assertTrue("Incorrect result", integer.getValue() == expSum); } this.outList.clear(); }