Example usage for java.util SortedMap get

List of usage examples for java.util SortedMap get

Introduction

In this page you can find the example usage for java.util SortedMap get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.alfresco.extension.bulkimport.source.fs.DirectoryAnalyser.java

private final NavigableSet<FilesystemBulkImportItemVersion> constructImportItemVersions(
        final SortedMap<BigDecimal, Pair<File, File>> itemVersions) throws InterruptedException {
    // PRECONDITIONS
    if (itemVersions == null)
        throw new IllegalArgumentException("itemVersions cannot be null.");
    if (itemVersions.size() <= 0)
        throw new IllegalArgumentException("itemVersions cannot be empty.");

    // Body/* w w w . j a v  a 2 s  . com*/
    final NavigableSet<FilesystemBulkImportItemVersion> result = new TreeSet<>();

    for (final BigDecimal versionNumber : itemVersions.keySet()) {
        if (importStatus.isStopping() || Thread.currentThread().isInterrupted())
            throw new InterruptedException(
                    Thread.currentThread().getName() + " was interrupted. Terminating early.");

        final Pair<File, File> contentAndMetadataFiles = itemVersions.get(versionNumber);
        final FilesystemBulkImportItemVersion version = new FilesystemBulkImportItemVersion(serviceRegistry,
                configuredContentStore, metadataLoader, versionNumber, contentAndMetadataFiles.getFirst(),
                contentAndMetadataFiles.getSecond());

        result.add(version);
    }

    return (result);
}

From source file:de.appsolve.padelcampus.controller.events.EventsController.java

@RequestMapping(method = GET, value = "event/{eventId}/score")
public ModelAndView getScore(@PathVariable("eventId") Long eventId, HttpServletRequest request) {
    Event event = eventDAO.findByIdFetchWithParticipantsAndGames(eventId);
    if (event == null) {
        throw new ResourceNotFoundException();
    }/*  w ww. j av  a 2  s  . c  o  m*/
    SortedMap<Community, ScoreEntry> communityScoreMap = new TreeMap<>();
    Set<Participant> teams = new HashSet<>();
    event.getGames().forEach(game -> game.getParticipants().forEach(participant -> {
        if (participant instanceof Team) {
            teams.add(participant);
        }
    }));
    List<ScoreEntry> scores = rankingUtil.getScores(teams, event.getGames());
    for (ScoreEntry scoreEntry : scores) {
        Team team = (Team) scoreEntry.getParticipant();
        ScoreEntry communityScore = communityScoreMap.get(team.getCommunity());
        if (communityScore == null) {
            communityScore = new ScoreEntry();
        }
        communityScore.add(scoreEntry);
        communityScoreMap.put(team.getCommunity(), communityScore);
    }
    SortedMap<Community, ScoreEntry> communityScoreMapSorted = SortUtil.sortMap(communityScoreMap, true);
    ModelAndView scoreView = new ModelAndView("events/communityroundrobin/score");
    scoreView.addObject("Model", event);
    scoreView.addObject("CommunityScoreMap", communityScoreMapSorted);
    return scoreView;
}

From source file:com.googlecode.jdeltasync.DeltaSyncClient.java

