List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Collection<EventBean> normalizeCollection(SortedMap<Object, Set<EventBean>> submapOne, SortedMap<Object, Set<EventBean>> submapTwo) { if (submapOne.size() == 0) { return normalizeCollection(submapTwo); }/*from ww w . jav a2 s.c o m*/ if (submapTwo.size() == 0) { return normalizeCollection(submapOne); } ArrayDeque<EventBean> result = new ArrayDeque<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submapOne.entrySet()) { result.addAll(entry.getValue()); } for (Map.Entry<Object, Set<EventBean>> entry : submapTwo.entrySet()) { result.addAll(entry.getValue()); } return result; }
From source file:org.cloudata.core.tabletserver.ColumnCollection.java
License:asdf
public TabletMapFile[] splitAndSaveToDisk(TabletInfo tabletInfo, Row.Key midRowKey, TabletInfo[] splitedTabletInfos, String columnName, String fileId, int numOfVersion) throws IOException { TabletMapFile[] tabletMapFiles = new TabletMapFile[2]; MapFileWriter[] mapFileWriters = new MapFileWriter[2]; for (int i = 0; i < 2; i++) { GPath tempMapFilePath = new GPath(Tablet.getTabletSplitTempPath(conf, splitedTabletInfos[i]), columnName + "/" + fileId + "/"); tabletMapFiles[i] = new TabletMapFile(conf, CloudataFileSystem.get(conf), splitedTabletInfos[i], columnName, fileId, tempMapFilePath, numOfVersion); mapFileWriters[i] = tabletMapFiles[i].getMapFileWriter(); }//from w ww.ja v a2 s . c om int index = 0; CStopWatch watch = new CStopWatch(); mapLock.readLock().lock(); try { for (Map.Entry<Row.Key, SortedMap<Cell.Key, ValueCollection>> entry : columnCollectionMap.entrySet()) { Row.Key rowKey = entry.getKey(); if (index < 1 && rowKey.compareTo(midRowKey) > 0) { index++; } SortedMap<Cell.Key, ValueCollection> columnValues = entry.getValue(); synchronized (columnValues) { watch.start("write mapFileWriters in split", 1000); for (Map.Entry<Cell.Key, ValueCollection> eachEntry : columnValues.entrySet()) { mapFileWriters[index].write(eachEntry.getValue()); } watch.stopAndReportIfExceed(LOG); } } } finally { mapLock.readLock().unlock(); for (int i = 0; i < 2; i++) { try { mapFileWriters[i].close(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } return tabletMapFiles; }
From source file:org.orekit.time.UTCTAIBulletinAFilesLoader.java
/** {@inheritDoc} */ @Override/*from w w w .j a va2s . c o m*/ public List<OffsetModel> loadOffsets() throws OrekitException { final Parser parser = new Parser(); DataProvidersManager.getInstance().feed(supportedNames, parser); final SortedMap<Integer, Integer> taiUtc = parser.getTaiUtc(); final SortedMap<Integer, Double> ut1Utc = parser.getUt1Utc(); // identify UT1-UTC discontinuities final List<Integer> leapDays = new ArrayList<Integer>(); Map.Entry<Integer, Double> previous = null; for (final Map.Entry<Integer, Double> entry : ut1Utc.entrySet()) { if (previous != null) { final double delta = entry.getValue() - previous.getValue(); if (FastMath.abs(delta) > 0.5) { // discontinuity found between previous and current entry, a leap second has occurred leapDays.add(entry.getKey()); } } previous = entry; } final List<OffsetModel> offsets = new ArrayList<OffsetModel>(); if (!taiUtc.isEmpty()) { // find the start offset, before the first UT1-UTC entry final Map.Entry<Integer, Integer> firstTaiMUtc = taiUtc.entrySet().iterator().next(); int offset = firstTaiMUtc.getValue(); final int refMJD = firstTaiMUtc.getKey(); for (final int leapMJD : leapDays) { if (leapMJD > refMJD) { break; } --offset; } // set all known time steps for (final int leapMJD : leapDays) { offsets.add(new OffsetModel(new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, leapMJD), ++offset)); } // check for missing time steps for (final Map.Entry<Integer, Integer> refTaiMUtc : taiUtc.entrySet()) { final DateComponents refDC = new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, refTaiMUtc.getKey() + 1); OffsetModel before = null; for (final OffsetModel o : offsets) { if (o.getStart().compareTo(refDC) < 0) { before = o; } } if (before != null) { if (refTaiMUtc.getValue() != (int) FastMath.rint(before.getOffset())) { throw new OrekitException(OrekitMessages.MISSING_EARTH_ORIENTATION_PARAMETERS_BETWEEN_DATES, before.getStart(), refDC); } } } // make sure we stop the linear drift that was used before 1972 if (offsets.isEmpty()) { offsets.add(0, new OffsetModel(new DateComponents(1972, 1, 1), taiUtc.get(taiUtc.firstKey()))); } else { if (offsets.get(0).getStart().getYear() > 1972) { offsets.add(0, new OffsetModel(new DateComponents(1972, 1, 1), ((int) FastMath.rint(offsets.get(0).getOffset())) - 1)); } } } return offsets; }
From source file:JTop.java
/** * Get the thread list with CPU consumption and the ThreadInfo for each thread * sorted by the CPU time.//from w ww . ja v a2 s.c o m */ private List<Map.Entry<Long, ThreadInfo>> getThreadList() { // Get all threads and their ThreadInfo objects // with no stack trace long[] tids = tmbean.getAllThreadIds(); ThreadInfo[] tinfos = tmbean.getThreadInfo(tids); // build a map with key = CPU time and value = ThreadInfo SortedMap<Long, ThreadInfo> map = new TreeMap<Long, ThreadInfo>(); for (int i = 0; i < tids.length; i++) { long cpuTime = tmbean.getThreadCpuTime(tids[i]); // filter out threads that have been terminated if (cpuTime != -1 && tinfos[i] != null) { map.put(new Long(cpuTime), tinfos[i]); } } // build the thread list and sort it with CPU time // in decreasing order Set<Map.Entry<Long, ThreadInfo>> set = map.entrySet(); List<Map.Entry<Long, ThreadInfo>> list = new ArrayList<Map.Entry<Long, ThreadInfo>>(set); Collections.reverse(list); return list; }
From source file:eu.ggnet.dwoss.misc.op.listings.SalesListingProducerOperation.java
/** * Generates PDF files for units in a specific sales channel. * The lists are seperated by brand.//www . j av a 2 s .c o m * <p> * @param channel the saleschannel * @return PDF files for units in a specific sales channel. */ private Map<TradeName, Collection<FileJacket>> generatePdfListings(SalesChannel channel) throws UserInfoException { SubMonitor m = monitorFactory.newSubMonitor("Endkundenlisten erstellen", 10); m.message("lade Gertedaten"); m.start(); List<StockUnit> stockUnits = new StockUnitEao(stockEm).findByNoLogicTransaction(); List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uuEm).findByIds(toUniqueUnitIds(stockUnits)); PriceType priceType = (channel == SalesChannel.CUSTOMER ? PriceType.CUSTOMER : PriceType.RETAILER); m.worked(2, "prfe und filtere Gerte"); SortedMap<UniqueUnit, StockUnit> uusus = toSortedMap(uniqueUnits, stockUnits, new UniqueUnitComparator()); for (Iterator<Map.Entry<UniqueUnit, StockUnit>> it = uusus.entrySet().iterator(); it.hasNext();) { Map.Entry<UniqueUnit, StockUnit> entry = it.next(); UniqueUnit uu = entry.getKey(); StockUnit su = entry.getValue(); if (uu == null) throw new NullPointerException(su + " has no UniqueUnit, Database Error"); if (uu.getSalesChannel() != channel || !uu.hasPrice(priceType) || su.isInTransaction()) { it.remove(); } } L.info("Selected {} Units for the Lists", uusus.size()); m.worked(1, "sortiere und bereite Gerte vor"); Map<Product, Set<UniqueUnit>> stackedUnits = new HashMap<>(); for (Map.Entry<UniqueUnit, StockUnit> entry : uusus.entrySet()) { Product p = entry.getKey().getProduct(); if (!stackedUnits.containsKey(p)) stackedUnits.put(p, new HashSet<>()); stackedUnits.get(p).add(entry.getKey()); } List<StackedLine> stackedLines = new ArrayList<>(stackedUnits.size()); DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN); df.applyPattern("#,###,##0.00"); for (Map.Entry<Product, Set<UniqueUnit>> entry : stackedUnits.entrySet()) { Product p = entry.getKey(); StackedLine line = new StackedLine(); line.setBrand(p.getTradeName()); line.setGroup(p.getGroup()); line.setCommodityGroupName(p.getGroup().getNote()); line.setDescription(p.getDescription()); line.setManufacturerName(p.getTradeName().getName()); line.setManufacturerPartNo(p.getPartNo()); line.setName(p.getName()); line.setImageUrl(imageFinder.findImageUrl(p.getImageId())); boolean priceChanged = false; double customerPrice = 0; for (UniqueUnit uu : entry.getValue()) { StackedLineUnit elem = new StackedLineUnit(); elem.setAccessories(UniqueUnitFormater.toSingleLineAccessories(uu)); elem.setComment(UniqueUnitFormater.toSingleLineComment(uu)); elem.setConditionLevelDescription(uu.getCondition().getNote()); elem.setMfgDate(uu.getMfgDate()); elem.setRefurbishedId(uu.getRefurbishId()); elem.setSerial(uu.getSerial()); elem.setWarranty(uu.getWarranty().getName()); if (uu.getWarranty().equals(Warranty.WARRANTY_TILL_DATE)) elem.setWarrentyTill(uu.getWarrentyValid()); double uuPrice = uu.getPrice(priceType); elem.setCustomerPrice(uuPrice); elem.setRoundedTaxedCustomerPrice(MathUtil.roundedApply(uuPrice, GlobalConfig.TAX, 0.02)); // For the "ab XXX" handler if (customerPrice == 0) { customerPrice = uuPrice; } else if (customerPrice > uuPrice) { customerPrice = uuPrice; priceChanged = true; } else if (customerPrice < uuPrice) { priceChanged = true; } elem.normaize(); line.add(elem); } line.setAmount(line.getUnits().size()); line.setCustomerPriceLabel((priceChanged ? "ab " : "") + df.format(MathUtil.roundedApply(customerPrice, GlobalConfig.TAX, 0.02))); line.normaize(); stackedLines.add(line); } L.info("Created {} Lines for the Lists", stackedLines.size()); m.worked(1, "erzeuge listen"); Set<ListingConfiguration> configs = new HashSet<>(); if (listingService.isAmbiguous() || listingService.isUnsatisfied()) { for (TradeName brand : TradeName.values()) { for (ProductGroup value : ProductGroup.values()) { configs.add(ListingConfiguration.builder().filePrefix("Gerteliste ") .name(brand.getName() + " " + value.getName()).brand(brand).groups(EnumSet.of(value)) .headLeft("Beispieltext Links\nZeile 2").headCenter("Beispieltext Mitte\nZeile 2") .headRight("Beispieltext Rechts\nZeile 2").footer("Fusszeilentext").build()); } } } else { configs.addAll(listingService.get().listingConfigurations()); } m.setWorkRemaining(configs.size() + 1); Map<TradeName, Collection<FileJacket>> jackets = new HashMap<>(); for (ListingConfiguration config : configs) { m.worked(1, "erstelle Liste " + config.getName()); if (StringUtils.isBlank(config.getJasperTemplateFile())) config.setJasperTemplateFile(compileReportToTempFile("CustomerSalesListing")); if (StringUtils.isBlank(config.getJasperTempleteUnitsFile())) config.setJasperTempleteUnitsFile(compileReportToTempFile("CustomerSalesListingUnits")); FileJacket fj = createListing(config, stackedLines); if (fj != null) { if (!jackets.containsKey(config.getBrand())) jackets.put(config.getBrand(), new HashSet<>()); jackets.get(config.getBrand()).add(fj); } } m.finish(); return jackets; }
From source file:org.apache.falcon.resource.proxy.ExtensionManagerProxy.java
private void deleteEntities(SortedMap<EntityType, List<String>> entityMap, HttpServletRequest request) throws FalconException { for (Map.Entry<EntityType, List<String>> entityTypeEntry : entityMap.entrySet()) { for (final String entityName : entityTypeEntry.getValue()) { HttpServletRequest bufferedRequest = new BufferedRequest(request); entityProxyUtil.proxyDelete(entityTypeEntry.getKey().name(), entityName, bufferedRequest); if (!embeddedMode) { super.delete(bufferedRequest, entityTypeEntry.getKey().name(), entityName, currentColo); }//from w ww. j ava2 s. co m } } }
From source file:org.apache.accumulo.server.master.balancer.ChaoticLoadBalancer.java
@Override public long balance(SortedMap<TServerInstance, TabletServerStatus> current, Set<KeyExtent> migrations, List<TabletMigration> migrationsOut) { Map<TServerInstance, Long> numTablets = new HashMap<TServerInstance, Long>(); List<TServerInstance> underCapacityTServer = new ArrayList<TServerInstance>(); if (!migrations.isEmpty()) { outstandingMigrations.migrations = migrations; constraintNotMet(outstandingMigrations); return 100; }// w w w. j a va 2s. com resetBalancerErrors(); boolean moveMetadata = r.nextInt(4) == 0; long totalTablets = 0; for (Entry<TServerInstance, TabletServerStatus> e : current.entrySet()) { long tabletCount = 0; for (TableInfo ti : e.getValue().getTableMap().values()) { tabletCount += ti.tablets; } numTablets.put(e.getKey(), tabletCount); underCapacityTServer.add(e.getKey()); totalTablets += tabletCount; } // totalTablets is fuzzy due to asynchronicity of the stats // *1.2 to handle fuzziness, and prevent locking for 'perfect' balancing scenarios long avg = (long) Math.ceil(((double) totalTablets) / current.size() * 1.2); for (Entry<TServerInstance, TabletServerStatus> e : current.entrySet()) { for (String table : e.getValue().getTableMap().keySet()) { if (!moveMetadata && MetadataTable.NAME.equals(table)) continue; try { for (TabletStats ts : getOnlineTabletsForTable(e.getKey(), table)) { KeyExtent ke = new KeyExtent(ts.extent); int index = r.nextInt(underCapacityTServer.size()); TServerInstance dest = underCapacityTServer.get(index); if (dest.equals(e.getKey())) continue; migrationsOut.add(new TabletMigration(ke, e.getKey(), dest)); if (numTablets.put(dest, numTablets.get(dest) + 1) > avg) underCapacityTServer.remove(index); if (numTablets.put(e.getKey(), numTablets.get(e.getKey()) - 1) <= avg && !underCapacityTServer.contains(e.getKey())) underCapacityTServer.add(e.getKey()); // We can get some craziness with only 1 tserver, so lets make sure there's always an option! if (underCapacityTServer.isEmpty()) underCapacityTServer.addAll(numTablets.keySet()); } } catch (ThriftSecurityException e1) { // Shouldn't happen, but carry on if it does log.debug("Encountered ThriftSecurityException. This should not happen. Carrying on anyway.", e1); } catch (TException e1) { // Shouldn't happen, but carry on if it does log.debug("Encountered TException. This should not happen. Carrying on anyway.", e1); } } } return 100; }
From source file:hermes.browser.model.PropertySetTableModel.java
public PropertySetTableModel(Object bean, PropertySetConfig propertySet, Set filter) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { this.propertySet = propertySet; Set iterSet = null;/* w w w. ja v a2 s.c o m*/ SortedMap sortMap = new TreeMap(); if (propertySet.getProperty() != null) { for (Iterator iter = propertySet.getProperty().iterator(); iter.hasNext();) { PropertyConfig property = (PropertyConfig) iter.next(); if (!ignore.contains(property.getName())) { Object propertyValue = property.getValue(); if (propertyValue == null) { propertyValue = "null"; } sortMap.put(property.getName(), propertyValue); } } for (Iterator iter2 = sortMap.entrySet().iterator(); iter2.hasNext();) { Map.Entry entry = (Map.Entry) iter2.next(); Vector row = new Vector(); row.add(entry.getKey()); row.add(entry.getValue()); rows.add(row); } } setBean(bean); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step6GraphTransitivityCleaner.java
@SuppressWarnings("unchecked") public static void printResultStatistics(File xmlFile) throws IllegalAccessException { Map<String, Map<String, GraphCleaningResults>> results = (Map<String, Map<String, GraphCleaningResults>>) XStreamTools .getXStream().fromXML(xmlFile); // System.out.println(results); SortedMap<String, List<GraphCleaningResults>> resultsGroupedByMethod = new TreeMap<>(); for (Map.Entry<String, Map<String, GraphCleaningResults>> entry : results.entrySet()) { // System.out.println(entry.getKey()); for (Map.Entry<String, GraphCleaningResults> e : entry.getValue().entrySet()) { // System.out.println(e.getKey()); // System.out.println(e.getValue()); if (!resultsGroupedByMethod.containsKey(e.getKey())) { resultsGroupedByMethod.put(e.getKey(), new ArrayList<GraphCleaningResults>()); }/*from w ww . j a v a 2s . co m*/ resultsGroupedByMethod.get(e.getKey()).add(e.getValue()); } } String header = null; // collect statistics for (Map.Entry<String, List<GraphCleaningResults>> entry : resultsGroupedByMethod.entrySet()) { List<GraphCleaningResults> value = entry.getValue(); SortedMap<String, DescriptiveStatistics> stringDescriptiveStatisticsMap = collectStatisticsOverGraphCleaningResults( value); if (header == null) { header = StringUtils.join(stringDescriptiveStatisticsMap.keySet(), "\t"); System.out.println("\t\t" + header); } List<Double> means = new ArrayList<>(); List<Double> stdDevs = new ArrayList<>(); for (DescriptiveStatistics statistics : stringDescriptiveStatisticsMap.values()) { means.add(statistics.getMean()); stdDevs.add(statistics.getStandardDeviation()); } List<String> meansString = new ArrayList<>(); for (Double mean : means) { meansString.add(String.format(Locale.ENGLISH, "%.2f", mean)); } List<String> stdDevString = new ArrayList<>(); for (Double stdDev : stdDevs) { stdDevString.add(String.format(Locale.ENGLISH, "%.2f", stdDev)); } System.out.println(entry.getKey() + "\tmean\t" + StringUtils.join(meansString, "\t")); // System.out.println(entry.getKey() + "\tstdDev\t" + StringUtils.join(stdDevString, "\t")); } }
From source file:disAMS.AMRMClient.Impl.AMRMClientImpl.java
@Override public synchronized List<? extends Collection<T>> getMatchingRequests(Priority priority, String resourceName, Resource capability) {// w w w .j a v a 2s .com Preconditions.checkArgument(capability != null, "The Resource to be requested should not be null "); Preconditions.checkArgument(priority != null, "The priority at which to request containers should not be null "); List<LinkedHashSet<T>> list = new LinkedList<LinkedHashSet<T>>(); Map<String, TreeMap<Resource, ResourceRequestInfo>> remoteRequests = this.remoteRequestsTable.get(priority); if (remoteRequests == null) { return list; } TreeMap<Resource, ResourceRequestInfo> reqMap = remoteRequests.get(resourceName); if (reqMap == null) { return list; } ResourceRequestInfo resourceRequestInfo = reqMap.get(capability); if (resourceRequestInfo != null && !resourceRequestInfo.containerRequests.isEmpty()) { list.add(resourceRequestInfo.containerRequests); return list; } // no exact match. Container may be larger than what was requested. // get all resources <= capability. map is reverse sorted. SortedMap<Resource, ResourceRequestInfo> tailMap = reqMap.tailMap(capability); for (Map.Entry<Resource, ResourceRequestInfo> entry : tailMap.entrySet()) { if (canFit(entry.getKey(), capability) && !entry.getValue().containerRequests.isEmpty()) { // match found that fits in the larger resource list.add(entry.getValue().containerRequests); } } // no match found return list; }