List of usage examples for java.util SortedMap keySet
Set<K> keySet();
From source file:eu.stratosphere.pact.runtime.hash.HashFunctionCollisionBenchmark.java
private void printStatistics() { for (int level = 0; level < maxLevel; level++) { int bucketCountInLevel = 0; SortedMap<Integer, Integer> levelMap = bucketSizesPerLevel.get(level); Iterator<Integer> bucketSizeIterator = levelMap.keySet().iterator(); LOG.debug("Statistics for level: " + level); LOG.debug("----------------------------------------------"); LOG.debug(""); LOG.debug("Bucket Size | Count"); LOG.debug("------------------------"); int i = 0; while (bucketSizeIterator.hasNext()) { int bucketSize = bucketSizeIterator.next(); if (bucketSize != 0) { int countForBucketSize = levelMap.get(bucketSize); bucketCountInLevel += countForBucketSize; Formatter formatter = new Formatter(); formatter.format(" %10d | %10d", bucketSize, countForBucketSize); if (levelMap.size() < 20 || i < 3 || i >= (levelMap.size() - 3)) { LOG.debug(formatter.out()); } else if (levelMap.size() / 2 == i) { LOG.debug(" .. | .."); LOG.debug(formatter.out()); LOG.debug(" .. | .."); }/*from w ww .j a v a 2s. c o m*/ i++; formatter.close(); } } LOG.debug(""); LOG.debug("Number of non-empty buckets in level: " + bucketCountInLevel); LOG.debug("Number of empty buckets in level : " + levelMap.get(0)); LOG.debug("Number of different bucket sizes : " + (levelMap.size() - 1)); LOG.debug(""); LOG.debug(""); LOG.debug(""); } }
From source file:eu.stratosphere.pact.runtime.hash.MultiLevelHashITCase.java
private void printStatistics() { for (int level = 0; level < maxLevel; level++) { int bucketCountInLevel = 0; SortedMap<Integer, Integer> levelMap = bucketSizesPerLevel.get(level); Iterator<Integer> bucketSizeIterator = levelMap.keySet().iterator(); LOG.debug("Statistics for level: " + level); LOG.debug("----------------------------------------------"); LOG.debug(""); LOG.debug("Bucket Size | Count"); LOG.debug("------------------------"); int i = 0; while (bucketSizeIterator.hasNext()) { int bucketSize = bucketSizeIterator.next(); if (bucketSize != 0) { int countForBucketSize = levelMap.get(bucketSize); bucketCountInLevel += countForBucketSize; Formatter formatter = new Formatter(); formatter.format(" %10d | %10d", bucketSize, countForBucketSize); if (levelMap.size() < 20 || i < 3 || i >= (levelMap.size() - 3)) { LOG.debug(formatter.out()); } else if (levelMap.size() / 2 == i) { LOG.debug(" .. | .."); LOG.debug(formatter.out()); LOG.debug(" .. | .."); }/*from w w w. ja v a 2 s .c o m*/ i++; } } LOG.debug(""); LOG.debug("Number of non-empty buckets in level: " + bucketCountInLevel); LOG.debug("Number of empty buckets in level : " + levelMap.get(0)); LOG.debug("Number of different bucket sizes : " + (levelMap.size() - 1)); LOG.debug(""); LOG.debug(""); LOG.debug(""); } }
From source file:org.apache.hadoop.hive.ql.udf.UDFIpInfo.java
private void putToIpTables(IpRange range) { Long range_end = range.getEndip(); SortedMap<Long, IpRange> subList = ipTables.tailMap(range.getStartip()); List<IpRange> rangeList = new ArrayList<IpRange>(); for (Iterator<Long> it = subList.keySet().iterator(); it.hasNext();) { Long start = it.next();/*from w ww . j a v a 2s . c o m*/ IpRange rang1 = subList.get(start); if (rang1.getStartip() <= range_end) { rangeList.add(rang1); } } for (int i = 0; i < rangeList.size(); i++) { IpRange rang1 = rangeList.get(i); this.ipTables.remove(rang1.getEndip()); range = this.subSetRange(rang1, range); if (range == null) { break; } } if (range != null) { this.ipTables.put(range.getEndip(), range); } }
From source file:gov.nih.nci.caarray.magetab.splitter.SdrfSplitterTest.java
/** * linesToAdd are added in sequential order. This <em>modifies</em> the lines * in place. So to add 2 lines before the header and 1 after, the keys should be * (0, 1, 3), because that will add two lines (moving the header down), then add after * the header./*from ww w. j a v a2 s . c o m*/ */ private Function<File, File> getTransform(final SortedMap<Integer, String> linesToAdd) { Function<File, File> transform = new Function<File, File>() { @Override public File apply(File input) { try { @SuppressWarnings("unchecked") List<String> lines = FileUtils.readLines(input); for (Integer i : linesToAdd.keySet()) { lines.add(i, linesToAdd.get(i)); } File revisedSdrf = File.createTempFile("test", ".sdrf"); FileUtils.writeLines(revisedSdrf, lines); return revisedSdrf; } catch (IOException ioe) { throw new RuntimeException(ioe); } } }; return transform; }
From source file:uk.org.sappho.applications.transcript.service.registry.WorkingCopy.java
public void putProperties(String environment, String application, SortedMap<String, Object> properties, boolean isMerge) throws TranscriptException { Gson gson = new Gson(); synchronized (getLock()) { SortedMap<String, Object> oldProperties = getJsonProperties(environment, application); SortedMap<String, Object> newProperties; if (isMerge && !oldProperties.isEmpty()) { newProperties = new TreeMap<String, Object>(); for (String key : oldProperties.keySet()) { newProperties.put(key, oldProperties.get(key)); }// w w w .j a v a 2s .c om for (String key : properties.keySet()) { Object newValue = properties.get(key); if (transcriptParameters.isFailOnValueChange() && oldProperties.containsKey(key) && !gson.toJson(newValue).equals(gson.toJson(oldProperties.get(key)))) { throw new TranscriptException("Value of property " + environment + ":" + application + ":" + key + " would change"); } newProperties.put(key, newValue); } } else { newProperties = properties; } String oldJson = gson.toJson(oldProperties); String newJson = gson.toJson(newProperties); if (!newJson.equals(oldJson)) { putProperties(environment, application, newProperties); } } }
From source file:org.opennaas.extensions.genericnetwork.capability.circuitstatistics.CircuitStatisticsCapability.java
private String writeToCSV(SortedMap<Long, List<CircuitStatistics>> circuitStatistics) throws IOException { StringBuilder sb = new StringBuilder(); CSVWriter writer = new CSVWriter(new StringBuilderWriter(sb), CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER); try {/*from www . j a va2 s. c om*/ for (Long timestamp : circuitStatistics.keySet()) for (CircuitStatistics currentStatistic : circuitStatistics.get(timestamp)) { String[] csvStatistic = new String[7]; csvStatistic[0] = String.valueOf(timestamp); csvStatistic[1] = currentStatistic.getSlaFlowId(); csvStatistic[2] = currentStatistic.getThroughput(); csvStatistic[3] = currentStatistic.getPacketLoss(); csvStatistic[4] = currentStatistic.getDelay(); csvStatistic[5] = currentStatistic.getJitter(); csvStatistic[6] = currentStatistic.getFlowData(); writer.writeNext(csvStatistic); } return sb.toString(); } finally { writer.close(); } }
From source file:jhttpp2.Jhttpp2ClientInputStream.java
/** * Parser for the first (!) line from the HTTP request<BR> * Sets up the URL, method and remote hostname. * /*from w ww . j a va 2 s . c o m*/ * @return an InetAddress for the hostname, null on errors with a * statuscode!=SC_OK */ public InetAddress parseRequest(String a, int method_index) { log.debug(a); String f; int pos; url = ""; if (ssl) { f = a.substring(8); } else { method = a.substring(0, a.indexOf(" ")); // first word in the line pos = a.indexOf(":"); // locate first : if (pos == -1) { // occours with "GET / HTTP/1.1" url = a.substring(a.indexOf(" ") + 1, a.lastIndexOf(" ")); if (method_index == 0) { // method_index==0 --> GET if (url.indexOf(server.WEB_CONFIG_FILE) != -1) statuscode = Jhttpp2HTTPSession.SC_CONFIG_RQ; else statuscode = Jhttpp2HTTPSession.SC_FILE_REQUEST; } else { if (method_index == 1 && url.indexOf(server.WEB_CONFIG_FILE) != -1) { // allow // "POST" // for // admin // log // in statuscode = Jhttpp2HTTPSession.SC_CONFIG_RQ; } else { statuscode = Jhttpp2HTTPSession.SC_INTERNAL_SERVER_ERROR; errordescription = "This WWW proxy supports only the \"GET\" method while acting as webserver."; } } return null; } f = a.substring(pos + 3); // removes "http://" } pos = f.indexOf(" "); // locate space, should be the space before // "HTTP/1.1" if (pos == -1) { // buggy request statuscode = Jhttpp2HTTPSession.SC_CLIENT_ERROR; errordescription = "Your browser sent an invalid request: \"" + a + "\""; return null; } f = f.substring(0, pos); // removes all after space // if the url contains a space... it's not our mistake...(url's must // never contain a space character) pos = f.indexOf("/"); // locate the first slash if (pos != -1) { url = f.substring(pos); // saves path without hostname f = f.substring(0, pos); // reduce string to the hostname } else url = "/"; // occurs with this request: // "GET http://localhost HTTP/1.1" pos = f.indexOf(":"); // check for the portnumber if (pos != -1) { String l_port = f.substring(pos + 1); l_port = l_port.indexOf(" ") != -1 ? l_port.substring(0, l_port.indexOf(" ")) : l_port; int i_port = 80; try { i_port = Integer.parseInt(l_port); } catch (NumberFormatException e_get_host) { server.writeLog("get_Host :" + e_get_host + " !!!!"); } f = f.substring(0, pos); remote_port = i_port; } else remote_port = 80; remote_host_name = f; SortedMap<String, URL> map = server.getHostRedirects(); for (String redirectHost : map.keySet()) { if (redirectHost.equals(remote_host_name)) { URL u = map.get(redirectHost); f = u.getHost(); if (u.getPort() != -1) { remote_port = u.getPort(); } log.debug("Redirecting host " + redirectHost + " to " + f + " port " + remote_port); } } InetAddress address = null; if (server.log_access) server.logAccess(connection.getLocalSocket().getInetAddress().getHostAddress() + " " + method + " " + getFullURL()); try { address = InetAddress.getByName(f); if (remote_port == server.port && address.equals(InetAddress.getLocalHost())) { if (url.indexOf(server.WEB_CONFIG_FILE) != -1 && (method_index == 0 || method_index == 1)) statuscode = Jhttpp2HTTPSession.SC_CONFIG_RQ; else if (method_index > 0) { statuscode = Jhttpp2HTTPSession.SC_INTERNAL_SERVER_ERROR; errordescription = "This WWW proxy supports only the \"GET\" method while acting as webserver."; } else statuscode = Jhttpp2HTTPSession.SC_FILE_REQUEST; } } catch (UnknownHostException e_u_host) { if (!server.use_proxy) statuscode = Jhttpp2HTTPSession.SC_HOST_NOT_FOUND; } return address; }
From source file:net.ripe.rpki.commons.crypto.rfc3779.ResourceExtensionParser.java
/** * Parses the IP address blocks extension and merges all address families * into a single {@link IpResourceSet} containing both IPv4 and IPv6 * addresses. Maps an {@link AddressFamily} to <code>null</code> when the * resource of this type are inherited. If no resources are specified it is * mapped to an empty resource set.//from w w w . j a v a2 s . co m */ public SortedMap<AddressFamily, IpResourceSet> parseIpAddressBlocks(byte[] extension) { ASN1Primitive octetString = decode(extension); expect(octetString, ASN1OctetString.class); ASN1OctetString o = (ASN1OctetString) octetString; SortedMap<AddressFamily, IpResourceSet> map = derToIpAddressBlocks(decode(o.getOctets())); for (AddressFamily family : SUPPORTED_ADDRESS_FAMILIES) { if (!map.containsKey(family)) { map.put(family, new IpResourceSet()); } } for (AddressFamily addressFamily : map.keySet()) { Validate.isTrue(!addressFamily.hasSubsequentAddressFamilyIdentifier(), "SAFI not supported"); } return map; }
From source file:org.photovault.replication.ValueChange.java
/** * Add a new property change to the field. * @param propName Name of the property// ww w . j a v a 2 s .c om * @param newValue New value for the property */ void addPropChange(String propName, Object newValue) { // Find all previous attemps to set a part of this property String subPartStart = getKeyForProp(propName); SortedMap<String, Object> propParts = propChanges.tailMap(subPartStart); Set<String> subValueChanges = new HashSet<String>(); for (String k : propParts.keySet()) { if (k.startsWith(subPartStart)) { subValueChanges.add(k); } else { break; } } for (String k : subValueChanges) { propChanges.remove(k); } propChanges.put(getKeyForProp(propName), newValue); }
From source file:com.aurel.track.exchange.importer.MsProjectImportActionTest.java
/** * This method executes the ms project file import. In case if needed handles resource mappings. *///from www . ja v a 2 s . com @Test public void testSubmitResourceMapping() { try { File msProjectFolder = new File(MS_PROJECT_FILES_PATH); File[] listOfFiles = msProjectFolder.listFiles(); for (File fileToUpload : listOfFiles) { if (fileToUpload.isFile()) { System.out.println("Testing the following Ms. project file: " + fileToUpload.getName()); File tempFile = new File( msProjectFolder + "/" + FilenameUtils.removeExtension(fileToUpload.getName()) + "Tmp." + FilenameUtils.getExtension(fileToUpload.getName())); Files.copy(fileToUpload, tempFile); MsProjectExchangeDataStoreBean msProjectExchangeDataStoreBean; msProjectExchangeDataStoreBean = MsProjectExchangeBL.initMsProjectExchangeBeanForImport( PROJECT_OR_RELEASE_ID, PersonBL.loadByPrimaryKey(1), tempFile, null); SortedMap<String, Integer> resourceNameToResourceUIDMap = MsProjectImporterBL .getResourceNameToResourceUIDMap(msProjectExchangeDataStoreBean.getWorkResources()); Map<Integer, Integer> resourceUIDToPersonIDMap = new HashMap<Integer, Integer>(); for (String key : resourceNameToResourceUIDMap.keySet()) { resourceUIDToPersonIDMap.put(resourceNameToResourceUIDMap.get(key), DEFAULT_PERSON_ID); } sessionMap.put("msProjectImporterBean", msProjectExchangeDataStoreBean); ActionProxy actionProxy = getActionProxy("/msProjectImport!submitResourceMapping.action"); actionProxy.getInvocation().getInvocationContext().setSession(sessionMap); String result = actionProxy.execute(); String responseText = response.getContentAsString(); assertTrue(responseText.length() > 0); assertNotNull(responseText); System.out.println("Test method name: submitResourceMapping result: " + result + " response: " + responseText); deleteProjectTasks(); if (tempFile.exists()) { tempFile.delete(); } } } } catch (Exception ex) { ex.printStackTrace(); } }