private void addCommand(SortedMap<Integer, List<Command>> commandMap, Element element, Command command) {
    int index;/*from ww w .j a  v  a2  s  . c o  m*/
    if (element instanceof DeferredNode) {
        index = ((DeferredNode) element).getNodeIndex();
    } else {
        index = -1;
    }
    List<Command> commandsForIndex = commandMap.get(index);
    if (commandsForIndex == null) {
        commandsForIndex = new ArrayList<Command>();
        commandMap.put(index, commandsForIndex);
    }
    commandsForIndex.add(command);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ViewHomepageDA.java

public ActionForward listStudents(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    final SortedMap<Degree, SortedSet<Homepage>> homepages = new TreeMap<Degree, SortedSet<Homepage>>(
            Degree.COMPARATOR_BY_DEGREE_TYPE_AND_NAME_AND_ID);
    for (final Registration registration : rootDomainObject.getRegistrationsSet()) {
        final StudentCurricularPlan studentCurricularPlan = registration.getActiveStudentCurricularPlan();
        if (studentCurricularPlan != null) {
            final DegreeCurricularPlan degreeCurricularPlan = studentCurricularPlan.getDegreeCurricularPlan();
            final Degree degree = degreeCurricularPlan.getDegree();
            final Person person = registration.getPerson();
            final SortedSet<Homepage> degreeHomepages;
            if (homepages.containsKey(degree)) {
                degreeHomepages = homepages.get(degree);
            } else {
                degreeHomepages = new TreeSet<Homepage>(Homepage.HOMEPAGE_COMPARATOR_BY_NAME);
                homepages.put(degree, degreeHomepages);
            }/*from   w  ww .  jav  a 2s  .c  om*/
            final Homepage homepage = person.getHomepage();
            if (homepage != null && homepage.getActivated().booleanValue()) {
                degreeHomepages.add(homepage);
            }
        }
    }
    request.setAttribute("homepages", homepages);

    final String selectedPage = request.getParameter("selectedPage");
    if (selectedPage != null) {
        request.setAttribute("selectedPage", selectedPage);
    }

    return mapping.findForward("list-homepages-students");
}

From source file:org.springframework.security.oauth.provider.filter.CoreOAuthProviderSupport.java

/**
 * Loads the significant parameters (name-to-value map) that are to be used to calculate the signature base string.
 * The parameters will be encoded, per the spec section 9.1.
 *
 * @param request The request.//from   ww  w .  j  a  v a  2s . c o  m
 * @return The significan parameters.
 */
protected SortedMap<String, SortedSet<String>> loadSignificantParametersForSignatureBaseString(
        HttpServletRequest request) {
    //first collect the relevant parameters...
    SortedMap<String, SortedSet<String>> significantParameters = new TreeMap<String, SortedSet<String>>();
    //first pull from the request...
    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        String[] values = request.getParameterValues(parameterName);
        if (values == null) {
            values = new String[] { "" };
        }

        parameterName = oauthEncode(parameterName);
        for (String parameterValue : values) {
            if (parameterValue == null) {
                parameterValue = "";
            }

            parameterValue = oauthEncode(parameterValue);
            SortedSet<String> significantValues = significantParameters.get(parameterName);
            if (significantValues == null) {
                significantValues = new TreeSet<String>();
                significantParameters.put(parameterName, significantValues);
            }
            significantValues.add(parameterValue);
        }
    }

    //then take into account the header parameter values...
    Map<String, String> oauthParams = parseParameters(request);
    oauthParams.remove("realm"); //remove the realm
    Set<String> parsedParams = oauthParams.keySet();
    for (String parameterName : parsedParams) {
        String parameterValue = oauthParams.get(parameterName);
        if (parameterValue == null) {
            parameterValue = "";
        }

        parameterName = oauthEncode(parameterName);
        parameterValue = oauthEncode(parameterValue);
        SortedSet<String> significantValues = significantParameters.get(parameterName);
        if (significantValues == null) {
            significantValues = new TreeSet<String>();
            significantParameters.put(parameterName, significantValues);
        }
        significantValues.add(parameterValue);
    }

    //remove the oauth signature parameter value.
    significantParameters.remove(OAuthConsumerParameter.oauth_signature.toString());
    return significantParameters;
}

From source file:org.apache.hadoop.hive.ql.MetaStoreDumpUtility.java

