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:de.tudarmstadt.ukp.dkpro.tc.svmhmm.writer.SVMHMMDataWriterTest.java

@Test
public void testMetDataFeatures() throws Exception {
    String longText = "rO0ABXNyABNqYXZhLnV0aWwuQXJyYXlMaXN0eIHSHZnHYZ0DAAFJAARzaXpleHAAAAAedwQAAAAedAABT3EAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJ4";

    featureStore = new SparseFeatureStore();
    Feature f1 = new Feature(OriginalTextHolderFeatureExtractor.ORIGINAL_TEXT, "multi line \n text");
    Feature f2 = new Feature(SVMHMMDataWriter.META_DATA_FEATURE_PREFIX + "someFeature", longText);

    Instance instance = new Instance(Arrays.asList(f1, f2), "outcome");
    featureStore.addInstance(instance);/* w  ww. jav  a  2 s  .c o m*/

    SVMHMMDataWriter svmhmmDataWriter = new SVMHMMDataWriter();
    System.out.println(featureStore.getNumberOfInstances());
    svmhmmDataWriter.write(temporaryFolder.getRoot(), featureStore, false, null, false);

    File featureVectorsFile = new File(temporaryFolder.getRoot(), "feature-vectors.txt");
    List<String> lines = IOUtils.readLines(new FileInputStream(featureVectorsFile));
    System.out.println(lines);

    assertEquals("outcome",
            SVMHMMUtils.extractOutcomeLabelsFromFeatureVectorFiles(featureVectorsFile).iterator().next());

    assertEquals(Integer.valueOf(0),
            SVMHMMUtils.extractOriginalSequenceIDs(featureVectorsFile).iterator().next());

    SortedMap<String, String> metaDataFeatures = SVMHMMUtils.extractMetaDataFeatures(featureVectorsFile).get(0);

    assertTrue(metaDataFeatures.containsKey(SVMHMMDataWriter.META_DATA_FEATURE_PREFIX + "someFeature"));
    assertEquals(longText, metaDataFeatures.get(SVMHMMDataWriter.META_DATA_FEATURE_PREFIX + "someFeature"));

}

From source file:com.aqnote.app.wifianalyzer.vendor.model.VendorService.java

public SortedMap<String, List<String>> findAll() {
    SortedMap<String, List<String>> results = new TreeMap<>();
    Database database = MainContext.INSTANCE.getDatabase();
    List<VendorData> vendorDatas = database.findAll();
    for (VendorData vendorData : vendorDatas) {
        String key = VendorNameUtils.cleanVendorName(vendorData.getName());
        List<String> macs = results.get(key);
        if (macs == null) {
            macs = new ArrayList<>();
            results.put(key, macs);/* www. java 2s. c  o m*/
        }
        macs.add(vendorData.getMac());
        Collections.sort(macs);
    }
    return results;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.F1ScoreTableAggregator.java

public static void evaluatePredictionsFoldersDomain(File masterFolder, String folderContains) throws Exception {
    SortedMap<String, SortedMap<String, String>> featureSetsResults = new TreeMap<>();

    File[] foldersFeatureSets = masterFolder.listFiles(EvalHelper.DIRECTORY_FILTER);

    for (File folderFeatureSet : foldersFeatureSets) {
        String[] split = folderFeatureSet.getName().split("_");
        String featureSet = split[0];
        String paramE = split[1];
        String paramT = split[2];

        if ("e0".equals(paramE) && "t1".equals(paramT)) {

            Map<String, File> foldersData = EvalHelper.listSubFoldersAndRemoveUUID(folderFeatureSet);
            for (Map.Entry<String, File> folderData : foldersData.entrySet()) {

                String data = folderData.getKey();

                if (data.contains(folderContains)) {
                    File resultSummary = new File(folderData.getValue(), "resultSummary.txt");

                    List<String> values = extractValues(resultSummary);
                    String macroF1 = values.get(0);

                    if (!featureSetsResults.containsKey(featureSet)) {
                        featureSetsResults.put(featureSet, new TreeMap<String, String>());
                    }/*  w w w  . j a va2 s  . com*/

                    String domainName = data.split("_")[2];

                    featureSetsResults.get(featureSet).put(domainName, macroF1);
                }
            }
        }
    }

    // print results
    int rows = featureSetsResults.values().iterator().next().size();
    System.out.printf("\t");

    for (String featureSet : featureSetsResults.keySet()) {
        System.out.printf("%s\t", featureSet);
    }
    System.out.println();
    for (int i = 0; i < rows; i++) {
        //            Set<String> keySet = featureSetsResults.values().iterator().next().keySet();
        SortedMap<String, String> firstColumn = featureSetsResults.values().iterator().next();
        List<String> keys = new ArrayList<>(firstColumn.keySet());
        System.out.printf("%s\t", keys.get(i));

        for (SortedMap<String, String> values : featureSetsResults.values()) {
            System.out.printf("%s\t", values.get(keys.get(i)));
        }

        System.out.println();
    }
}

From source file:lti.oauth.OAuthFilter.java

@Override
protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain fc)
        throws ServletException, IOException {

    LaunchRequest launchRequest = new LaunchRequest(req.getParameterMap());
    SortedMap<String, String> alphaSortedMap = launchRequest.toSortedMap();
    String signature = alphaSortedMap.remove(OAuthUtil.SIGNATURE_PARAM);

    String calculatedSignature = null;
    try {//from w ww.j ava  2  s .co  m
        calculatedSignature = new OAuthMessageSigner().sign(secret,
                OAuthUtil.mapToJava(alphaSortedMap.get(OAuthUtil.SIGNATURE_METHOD_PARAM)), "POST",
                req.getRequestURL().toString(), alphaSortedMap);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        res.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value());
        return;
    }

    if (!signature.equals(calculatedSignature)) {
        // try again with http
        String recalculatedSignature = null;

        if (StringUtils.startsWithIgnoreCase(req.getRequestURL().toString(), "https:")) {
            String url = StringUtils.replaceOnce(req.getRequestURL().toString(), "https:", "http:");
            try {
                recalculatedSignature = new OAuthMessageSigner().sign(secret,
                        OAuthUtil.mapToJava(alphaSortedMap.get(OAuthUtil.SIGNATURE_METHOD_PARAM)), "POST", url,
                        alphaSortedMap);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                res.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value());
                return;
            }
        }

        if (!signature.equals(recalculatedSignature)) {
            res.sendError(HttpStatus.UNAUTHORIZED.value());
            return;
        }
    }

    fc.doFilter(req, res);
}

