List of usage examples for java.util TreeMap keySet
public Set<K> keySet()
From source file:org.apache.hadoop.hbase.TestSplit.java
private void assertScan(final HRegion r, final String column, final Text firstValue) throws IOException { Text[] cols = new Text[] { new Text(column) }; HInternalScannerInterface s = r.getScanner(cols, HConstants.EMPTY_START_ROW, System.currentTimeMillis(), null);/*from www . j a va 2 s . c om*/ try { HStoreKey curKey = new HStoreKey(); TreeMap<Text, byte[]> curVals = new TreeMap<Text, byte[]>(); boolean first = true; OUTER_LOOP: while (s.next(curKey, curVals)) { for (Text col : curVals.keySet()) { byte[] val = curVals.get(col); Text curval = new Text(val); if (first) { first = false; assertTrue(curval.compareTo(firstValue) == 0); } else { // Not asserting anything. Might as well break. break OUTER_LOOP; } } } } finally { s.close(); } }
From source file:org.apache.hadoop.hdfs.TestDFSUpgradeFromImage.java
private void verifyDir(DistributedFileSystem dfs, Path dir) throws IOException { FileStatus[] fileArr = dfs.listStatus(dir); TreeMap<Path, Boolean> fileMap = new TreeMap<Path, Boolean>(); for (FileStatus file : fileArr) { fileMap.put(file.getPath(), Boolean.valueOf(file.isDir())); }/* w w w . j av a 2 s.co m*/ for (Iterator<Path> it = fileMap.keySet().iterator(); it.hasNext();) { Path path = it.next(); boolean isDir = fileMap.get(path); String pathName = path.toUri().getPath(); overallChecksum.update(pathName.getBytes()); if (isDir) { verifyDir(dfs, path); } else { // this is not a directory. Checksum the file data. CRC32 fileCRC = new CRC32(); FSInputStream in = dfs.dfs.open(pathName); byte[] buf = new byte[4096]; int nRead = 0; while ((nRead = in.read(buf, 0, buf.length)) > 0) { fileCRC.update(buf, 0, nRead); } verifyChecksum(pathName, fileCRC.getValue()); } } }
From source file:org.apache.hadoop.raid.TestRaidHistogram.java
public void printBlockFixStatus(TreeMap<Long, BlockFixStatus> status) { for (Long window : status.keySet()) { LOG.info("Window: " + window); BlockFixStatus bfs = status.get(window); LOG.info("failedPaths: " + bfs.failedPaths); String values = ""; for (Long val : bfs.percentValues) { values += "/" + val; }// w ww. j a v a 2 s . com LOG.info("percentValues: " + values); } }
From source file:com.masse.mvn.plugin.BuildJsonFromPropertiesMojo.java
private StringBuffer PrintJsonTree(TreeMap<String, PropertiesToJson> tm, int indent, boolean hasNext) { StringBuffer sb = new StringBuffer(); sb.append("{"); Iterator<String> itr = tm.keySet().iterator(); while (itr.hasNext()) { PropertiesToJson ptj = tm.get(itr.next()); if (ptj.getValue() != null) { sb.append("\"" + ptj.getJsonKey() + "\"" + ":" + "\"" + escapingQuote(ptj.getValue()) + "\""); if (itr.hasNext()) sb.append(","); } else {/* w ww. jav a 2s . c om*/ sb.append("\"" + ptj.getJsonKey() + "\"" + ":"); sb.append(PrintJsonTree(ptj.getChildren(), indent + 1, itr.hasNext())); } } if (hasNext) { sb.append("},"); } else { sb.append("}"); } return sb; }
From source file:com.sfs.beans.PrivilegesBean.java
/** * Generates a JDOM Document form the values set in this PrivilegesBean. * * @return JDOM element representing the privilege values *//*from ww w.j a v a2 s.co m*/ public final Document getXmlDocument() { Element rootElement = new Element("privileges"); TreeMap<String, RoleBean> roleMap = this.getRoles(); for (String roleName : roleMap.keySet()) { RoleBean role = (RoleBean) roleMap.get(roleName); if (role != null) { Element userclass = new Element("userClass"); Element name = new Element("name").setText(role.getName()); Element description = new Element("description").setText(role.getDescription()); Element emailName = new Element("emailName").setText(role.getEmailName()); Element emailAddress = new Element("emailAddress").setText(role.getEmailAddress()); Element actions = new Element("actions"); userclass.addContent(name); userclass.addContent(description); userclass.addContent(emailName); userclass.addContent(emailAddress); TreeMap<String, PrivilegeBean> privilegeRoles = role.getPrivileges(); for (String privilegeName : privilegeRoles.keySet()) { PrivilegeBean privilege = (PrivilegeBean) privilegeRoles.get(privilegeName); if (privilege != null) { Element action = new Element("action").setText(privilege.getName()); ArrayList<Attribute> attributes = new ArrayList<Attribute>(); String strCreate = "false"; String strModify = "false"; String strDelete = "false"; if (privilege.getCreate()) { strCreate = "true"; } if (privilege.getModify()) { strModify = "true"; } if (privilege.getDelete()) { strDelete = "true"; } Attribute create = new Attribute("create", strCreate); Attribute modify = new Attribute("modify", strModify); Attribute delete = new Attribute("delete", strDelete); attributes.add(create); attributes.add(modify); attributes.add(delete); action.setAttributes(attributes); actions.addContent(action); } } userclass.addContent(actions); rootElement.addContent(userclass); } } return new Document(rootElement); }
From source file:org.openmrs.module.rheapocadapter.handler.ConnectionHandler.java
public String createUrl(String methodType, TreeMap<String, String> parameter) { // URL encode all parameters for (String key : parameter.keySet()) { try {/* www. ja v a 2 s . co m*/ parameter.put(key, URLEncoder.encode(parameter.get(key), "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); log.error("Unsupported encoding used during parameter URL encoding", e); } } String url = hostname; if ((hostname == null) || (hostname == "")) { return null; } if (methodType.equalsIgnoreCase("GetClinicalData")) { setImplementationId(getImplementationId().toLowerCase()); String fosaid = getImplementationId().substring(getImplementationId().indexOf("rwanda") + 6); String createdSince = parameter.get("createdInSince"); if (createdSince != null && createdSince != "" && createdSince != "null") { return hostname + getGloabalPropertyByName(RHEAConstants.PATIENT_SINGLE_PATIENT_URL_NAME) + "/" + parameter.get("patientId") + "/encounters/?" + "encounter_start_date=" + createdSince + "&ELID=" + fosaid; } else { return hostname + getGloabalPropertyByName(RHEAConstants.PATIENT_SINGLE_PATIENT_URL_NAME) + "/" + parameter.get("patientId") + "/encounters/?" + "&ELID=" + fosaid; } } else if (methodType.equalsIgnoreCase("UpdatePatientData")) { return hostname + getGloabalPropertyByName(RHEAConstants.PATIENT_SINGLE_PATIENT_URL_NAME) + "/" + parameter.get("patientId"); } else if (methodType.equalsIgnoreCase("RegisterNew")) { return hostname + getGloabalPropertyByName(RHEAConstants.PATIENT_MULTIPLE_PATIENTS_URL_NAME) + "/"; } else if (methodType.equalsIgnoreCase("GetClients")) { String parameters = ""; for (String param : parameter.keySet()) { if (parameters != "") parameters += "&"; if ((param == "") || (param.equalsIgnoreCase("")) || (param.equalsIgnoreCase(null))) continue; parameters += param + "=" + parameter.get(param); } if (parameters != "" && parameters != null) { url = hostname + getGloabalPropertyByName(RHEAConstants.PATIENT_MULTIPLE_PATIENTS_URL_NAME) + "/?" + parameters; } else { return null; } return url; } else if (methodType.equalsIgnoreCase("GetClient")) { return hostname + getGloabalPropertyByName(RHEAConstants.PATIENT_SINGLE_PATIENT_URL_NAME) + "/" + parameter.get("patientId"); } else if (methodType.equalsIgnoreCase("SavePatientEncounter")) { return hostname + getGloabalPropertyByName(RHEAConstants.PATIENT_SINGLE_PATIENT_URL_NAME) + "/" + parameter.get("patientId") + "/encounters"; } return null; }
From source file:gsn.wrappers.general.CSVWrapperTest.java
@Test public void testFieldConverting() throws IOException { String fields = "TIMED, air_temp , TIMED , AiR_TeMp2"; String formats = "Timestamp(d.M.y ) , Numeric , timestamp(k:m) , numeric "; String badFormat = "Timestamp(d.M.y k:m) , numeric , numeric, numeric,numeric,dollluble "; String badFormat2 = "Timestamp(d.Mjo0o.y k:m) , numeric, numeric, numeric"; CSVHandler wrapper = new CSVHandler(); assertEquals(false, wrapper.initialize("test.csv.csv", fields, badFormat, ',', '\"', 0, "NaN,-1234,4321")); assertEquals(false, wrapper.initialize("test.csv.csv", fields, badFormat, ',', '\"', 0, "NaN,-1234,4321")); assertEquals(false, wrapper.initialize("test.csv.csv", fields, badFormat2, ',', '\"', 0, "NaN,-1234,4321")); assertEquals(true, wrapper.initialize("test.csv.csv", fields, formats, ',', '\"', 0, "NaN,-1234,4321")); FileUtils.writeStringToFile(new File(wrapper.getCheckPointFile()), "", "UTF-8"); String[] formatsParsed = wrapper.getFormats(); String[] fieldsParsed = wrapper.getFields(); assertEquals(true, compare(fieldsParsed, new String[] { "timed", "air_temp", "timed", "air_temp2" })); assertEquals(true, compare(formatsParsed, new String[] { "Timestamp(d.M.y )", "Numeric", "timestamp(k:m)", "numeric" })); TreeMap<String, Serializable> se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] {}, wrapper.getSeparator()); assertEquals(wrapper.getFields().length - 1, se.keySet().size());//timestamp is douplicated. assertEquals(null, se.get("timed")); se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] { "", "", "", "-1234", "4321", "NaN" }, wrapper.getSeparator()); assertEquals(null, se.get("timed")); se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] { "", "", "", "-1234", "4321", "NaN" }, wrapper.getSeparator()); assertEquals(null, se.get("timed")); se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] { "01.01.2009", "1234", "", "-4321", "ignore-me", "NaN" }, wrapper.getSeparator()); long parsedTimestamp = (Long) se.get("timed"); assertEquals(true, parsedTimestamp > 0); assertEquals(1234.0, se.get("air_temp")); assertEquals(-4321.0, se.get("air_temp2")); se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] { "01.01.2009", "-1234", "10:10", "-4321", "ignore-me", "NaN" }, wrapper.getSeparator());/*from www. j a va 2 s. co m*/ assertEquals(true, ((Long) se.get("timed")) > parsedTimestamp); assertNull(se.get("air_temp")); }
From source file:ubic.gemma.persistence.service.association.coexpression.CoexpressionServiceImpl.java
private Map<Long, List<Double>> computeRelativeRanks(TreeMap<Integer, Map<Long, Integer>> forRanks) { Map<Long, List<Double>> relRanks = new HashMap<>(); for (Integer support : forRanks.keySet()) { // low ranks = low node degree = good. Map<Long, Double> rt = Rank.rankTransform(forRanks.get(support)); double max = DescriptiveWithMissing.max(new DoubleArrayList( ArrayUtils.toPrimitive(new ArrayList<>(rt.values()).toArray(new Double[] {})))); for (Long g : rt.keySet()) { double relRank = rt.get(g) / max; if (!relRanks.containsKey(g)) { relRanks.put(g, new ArrayList<Double>()); }/*from w w w . ja va 2 s .com*/ // the ranks are in order. relRanks.get(g).add(relRank); } } return relRanks; }
From source file:com.alkacon.opencms.counter.CmsCounterDialog.java
/** * This function compares the list from the dialog with the list from the database and * update the list from the database with the values from the dialog.<p> * //from ww w .ja va2 s.c o m * @param counterList the list from the dialog * * @throws Exception if an Exception occurred. */ private void updateCounterValues(SortedMap counterList) throws Exception { if (m_manager == null) { m_manager = getCounterManager(); } // get the counters from the database TreeMap map = m_manager.getCounters(); Iterator iteratork = map.keySet().iterator(); Iterator iterator = map.values().iterator(); // for each entry check if its changed or deleted int o_value; int new_value; String o_key; while (iterator.hasNext() && iteratork.hasNext()) { o_value = getIntValue(iterator.next()); o_key = (String) iteratork.next(); if (counterList.containsKey(o_key)) { // the value exits new_value = getIntValue(counterList.get(o_key)); if (o_value != new_value) { if ((o_value < new_value) || (o_value > new_value && m_overwrite)) { m_manager.setCounter(o_key, new_value); } counterList.remove(o_key); } else { counterList.remove(o_key); } } else { // the value is deleted m_manager.deleteCounter(o_key); } } // now the new values is adding to the database if (!counterList.isEmpty()) { iteratork = counterList.keySet().iterator(); iterator = counterList.values().iterator(); while (iterator.hasNext() && iteratork.hasNext()) { o_value = getIntValue(iterator.next()); o_key = (String) iteratork.next(); m_manager.setCounter(o_key, o_value); } } }
From source file:org.apache.hadoop.dfs.TestDFSUpgradeFromImage.java
private void verifyDir(DFSClient client, String dir) throws IOException { DFSFileInfo[] fileArr = client.listPaths(dir); TreeMap<String, Boolean> fileMap = new TreeMap<String, Boolean>(); for (DFSFileInfo file : fileArr) { String path = file.getPath().toString(); fileMap.put(path, Boolean.valueOf(file.isDir())); }//from w ww.j av a 2s.co m for (Iterator<String> it = fileMap.keySet().iterator(); it.hasNext();) { String path = it.next(); boolean isDir = fileMap.get(path); overallChecksum.update(path.getBytes()); if (isDir) { verifyDir(client, path); } else { // this is not a directory. Checksum the file data. CRC32 fileCRC = new CRC32(); FSInputStream in = client.open(path); byte[] buf = new byte[4096]; int nRead = 0; while ((nRead = in.read(buf, 0, buf.length)) > 0) { fileCRC.update(buf, 0, nRead); } verifyChecksum(path, fileCRC.getValue()); } } }