Example usage for java.util TreeMap entrySet

List of usage examples for java.util TreeMap entrySet

Introduction

In this page you can find the example usage for java.util TreeMap entrySet.

Prototype

EntrySet entrySet

To view the source code for java.util TreeMap entrySet.

Click Source Link

Document

Fields initialized to contain an instance of the entry set view the first time this view is requested.

Usage

From source file:com.intellij.ide.passwordSafe.impl.providers.masterKey.PasswordDatabase.java

/**
 * {@inheritDoc}//from w  ww.j  a  v  a 2s .c o m
 */
public State getState() {
    TreeMap<ByteArrayWrapper, byte[]> sorted;
    String pi;
    synchronized (myDatabase) {
        pi = toHex(myMasterPasswordInfo);
        sorted = new TreeMap<ByteArrayWrapper, byte[]>(myDatabase);
    }
    String[][] db = new String[2][sorted.size()];
    int i = 0;
    for (Map.Entry<ByteArrayWrapper, byte[]> e : sorted.entrySet()) {
        db[0][i] = toHex(e.getKey().unwrap());
        db[1][i] = toHex(e.getValue());
        i++;
    }
    State s = new State();
    s.PASSWORDS = db;
    s.MASTER_PASSWORD_INFO = pi;
    return s;
}

From source file:org.mda.bcb.tcgagsdata.create.ProcessFile.java

protected void scanAndProcessDirs(TreeMap<File, String> theFiles) throws IOException {
    TcgaGSData.printWithFlag("ProcessFile::scanAndProcessDirs - Start");
    for (Entry<File, String> entry : theFiles.entrySet()) {
        processFile(entry.getKey(), entry.getValue());
    }/*  w  ww  . j  a v a  2 s .  c o  m*/
    TcgaGSData.printWithFlag("ProcessFile::scanAndProcessDirs - Finished");
}

From source file:edu.utexas.cs.tactex.utilityestimation.UtilityArchitectureActionGenerator.java

/**
 * Potential template method - any function call can be refactored to an interface
 *///from   w  w w.j av a  2 s . c  o m
@Override
public List<TariffMessage> selectTariffActions(boolean useCanUse,
        HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions,
        List<TariffSpecification> competingTariffs, MarketManager marketManager, ContextManager contextManager,
        CostCurvesPredictor costCurvesPredictor, int currentTimeslot, boolean useRevoke, Broker me) {

    boolean customerPerspective = true;
    HashMap<CustomerInfo, ArrayRealVector> customer2estimatedEnergy = energyPredictionManager
            .getAbout7dayPredictionForAllCustomers(customerPerspective, currentTimeslot, /*false*/ true); // false: don't use fixed-rate only, use the standard one

    TreeMap<Double, TariffSpecification> sortedTariffs = tariffOptimizer.optimizeTariffs(tariffSubscriptions,
            customer2estimatedEnergy, competingTariffs, marketManager, contextManager, costCurvesPredictor,
            currentTimeslot, me);

    log.info("Estimated Utilities: ");
    for (Entry<Double, TariffSpecification> e : sortedTariffs.entrySet()) {
        log.info("u: " + e.getKey() + " spec: " + e.getValue());
    }

    TreeMap<Double, TariffMessage> sortedTariffActions = new TreeMap<Double, TariffMessage>();
    sortedTariffActions.putAll(sortedTariffs);

    if (useRevoke) {
        TreeMap<Double, TariffSpecification> sortedTariffRevokes = tariffOptimizerRevoke.optimizeTariffs(
                tariffSubscriptions, customer2estimatedEnergy, competingTariffs, marketManager, contextManager,
                costCurvesPredictor, currentTimeslot, me);

        log.info("(Revoke) Estimated Utilities: ");
        for (Entry<Double, TariffSpecification> e : sortedTariffRevokes.entrySet()) {
            log.info("u: " + e.getKey() + " spec: " + e.getValue());
        }

        // fill util=>action
        for (Entry<Double, TariffSpecification> entry : sortedTariffRevokes.entrySet()) {
            TariffSpecification spec = entry.getValue();
            if (null == spec) {
                sortedTariffActions.put(entry.getKey(), spec);
            } else {
                sortedTariffActions.put(entry.getKey(), new TariffRevoke(me, spec));
            }
        }
    }

    List<TariffMessage> tariffActionsToExecute = selectBestActions(currentTimeslot, sortedTariffActions,
            tariffSubscriptions.keySet());

    return tariffActionsToExecute;
}