From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexedRegion.java

public static void putIndexMultTable(IndexedRegion r, IndexSpecification indexSpec, byte[] row,
        SortedMap<byte[], byte[]> columnValues, Integer lockId, Result oldResult) throws IOException {
    updateTimes++;/*from  w  w  w .j a  va 2s  .  c o m*/
    HashSet<String> IndexColumns = new HashSet<String>();
    Put lastPut = null;

    if (r.orgTable == null) {
        HTableDescriptor td = r.getTableDesc();
        r.orgTable = new HTable(r.conf, td.getName());
        r.orgTable.setWriteBufferSize(1000 * 1000 * 20);
    }

    for (byte[] column : indexSpec.getIndexedColumns()) {
        IndexColumns.add(new String(column));
    }
    boolean hasIndex = false;

    for (byte[] column : columnValues.keySet())
        if (IndexColumns.contains(new String(column))) {
            if (oldResult != null && oldResult.raw() != null && oldResult.list() != null) {
                if (oldResult.getValue(column).equals(columnValues.get(column))) {
                    continue;
                }
                SortedMap<byte[], byte[]> oldColumnValues = r.convertToValueMap(oldResult);
                Get get = new Get(indexSpec.getKeyGenerator().createIndexKey(row, oldColumnValues));

                get.addColumn(column);
                try {
                    if (r.isClosed()) {
                        oldResult = r.orgTable.get(get);
                    } else
                        oldResult = r.superGet(get, lockId);
                    if (oldResult != null && oldResult.raw() != null && oldResult.list() != null) {
                        Delete delete = new Delete(get.getRow());
                        r.getIndexTable(indexSpec).delete(delete);
                        r.getCCTTable(indexSpec).delete(delete);
                    }

                    deletTimes++;
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

            }
        }

    for (byte[] column : columnValues.keySet())
        if (IndexColumns.contains(new String(column))) {

            hasIndex = true;
            Get oldGet = new Get(row);

            HColumnDescriptor dess[] = r.getTableDesc().getColumnFamilies();
            for (HColumnDescriptor des : dess) {
                if (columnValues.get(des.getName()) == null) {
                    oldGet.addColumn(des.getName());
                }
            }
            // oldGet.addColumn(column);
            oldResult = null;
            if (r.isClosed()) {
                oldResult = r.orgTable.get(oldGet);
            } else
                oldResult = r.superGet(oldGet, lockId);
            if (oldResult != null && oldResult.raw() != null && oldResult.list() != null) {
                for (KeyValue kv : oldResult.list()) {
                    if (columnValues.get(kv.getColumn()) == null)
                        columnValues.put(kv.getColumn(), kv.getValue());
                }
            }
        }
    if (!hasIndex) {
        Get oldGet = new Get(row);
        oldGet.addColumn(indexSpec.getIndexedColumns()[0]);
        oldResult = null;
        if (r.isClosed()) {
            oldResult = r.orgTable.get(oldGet);
        } else
            oldResult = r.superGet(oldGet, lockId);
        if (!(oldResult != null && oldResult.raw() != null && oldResult.list() != null)) {
            return;
        } else {
            SortedMap<byte[], byte[]> oldColumnValues = r.convertToValueMap(oldResult);
            for (KeyValue kv : oldResult.list()) {
                columnValues.put(kv.getColumn(), kv.getValue());
            }
        }

    }
    lastPut = IndexMaintenanceUtils.createIndexUpdate(indexSpec, row, columnValues);

    r.getIndexTable(indexSpec).put(lastPut);
    HTable cct = r.getCCTTable(indexSpec);
    cct.put(IndexMaintenanceUtils.createCCTUpdate(indexSpec, row, columnValues, r.indexTableDescriptor));

}

From source file:com.aurel.track.admin.customize.localize.LocalizeBL.java

/**
 * Update the resources based on the properties
 * @param properties//  w ww. j a va2 s  .  c o  m
 * @param strLocale
 * @param overwrite whether to overwrite the edited resources
 * @param withPrimaryKey whether the used to be BoxResources are imported or the ApplicationResources 
 */
static synchronized void uploadResources(Properties properties, String strLocale, boolean overwrite,
        boolean withPrimaryKey, boolean initBoxResources) {
    List<TLocalizedResourcesBean> resourceBeans = getResourcesForLocale(strLocale, withPrimaryKey);
    SortedMap<String, List<TLocalizedResourcesBean>> existingLabels = new TreeMap<String, List<TLocalizedResourcesBean>>();
    for (TLocalizedResourcesBean localizedResourcesBean : resourceBeans) {
        String key = localizedResourcesBean.getFieldName();
        if (withPrimaryKey) {
            if (key.startsWith(LocalizationKeyPrefixes.FIELD_LABEL_KEY_PREFIX)
                    || key.startsWith(LocalizationKeyPrefixes.FIELD_TOOLTIP_KEY_PREFIX)) {
                key += ".";
            }
            key = key + localizedResourcesBean.getPrimaryKeyValue();
        }
        List<TLocalizedResourcesBean> localizedResources = existingLabels.get(key);
        if (localizedResources == null) {
            localizedResources = new LinkedList<TLocalizedResourcesBean>();
            existingLabels.put(key, localizedResources);
        }
        localizedResources.add(localizedResourcesBean);
    }
    Enumeration propertyNames = properties.keys();
    Connection connection = null;
    try {
        connection = Transaction.begin();
        connection.setAutoCommit(false);
        while (propertyNames.hasMoreElements()) {
            String key = (String) propertyNames.nextElement();
            String localizedText = LocalizeBL.correctString(properties.getProperty(key));
            Integer primaryKey = null;
            String fieldName = null;
            if (withPrimaryKey) {
                int primaryKeyIndex = key.lastIndexOf(".");
                if (primaryKeyIndex != -1) {
                    try {
                        primaryKey = Integer.valueOf(key.substring(primaryKeyIndex + 1));
                    } catch (Exception e) {
                        LOGGER.warn("The last part after . can't be converted to integer " + e.getMessage());
                        LOGGER.debug(ExceptionUtils.getStackTrace(e));
                    }
                    fieldName = key.substring(0, primaryKeyIndex + 1);
                    if (fieldName.startsWith(LocalizationKeyPrefixes.FIELD_LABEL_KEY_PREFIX)
                            || fieldName.startsWith(LocalizationKeyPrefixes.FIELD_TOOLTIP_KEY_PREFIX)) {
                        //do not have . at the end (legacy)
                        fieldName = fieldName.substring(0, fieldName.length() - 1);
                    }
                }
            } else {
                fieldName = key;
            }
            List<TLocalizedResourcesBean> localizedResources = existingLabels.get(key);
            if (localizedResources != null && localizedResources.size() > 1) {
                //remove all duplicates (as a consequence of previous erroneous imports)
                localizedResourcesDAO.deleteLocalizedResourcesForFieldNameAndKeyAndLocale(fieldName, primaryKey,
                        strLocale);
                localizedResources = null;
            }
            if (localizedResources == null || localizedResources.isEmpty()) {
                //new resource
                TLocalizedResourcesBean localizedResourcesBean = new TLocalizedResourcesBean();
                localizedResourcesBean.setFieldName(fieldName);
                localizedResourcesBean.setPrimaryKeyValue(primaryKey);
                localizedResourcesBean.setLocalizedText(localizedText);
                localizedResourcesBean.setLocale(strLocale);
                localizedResourcesDAO.insert(localizedResourcesBean);
            } else {
                //existing resource
                if (localizedResources.size() == 1) {
                    TLocalizedResourcesBean localizedResourcesBean = localizedResources.get(0);
                    if (EqualUtils.notEqual(localizedText, localizedResourcesBean
                            .getLocalizedText()) /*&& locale.equals(localizedResourcesBean.getLocale())*/) {
                        //text changed locally by the customer
                        boolean textChanged = localizedResourcesBean.getTextChangedBool();
                        if ((textChanged == false && !initBoxResources) || (textChanged && overwrite)) {
                            localizedResourcesBean.setLocalizedText(localizedText);
                            localizedResourcesDAO.save(localizedResourcesBean);
                        }
                    } else {
                    }
                }
            }
        }
        Transaction.commit(connection);
        if (!connection.isClosed()) {
            connection.close();
        }
    } catch (Exception e) {
        LOGGER.error("Problem filling locales: " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        if (connection != null) {
            Transaction.safeRollback(connection);
        }
    }
    //delete the existing ones not found in the properties
    Locale locale;
    if (strLocale != null) {
        locale = LocaleHandler.getLocaleFromString(strLocale);
    } else {
        locale = Locale.getDefault();
    }
    if (withPrimaryKey) {
        //not sure that all is needed but to be sure we do not miss imported localizations
        LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_ISSUETYPE, locale);
        LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_STATE, locale);
        LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_PRIORITY, locale);
        LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_SEVERITY, locale);
    }
    ResourceBundle.clearCache();
}