public static void setupMetaStoreTableColumnStatsFor30TBTPCDSWorkload(HiveConf conf, String tmpBaseDir) {
    Connection conn = null;/*  w ww.ja  v a 2s.  c  o m*/

    try {
        Properties props = new Properties(); // connection properties
        props.put("user", conf.get("javax.jdo.option.ConnectionUserName"));
        props.put("password", conf.get("javax.jdo.option.ConnectionPassword"));
        String url = conf.get("javax.jdo.option.ConnectionURL");
        conn = DriverManager.getConnection(url, props);
        ResultSet rs = null;
        Statement s = conn.createStatement();

        if (LOG.isDebugEnabled()) {
            LOG.debug("Connected to metastore database ");
        }

        String mdbPath = HiveTestEnvSetup.HIVE_ROOT + "/data/files/tpcds-perf/metastore_export/";

        // Setup the table column stats
        BufferedReader br = new BufferedReader(new FileReader(new File(
                HiveTestEnvSetup.HIVE_ROOT + "/metastore/scripts/upgrade/derby/022-HIVE-11107.derby.sql")));
        String command;

        s.execute("DROP TABLE APP.TABLE_PARAMS");
        s.execute("DROP TABLE APP.TAB_COL_STATS");
        // Create the column stats table
        while ((command = br.readLine()) != null) {
            if (!command.endsWith(";")) {
                continue;
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("Going to run command : " + command);
            }
            PreparedStatement psCommand = conn.prepareStatement(command.substring(0, command.length() - 1));
            psCommand.execute();
            psCommand.close();
            if (LOG.isDebugEnabled()) {
                LOG.debug("successfully completed " + command);
            }
        }
        br.close();

        java.nio.file.Path tabColStatsCsv = FileSystems.getDefault().getPath(mdbPath, "csv",
                "TAB_COL_STATS.txt.bz2");
        java.nio.file.Path tabParamsCsv = FileSystems.getDefault().getPath(mdbPath, "csv",
                "TABLE_PARAMS.txt.bz2");

        // Set up the foreign key constraints properly in the TAB_COL_STATS data
        java.nio.file.Path tmpFileLoc1 = FileSystems.getDefault().getPath(tmpBaseDir, "TAB_COL_STATS.txt");
        java.nio.file.Path tmpFileLoc2 = FileSystems.getDefault().getPath(tmpBaseDir, "TABLE_PARAMS.txt");

        class MyComp implements Comparator<String> {
            @Override
            public int compare(String str1, String str2) {
                if (str2.length() != str1.length()) {
                    return str2.length() - str1.length();
                }
                return str1.compareTo(str2);
            }
        }

        final SortedMap<String, Integer> tableNameToID = new TreeMap<String, Integer>(new MyComp());

        rs = s.executeQuery("SELECT * FROM APP.TBLS");
        while (rs.next()) {
            String tblName = rs.getString("TBL_NAME");
            Integer tblId = rs.getInt("TBL_ID");
            tableNameToID.put(tblName, tblId);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Resultset : " + tblName + " | " + tblId);
            }
        }

        final Map<String, Map<String, String>> data = new HashMap<>();
        rs = s.executeQuery("select TBLS.TBL_NAME, a.COLUMN_NAME, a.TYPE_NAME from  "
                + "(select COLUMN_NAME, TYPE_NAME, SDS.SD_ID from APP.COLUMNS_V2 join APP.SDS on SDS.CD_ID = COLUMNS_V2.CD_ID) a"
                + " join APP.TBLS on  TBLS.SD_ID = a.SD_ID");
        while (rs.next()) {
            String tblName = rs.getString(1);
            String colName = rs.getString(2);
            String typeName = rs.getString(3);
            Map<String, String> cols = data.get(tblName);
            if (null == cols) {
                cols = new HashMap<>();
            }
            cols.put(colName, typeName);
            data.put(tblName, cols);
        }

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                new BZip2CompressorInputStream(Files.newInputStream(tabColStatsCsv, StandardOpenOption.READ))));

        Stream<String> replaced = reader.lines().parallel().map(str -> {
            String[] splits = str.split(",");
            String tblName = splits[0];
            String colName = splits[1];
            Integer tblID = tableNameToID.get(tblName);
            StringBuilder sb = new StringBuilder(
                    "default@" + tblName + "@" + colName + "@" + data.get(tblName).get(colName) + "@");
            for (int i = 2; i < splits.length; i++) {
                sb.append(splits[i] + "@");
            }
            // Add tbl_id and empty bitvector
            return sb.append(tblID).append("@").toString();
        });

        Files.write(tmpFileLoc1, (Iterable<String>) replaced::iterator);
        replaced.close();
        reader.close();

        BufferedReader reader2 = new BufferedReader(new InputStreamReader(
                new BZip2CompressorInputStream(Files.newInputStream(tabParamsCsv, StandardOpenOption.READ))));
        final Map<String, String> colStats = new ConcurrentHashMap<>();
        Stream<String> replacedStream = reader2.lines().parallel().map(str -> {
            String[] splits = str.split("_@");
            String tblName = splits[0];
            Integer tblId = tableNameToID.get(tblName);
            Map<String, String> cols = data.get(tblName);
            StringBuilder sb = new StringBuilder();
            sb.append("{\"COLUMN_STATS\":{");
            for (String colName : cols.keySet()) {
                sb.append("\"" + colName + "\":\"true\",");
            }
            sb.append("},\"BASIC_STATS\":\"true\"}");
            colStats.put(tblId.toString(), sb.toString());

            return tblId.toString() + "@" + splits[1];
        });

        Files.write(tmpFileLoc2, (Iterable<String>) replacedStream::iterator);
        Files.write(tmpFileLoc2,
                (Iterable<String>) colStats.entrySet().stream()
                        .map(map -> map.getKey() + "@COLUMN_STATS_ACCURATE@" + map.getValue())::iterator,
                StandardOpenOption.APPEND);

        replacedStream.close();
        reader2.close();
        // Load the column stats and table params with 30 TB scale
        String importStatement1 = "CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE(null, '" + "TAB_COL_STATS" + "', '"
                + tmpFileLoc1.toAbsolutePath().toString() + "', '@', null, 'UTF-8', 1)";
        String importStatement2 = "CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE(null, '" + "TABLE_PARAMS" + "', '"
                + tmpFileLoc2.toAbsolutePath().toString() + "', '@', null, 'UTF-8', 1)";

        PreparedStatement psImport1 = conn.prepareStatement(importStatement1);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Going to execute : " + importStatement1);
        }
        psImport1.execute();
        psImport1.close();
        if (LOG.isDebugEnabled()) {
            LOG.debug("successfully completed " + importStatement1);
        }
        PreparedStatement psImport2 = conn.prepareStatement(importStatement2);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Going to execute : " + importStatement2);
        }
        psImport2.execute();
        psImport2.close();
        if (LOG.isDebugEnabled()) {
            LOG.debug("successfully completed " + importStatement2);
        }

        s.execute("ALTER TABLE APP.TAB_COL_STATS ADD COLUMN CAT_NAME VARCHAR(256)");
        s.execute("update APP.TAB_COL_STATS set CAT_NAME = '" + Warehouse.DEFAULT_CATALOG_NAME + "'");

        s.close();

        conn.close();

    } catch (Exception e) {
        throw new RuntimeException("error while loading tpcds metastore dump", e);
    }
}