From source file:chanupdater.ChanUpdater.java

private void doUpdates() throws SQLException, IOException, FileNotFoundException, LdvTableException {
    if (verbose > 1) {
        System.out.println("Starting update process.");
    }/*w  ww  .  j a v a 2  s.  c o m*/
    ArrayList<ChanListSummary> chanLists;

    HashSet<ChanInfo> del = new HashSet<>();
    totalAdds = 0;
    totalDels = 0;

    for (ChanListSummary cls : cLists) {

        cls.printSummary();
        String server = cls.getServer();
        String cTyp = cls.getcType();

        if (verbose > 2) {
            System.out.format("Check %1$s for type:%2$s ", server, cTyp);
        }

        TreeMap<String, HashSet<ChanInfo>> chanSets = cls.getChanSets();
        for (Entry<String, HashSet<ChanInfo>> ent : chanSets.entrySet()) {
            del.clear();
            HashSet<ChanInfo> newChans = ent.getValue();
            String ifo = ent.getKey();
            if (verbose > 1) {
                System.out.format("Server: %1$s, cType: %2$s, IFO: %3$s, count: %4$,d\n", cls.getServer(),
                        cls.getcType(), ifo, newChans.size());
            }
            String namePat = ifo + ":%";
            TreeSet<ChanInfo> oldSet = chnTbl.getAsSet(server, namePat, cTyp, newChans.size());

            for (ChanInfo old : oldSet) {
                boolean gotit = newChans.contains(old);
                if (gotit) {
                    // it's in both
                    newChans.remove(old);
                } else {
                    if (old.isAvailable()) {
                        // only in old add it to be deleted set
                        del.add(old);
                    }
                }
            }
            totalAdds += newChans.size();
            totalDels += del.size();

            if ((newChans.size() > 0 || del.size() > 0)) {
                if (verbose > 1) {
                    System.out.format("    add: %1$d, del %2$d\n", newChans.size(), del.size());
                }
                for (ChanInfo ci : newChans) {
                    if (verbose > 2) {
                        System.out.print("Add: ");
                        ci.print();
                    }
                    chnTbl.insertNewBulk(ci);
                }
                if (newChans.size() > 0) {
                    chnTbl.insertNewBulk(null); // complete the bulk insert
                }
                if (doDeletes) {
                    for (ChanInfo ci : del) {
                        if (verbose > 2) {
                            System.out.print("Del: ");
                            ci.print();
                        }
                        chnTbl.setAvailable(ci.getId(), false);
                    }
                }
            } else if (verbose > 1) {
                System.out.println("    no updates.");
            }

        }
        if (verbose > 0 && totalAdds + totalDels > 0) {
            System.out.format("Total additions: %1$,d, total removals: %2$,d, " + "Server: %3$s, type: %4$s%n",
                    totalAdds, totalDels, cls.getServer(), cls.getcType());
        } else if (verbose > 1 && totalAdds + totalDels == 0) {
            System.out.println("No changes to channel table. %n");
        }
    }
}

From source file:com.vmware.identity.interop.registry.WinRegistryAdapter.java

@Override
public List<RegValueType> getRegEnumValues(IRegistryKey key) {

    List<RegValueType> keys = new ArrayList<RegValueType>();
    TreeMap<String, Object> map = Advapi32Util
            .registryGetValues(WinRegistryAdapter.getRegistryKey(key).getKey());
    try {/*from  ww  w. j  a  v a 2 s.c  o  m*/
        for (Entry<String, Object> entry : map.entrySet()) {
            Object obj = entry.getValue();
            if (obj instanceof String) {
                keys.add(new RegValueType(entry.getKey(), RegistryValueType.REG_SZ.getCode()));
            } else if (obj instanceof Integer) {
                keys.add(new RegValueType(entry.getKey(), RegistryValueType.REG_DWORD.getCode()));
            } else if (obj.getClass().isArray()) {
                keys.add(new RegValueType(entry.getKey(), RegistryValueType.REG_MULTI_SZ.getCode()));
            } else {
                throw new RegistryUnSupportedKeyTypeException("Unsupport Type " + obj.getClass().toString());
            }
        }
    } catch (RegistryUnSupportedKeyTypeException ex) {
        System.out.println(ex.getMessage());
    }
    return keys;
}