From source file:com.amazonaws.services.sns.util.SignatureChecker.java

protected String stringToSign(SortedMap<String, String> signables) {
    // each key and value is followed by a newline
    StringBuilder sb = new StringBuilder();
    for (String k : signables.keySet()) {
        sb.append(k).append("\n");
        sb.append(signables.get(k)).append("\n");
    }// w  ww. j a v  a2  s  .  co m
    String result = sb.toString();
    return result;
}

From source file:org.kuali.coeus.common.framework.custom.CustomDataHelperBase.java

protected void addToGroup(String groupName, SortedMap<String, List> customAttributeGroups,
        Entry<String, CustomAttributeDocument> customAttributeDocument) {
    List<CustomAttributeDocument> customAttributeDocumentList = customAttributeGroups.get(groupName);
    if (customAttributeDocumentList == null) {
        customAttributeDocumentList = new ArrayList<CustomAttributeDocument>();
        customAttributeGroups.put(groupName, customAttributeDocumentList);
    }// w w  w.  j  a va  2 s .  c o  m
    customAttributeDocumentList.add(customAttributeDocument.getValue());
}

From source file:com.github.fauu.natrank.service.MatchServiceImpl.java

@Override
public Map<NotableMatchCategory, List<Match>> findNotableMatchesByTeamName(String name)
        throws DataAccessException {
    List<NotableMatch> notableMatches = notableMatchRepository.findByTeam(teamRepository.findByName(name));
    List<NotableMatchCategory> notableMatchCategories = notableMatchCategoryRepository.findAll();
    SortedMap<NotableMatchCategory, List<Match>> notableMatchMap = new TreeMap<>();

    for (NotableMatchCategory category : notableMatchCategories) {
        notableMatchMap.put(category, new LinkedList<Match>());
    }//from w  ww .  j a v  a  2  s . co  m

    for (NotableMatch notableMatch : notableMatches) {
        notableMatchMap.get(notableMatch.getCategory()).add(notableMatch.getMatch());
    }

    return notableMatchMap;
}

From source file:org.bibsonomy.webapp.filters.ContentNegotiationFilter.java

/**
 * Supports content negotiation using the HTTP accept header.
 *  //ww  w .  j a v a2 s . com
 * Extracts the preferred response format from the accept header and returns
 * the corresponding URL path for the webapp. Only the format with the 
 * highest priority is regarded. Thus, this method is much stricter than
 * {@link HeaderUtils#getResponseFormat(String, int)}. 
 * <br/> 
 * If no matching URL path could be found, <code>null</code> is returned.
 *   
 * 
 * @param acceptHeader - the "Accept" header of the HTTP request.
 * @return The 
 */
private String getResponseFormat(final String acceptHeader) {
    if (!present(acceptHeader))
        return null;
    /*
     * extract ordered list of preferred types
     */
    final SortedMap<Double, Vector<String>> preferredTypes = org.bibsonomy.rest.utils.HeaderUtils
            .getPreferredTypes(acceptHeader);
    /*
     * extract highest ranked formats
     */
    final Vector<String> firstFormats = preferredTypes.get(preferredTypes.firstKey());
    /*
     * return best match
     */
    return FORMAT_MAPPING.get(firstFormats.firstElement());
}