From source file:org.springframework.security.oauth.provider.CoreOAuthProviderSupport.java

/**
 * Loads the significant parameters (name-to-value map) that are to be used to calculate the signature base string.
 * The parameters will be encoded, per the spec section 9.1.
 *
 * @param request The request.//w w w. j  a v a2  s  . c o  m
 * @return The significan parameters.
 */
protected SortedMap<String, SortedSet<String>> loadSignificantParametersForSignatureBaseString(
        HttpServletRequest request) {
    //first collect the relevant parameters...
    SortedMap<String, SortedSet<String>> significantParameters = new TreeMap<String, SortedSet<String>>();
    //first pull from the request...
    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        String[] values = request.getParameterValues(parameterName);
        if (values == null) {
            values = new String[] { "" };
        }

        for (String parameterValue : values) {
            if (parameterValue == null) {
                parameterValue = "";
            }

            parameterName = oauthEncode(parameterName);
            parameterValue = oauthEncode(parameterValue);
            SortedSet<String> significantValues = significantParameters.get(parameterName);
            if (significantValues == null) {
                significantValues = new TreeSet<String>();
                significantParameters.put(parameterName, significantValues);
            }
            significantValues.add(parameterValue);
        }
    }

    //then take into account the header parameter values...
    Map<String, String> oauthParams = parseParameters(request);
    oauthParams.remove("realm"); //remove the realm
    Set<String> parsedParams = oauthParams.keySet();
    for (String parameterName : parsedParams) {
        String parameterValue = oauthParams.get(parameterName);
        if (parameterValue == null) {
            parameterValue = "";
        }

        parameterName = oauthEncode(parameterName);
        parameterValue = oauthEncode(parameterValue);
        SortedSet<String> significantValues = significantParameters.get(parameterName);
        if (significantValues == null) {
            significantValues = new TreeSet<String>();
            significantParameters.put(parameterName, significantValues);
        }
        significantValues.add(parameterValue);
    }

    //remove the oauth signature parameter value.
    significantParameters.remove(OAuthConsumerParameter.oauth_signature.toString());
    return significantParameters;
}

From source file:org.apache.ctakes.ytex.kernel.metric.ConceptSimilarityServiceImpl.java

/**
 * convert the list of tuis into a bitset
 * //w w  w  .ja  v  a  2  s  .  c  om
 * @param tuis
 * @param mapTuiIndex
 * @return
 */
private BitSet tuiListToBitset(Set<String> tuis, SortedMap<String, Integer> mapTuiIndex) {
    BitSet bs = new BitSet(mapTuiIndex.size());
    for (String tui : tuis) {
        bs.set(mapTuiIndex.get(tui));
    }
    return bs;
}

From source file:org.codehaus.mojo.license.DefaultThirdPartyTool.java

protected void handleStuff(Properties customMappings, SortedMap<String, MavenProject> artifactCache) {
    // Store any custom mappings that are not used by this project
    List<String> unusedDependencies = new ArrayList<String>();

    // If the custom mapping file contains GAV entries with type+classifier, remove type+classifier
    // A simple GAV is enough to figure out appropriate licensing
    Map<String, String> migrateKeys = migrateCustomMappingKeys(customMappings.stringPropertyNames());
    for (String id : migrateKeys.keySet()) {
        String migratedId = migrateKeys.get(id);

        MavenProject project = artifactCache.get(migratedId);
        if (project == null) {
            // Now we are sure this is an unused dependency
            // Add this GAV as one that we don't care about for this project
            unusedDependencies.add(id);//from   w w w.j a v  a2 s .co  m
        } else {
            if (!id.equals(migratedId)) {

                // migrates id to migratedId
                getLogger().info("Migrates [" + id + "] to [" + migratedId + "] in the custom mapping file.");
                Object value = customMappings.get(id);
                customMappings.remove(id);
                customMappings.put(migratedId, value);
            }
        }
    }

    if (!unusedDependencies.isEmpty()) {
        // there are some unused dependencies in the custom mappings file, remove them
        for (String id : unusedDependencies) {
            getLogger().debug("dependency [" + id + "] does not exist in this project");
            // Remove it from the custom mappings file since we don't care about it for this project
            customMappings.remove(id);
        }
    }

}

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>
 * /* w  w w  . jav  a 2s . com*/
 * @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);
        }
    }

}