From source file:org.cloudata.core.client.TabletLocationCache.java

public void clearTabletCache(String tableName, TabletInfo tabletInfo) {
    if (tabletInfo == null) {
        return;//from   www. ja  v a  2s.  c o  m
    }
    cacheLock.obtainWriteLock();
    try {
        if (Constants.TABLE_NAME_ROOT.equals(tableName)) {
            rootTablet = null;
        } else if (Constants.TABLE_NAME_META.equals(tableName)) {
            rootCache.clear();
            metaCache.clear();
        } else {
            TreeMap<Row.Key, TabletInfo> tempMetaCache = new TreeMap<Row.Key, TabletInfo>();
            tempMetaCache.putAll(metaCache);
            for (Map.Entry<Row.Key, TabletInfo> entry : tempMetaCache.entrySet()) {
                Row.Key rowKey = entry.getKey();
                TabletInfo entryTabletInfo = entry.getValue();
                if (entryTabletInfo.equals(tabletInfo)) {
                    metaCache.remove(rowKey);
                }
            }
        }
    } finally {
        cacheLock.releaseWriteLock();
    }
}

From source file:captureplugin.drivers.dreambox.connector.DreamboxConnector.java

/**
 * @return All channels available in the dreambox
 *///from  w w w . ja  v a 2  s.c  om
public Collection<DreamboxChannel> getChannels() {
    try {
        ArrayList<DreamboxChannel> allChannels = new ArrayList<DreamboxChannel>();

        TreeMap<String, String> bouquets = getServiceDataBouquets(URLEncoder.encode(BOUQUET_LIST, "UTF8"));
        for (Entry<String, String> entry : bouquets.entrySet()) {
            String key = entry.getKey();
            String bouqetName = entry.getValue();

            TreeMap<String, String> map = getServiceData(URLEncoder.encode(key, "UTF8"));

            for (Entry<String, String> mEntry : map.entrySet()) {
                String mkey = mEntry.getKey();
                allChannels.add(new DreamboxChannel(mkey, mEntry.getValue(), bouqetName));
            }
        }

        return allChannels;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.serphacker.serposcope.db.google.GoogleSerpRescanDB.java

public void rescanNonBulk(Integer specificRunId, Collection<GoogleTarget> targets,
        Collection<GoogleSearch> searches, boolean updateSummary) {
    LOG.debug("SERP rescan (non-bulk) : starting");
    long _start = System.currentTimeMillis();
    Run specPrevRun = null;/*from   w w  w  . j  a  va2s. co m*/
    Map<Integer, GoogleTargetSummary> specPrevRunSummaryByTarget = new HashMap<>();

    if (specificRunId != null) {
        specPrevRun = runDB.findPrevious(specificRunId);
        if (specPrevRun != null) {
            specPrevRunSummaryByTarget = targetSummaryDB.list(specPrevRun.getId()).stream()
                    .collect(Collectors.toMap(GoogleTargetSummary::getTargetId, Function.identity()));
        }
    }

    for (GoogleTarget target : targets) {

        Map<Integer, GoogleTargetSummary> summaryByRunId = new HashMap<>();
        GoogleTargetSummary specificPreviousSummary = specPrevRunSummaryByTarget.get(target.getId());
        if (specificPreviousSummary != null) {
            summaryByRunId.put(specPrevRun.getId(), specificPreviousSummary);
        }

        for (GoogleSearch search : searches) {
            final MutableInt previousRunId = new MutableInt(0);
            final MutableInt previousRank = new MutableInt(GoogleRank.UNRANKED);
            GoogleBest searchBest = new GoogleBest(target.getGroupId(), target.getId(), search.getId(),
                    GoogleRank.UNRANKED, null, null);

            if (specPrevRun != null) {
                previousRunId.setValue(specPrevRun.getId());
                previousRank.setValue(
                        rankDB.get(specPrevRun.getId(), target.getGroupId(), target.getId(), search.getId()));
                GoogleBest specificBest = rankDB.getBest(target.getGroupId(), target.getId(), search.getId());
                if (specificBest != null) {
                    searchBest = specificBest;
                }
            }
            final GoogleBest best = searchBest;

            serpDB.stream(specificRunId, specificRunId, search.getId(), (GoogleSerp res) -> {

                int rank = GoogleRank.UNRANKED;
                String rankedUrl = null;
                for (int i = 0; i < res.getEntries().size(); i++) {
                    if (target.match(res.getEntries().get(i).getUrl())) {
                        rankedUrl = res.getEntries().get(i).getUrl();
                        rank = i + 1;
                        break;
                    }
                }

                // only update last run
                GoogleRank gRank = new GoogleRank(res.getRunId(), target.getGroupId(), target.getId(),
                        search.getId(), rank, previousRank.shortValue(), rankedUrl);
                rankDB.insert(gRank);

                if (updateSummary) {
                    GoogleTargetSummary summary = summaryByRunId.get(res.getRunId());
                    if (summary == null) {
                        summaryByRunId.put(res.getRunId(),
                                summary = new GoogleTargetSummary(target.getGroupId(), target.getId(),
                                        res.getRunId(), 0));
                    }
                    summary.addRankCandidat(gRank);
                }

                if (rank != GoogleRank.UNRANKED && rank <= best.getRank()) {
                    best.setRank((short) rank);
                    best.setUrl(rankedUrl);
                    best.setRunDay(res.getRunDay());
                }

                previousRunId.setValue(res.getRunId());
                previousRank.setValue(rank);
            });

            if (best.getRank() != GoogleRank.UNRANKED) {
                rankDB.insertBest(best);
            }
        }

        // fill previous summary score
        if (updateSummary) {
            TreeMap<Integer, GoogleTargetSummary> summaries = new TreeMap<>(summaryByRunId);

            GoogleTargetSummary previousSummary = null;
            for (Map.Entry<Integer, GoogleTargetSummary> entry : summaries.entrySet()) {
                if (previousSummary != null) {
                    entry.getValue().setPreviousScoreBP(previousSummary.getScoreBP());
                }
                previousSummary = entry.getValue();
            }

            if (specPrevRun != null) {
                summaries.remove(specPrevRun.getId());
            }

            if (!summaries.isEmpty()) {
                targetSummaryDB.insert(summaries.values());
            }
        }
    }
    LOG.debug("SERP rescan : done, duration = {}",
            DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - _start));
}

From source file:org.opendatakit.security.spring.RoleHierarchyImpl.java

/**
 * Parse input and build the map for the roles reachable in one step: the higher role will become
 * a key that references a set of the reachable lower roles.
 * //  w  w w  . j a  v  a  2  s .co m
 * @throws ODKDatastoreException
 */
private synchronized Map<GrantedAuthority, Set<GrantedAuthority>> buildRolesReachableInOneStepMap()
        throws ODKDatastoreException {
    Map<GrantedAuthority, Set<GrantedAuthority>> rolesReachableInOneStepMap = new HashMap<GrantedAuthority, Set<GrantedAuthority>>();

    User user = userService.getDaemonAccountUser();
    TreeMap<String, TreeSet<String>> oneStepRelations = GrantedAuthorityHierarchyTable
            .getEntireGrantedAuthorityHierarchy(datastore, user);

    for (Map.Entry<String, TreeSet<String>> e : oneStepRelations.entrySet()) {
        GrantedAuthority higherRole = new SimpleGrantedAuthority(e.getKey());
        Set<GrantedAuthority> rolesReachableInOneStepSet = null;

        if (!rolesReachableInOneStepMap.containsKey(higherRole)) {
            rolesReachableInOneStepSet = new HashSet<GrantedAuthority>();
            rolesReachableInOneStepMap.put(higherRole, rolesReachableInOneStepSet);
        } else {
            rolesReachableInOneStepSet = rolesReachableInOneStepMap.get(higherRole);
        }

        for (String s : e.getValue()) {
            GrantedAuthority lowerRole = new SimpleGrantedAuthority(s);

            addReachableRoles(rolesReachableInOneStepSet, lowerRole);

            logger.debug("buildRolesReachableInOneStepMap() - From role " + higherRole + " one can reach role "
                    + lowerRole + " in one step.");
        }
    }

    return rolesReachableInOneStepMap;
}

From source file:com.serphacker.serposcope.db.google.GoogleSerpRescanDB.java

public void rescan(Integer specificRunId, Collection<GoogleTarget> targets, Collection<GoogleSearch> searches,
        boolean updateSummary) {
    LOG.debug("SERP rescan (bulk) : starting");
    long _start = System.currentTimeMillis();
    Map<Integer, Integer> searchCountByGroup = searchDB.countByGroup();
    Run specPrevRun = null;// ww  w.  j  a  va 2  s.c o  m
    Map<Integer, GoogleTargetSummary> specPrevRunSummaryByTarget = new HashMap<>();

    if (specificRunId != null) {
        specPrevRun = runDB.findPrevious(specificRunId);
        if (specPrevRun != null) {
            specPrevRunSummaryByTarget = targetSummaryDB.list(specPrevRun.getId()).stream()
                    .collect(Collectors.toMap(GoogleTargetSummary::getTargetId, Function.identity()));
        }
    }

    List<GoogleRank> ranks = new ArrayList<>();
    for (GoogleTarget target : targets) {

        Map<Integer, GoogleTargetSummary> summaryByRunId = new HashMap<>();
        GoogleTargetSummary specificPreviousSummary = specPrevRunSummaryByTarget.get(target.getId());
        if (specificPreviousSummary != null) {
            summaryByRunId.put(specPrevRun.getId(), specificPreviousSummary);
        }

        for (GoogleSearch search : searches) {
            final MutableInt previousRunId = new MutableInt(0);
            final MutableInt previousRank = new MutableInt(GoogleRank.UNRANKED);
            GoogleBest searchBest = new GoogleBest(target.getGroupId(), target.getId(), search.getId(),
                    GoogleRank.UNRANKED, null, null);

            if (specPrevRun != null) {
                previousRunId.setValue(specPrevRun.getId());
                previousRank.setValue(
                        rankDB.get(specPrevRun.getId(), target.getGroupId(), target.getId(), search.getId()));
                GoogleBest specificBest = rankDB.getBest(target.getGroupId(), target.getId(), search.getId());
                if (specificBest != null) {
                    searchBest = specificBest;
                }
            }
            final GoogleBest best = searchBest;

            serpDB.stream(specificRunId, specificRunId, search.getId(), (GoogleSerp res) -> {

                int rank = GoogleRank.UNRANKED;
                String rankedUrl = null;
                for (int i = 0; i < res.getEntries().size(); i++) {
                    if (target.match(res.getEntries().get(i).getUrl())) {
                        rankedUrl = res.getEntries().get(i).getUrl();
                        rank = i + 1;
                        break;
                    }
                }

                // only update last run
                GoogleRank gRank = new GoogleRank(res.getRunId(), target.getGroupId(), target.getId(),
                        search.getId(), rank, previousRank.shortValue(), rankedUrl);
                ranks.add(gRank);
                if (ranks.size() > 2000) {
                    rankDB.insert(ranks);
                    ranks.clear();
                }

                if (updateSummary) {
                    GoogleTargetSummary summary = summaryByRunId.get(res.getRunId());
                    if (summary == null) {
                        summaryByRunId.put(res.getRunId(),
                                summary = new GoogleTargetSummary(target.getGroupId(), target.getId(),
                                        res.getRunId(), 0));
                    }
                    summary.addRankCandidat(gRank);
                }

                if (rank != GoogleRank.UNRANKED && rank <= best.getRank()) {
                    best.setRank((short) rank);
                    best.setUrl(rankedUrl);
                    best.setRunDay(res.getRunDay());
                }

                previousRunId.setValue(res.getRunId());
                previousRank.setValue(rank);
            });

            if (best.getRank() != GoogleRank.UNRANKED) {
                rankDB.insertBest(best);
            }
        }

        // fill previous summary score
        if (updateSummary) {
            TreeMap<Integer, GoogleTargetSummary> summaries = new TreeMap<>(summaryByRunId);

            GoogleTargetSummary previousSummary = null;
            for (Map.Entry<Integer, GoogleTargetSummary> entry : summaries.entrySet()) {
                GoogleTargetSummary summary = entry.getValue();
                summary.computeScoreBP(searchCountByGroup.getOrDefault(summary.getGroupId(), 0));
                if (previousSummary != null) {
                    summary.setPreviousScoreBP(previousSummary.getScoreBP());
                }
                previousSummary = summary;
            }

            if (specPrevRun != null) {
                summaries.remove(specPrevRun.getId());
            }

            if (!summaries.isEmpty()) {
                targetSummaryDB.insert(summaries.values());
            }
        }
    }

    if (!ranks.isEmpty()) {
        rankDB.insert(ranks);
        ranks.clear();
    }

    LOG.debug("SERP rescan : done, duration = {}",
            DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - _start));
}