Example usage for java.util HashMap entrySet

List of usage examples for java.util HashMap entrySet

Introduction

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

Prototype

Set entrySet

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

Click Source Link

Document

Holds cached entrySet().

Usage

From source file:com.fujitsu.dc.client.http.RestAdapter.java

/**
 * This is the PUT method that receives the response body.
 * @param url Target Request URL//  ww w .j ava 2  s  . com
 * @param map Hash map of Request Header
 * @return DcResponse object
 * @throws DaoException Exception thrown
 */
public DcResponse put(String url, HashMap<String, String> map) throws DaoException {
    HttpUriRequest req = new DcRequestBuilder().url(url).method(HttpMethods.PUT).token(getToken())
            .defaultHeaders(this.accessor.getDefaultHeaders()).build();
    for (Map.Entry<String, String> entry : map.entrySet()) {
        req.setHeader((String) entry.getKey(), (String) entry.getValue());
    }
    return this.request(req);
}

From source file:com.cloudbees.api.BeesClientBase.java

public String getRequestURL(String method, Map<String, String> methodParams, boolean asActionParam)
        throws Exception {
    HashMap<String, String> urlParams = getDefaultParameters();

    StringBuilder requestURL = getApiUrl(asActionParam ? null : method);
    requestURL.append("?");

    for (Map.Entry<String, String> entry : methodParams.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        urlParams.put(key, value);/*from   www  .ja v  a2s .c om*/
    }

    if (asActionParam)
        urlParams.put("action", method);

    String signature = calculateSignature(urlParams);
    Iterator<Map.Entry<String, String>> it = urlParams.entrySet().iterator();
    for (int i = 0; it.hasNext(); i++) {
        Map.Entry<String, String> entry = it.next();
        String key = entry.getKey();
        String value = entry.getValue();
        if (i > 0)
            requestURL.append("&");
        requestURL.append(URLEncoder.encode(key, "UTF-8"));
        requestURL.append("=");
        requestURL.append(URLEncoder.encode(value, "UTF-8"));
    }

    requestURL.append("&");
    requestURL.append("sig");
    requestURL.append("=");
    requestURL.append(signature);

    return requestURL.toString();
}

From source file:cc.aileron.wsgi.request.WsgiRequestParameterFactoryImpl.java

/**
 * @param request//from  ww  w . j a v a2s .  c o m
 * @param conv
 * @param upload
 * @return map
 * @throws FileUploadException
 */
private HashMap<String, Object> initMap(final Charset characterEncoding, final HttpServletRequest request,
        final ServletFileUpload upload) throws FileUploadException {
    final List<FileItem> params = Cast.<List<FileItem>>cast(upload.parseRequest(request));
    final HashMap<String, Object> result = new HashMap<String, Object>();
    final HashMap<String, List<Object>> tmp = new HashMap<String, List<Object>>();
    for (final FileItem item : params) {
        final String key = item.getFieldName();
        final List<Object> vals;
        {
            List<Object> t = tmp.get(key);
            if (t == null) {
                t = new SkipList<Object>();
                tmp.put(key, t);
            }
            vals = t;
        }
        if (item.isFormField()) {
            vals.add(new String(item.getString().getBytes(rawEncoding), characterEncoding));
        } else {
            vals.add(item);
        }
    }
    for (final Entry<String, List<Object>> e : tmp.entrySet()) {
        final String key = e.getKey();
        final List<Object> vals = e.getValue();
        result.put(key, vals.size() == 1 ? vals.get(0) : vals);
    }
    return result;
}

From source file:it.polito.tellmefirst.web.rest.clients.ClientEpub.java

public ArrayList<ClassifyOutput> sortResults(HashMap<String, List<ClassifyOutput>> classifiedChapters) {

    LOG.debug("[sortOccurrences] - BEGIN");

    HashMap<String, Integer> classifyOutputOcc = new LinkedHashMap<>();
    Set set = classifiedChapters.entrySet();
    Iterator i = set.iterator();/*from  w w  w .j a va2s . c o  m*/

    while (i.hasNext()) {
        Map.Entry me = (Map.Entry) i.next();
        List<ClassifyOutput> classifyOutputList = (List<ClassifyOutput>) me.getValue();

        for (ClassifyOutput classifyOutput : classifyOutputList) {
            if (classifyOutputOcc.get(classifyOutput.getUri()) == null) {
                classifyOutputOcc.put(classifyOutput.getUri(), 1);
            } else {
                Integer oldValue = classifyOutputOcc.get(classifyOutput.getUri());
                classifyOutputOcc.put(classifyOutput.getUri(), oldValue + 1);
            }
        }
    }

    HashMap<String, Integer> sortedMapByOcc = sortMapByValues(classifyOutputOcc, false);
    HashMap<ClassifyOutput, Integer> sortedMapWithScore = createMapWithScore(sortedMapByOcc,
            classifiedChapters);
    ArrayList<ClassifyOutput> classifyOutputList = sortByRank(sortedMapWithScore);

    LOG.debug("[sortOccurrences] - END");
    return classifyOutputList;
}

From source file:io.personium.client.http.RestAdapter.java

/**
 * This is the PUT method that receives the response body.
 * @param url Target Request URL/*from  ww w .  j a va 2s  .  c  om*/
 * @param map Hash map of Request Header
 * @return DcResponse object
 * @throws DaoException Exception thrown
 */
public PersoniumResponse put(String url, HashMap<String, String> map) throws DaoException {
    HttpUriRequest req = new PersoniumRequestBuilder().url(url).method(HttpMethods.PUT).token(getToken())
            .defaultHeaders(this.accessor.getDefaultHeaders()).build();
    for (Map.Entry<String, String> entry : map.entrySet()) {
        req.setHeader((String) entry.getKey(), (String) entry.getValue());
    }
    return this.request(req);
}

From source file:de.unioninvestment.portal.explorer.view.vfs.VFSMainView.java

public void scanDirectory(FileSystemManager fsManager, FileSystemOptions opts, String ftpconn)
        throws IOException {
    try {/*  w  w  w.  jav a  2 s .c o  m*/
        FileObject fileObject = fsManager.resolveFile(ftpconn, opts);
        FileObject[] files = fileObject.findFiles(new FileTypeSelector(FileType.FOLDER));
        HashMap<String, String> parentMap = new HashMap<String, String>();
        for (FileObject fo : files) {
            String objectName = fo.getName().toString();
            tree.addItem(objectName);
            tree.setItemIcon(objectName, FOLDER);
            if (fo.getParent() != null) {
                String parentName = fo.getParent().getName().toString();
                parentMap.put(objectName, parentName);
            } else
                tree.setItemCaption(objectName, "/");
        }

        // set parents
        logger.log(Level.INFO, "parentMap " + parentMap.size());
        if (parentMap.size() > 0) {
            Iterator<Map.Entry<String, String>> it = parentMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> pairs = it.next();
                tree.setParent(pairs.getKey(), pairs.getValue());
                String caption = pairs.getKey().toString().substring(pairs.getValue().toString().length());

                tree.setItemCaption(pairs.getKey(), removeSlash(caption));
                it.remove();
            }
        }
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
}

From source file:com.oracle.tutorial.jdbc.CoffeesTable.java

public void updateCoffeeSales(HashMap<String, Integer> salesForWeek) throws SQLException {

    PreparedStatement updateSales = null;
    PreparedStatement updateTotal = null;

    String updateString = "update COFFEES " + "set SALES = ? where COF_NAME = ?";

    String updateStatement = "update COFFEES " + "set TOTAL = TOTAL + ? where COF_NAME = ?";

    try {// www  .j a v a 2  s  . c  om
        con.setAutoCommit(false);
        updateSales = con.prepareStatement(updateString);
        updateTotal = con.prepareStatement(updateStatement);

        for (Map.Entry<String, Integer> e : salesForWeek.entrySet()) {
            updateSales.setInt(1, e.getValue().intValue());
            updateSales.setString(2, e.getKey());
            updateSales.executeUpdate();

            updateTotal.setInt(1, e.getValue().intValue());
            updateTotal.setString(2, e.getKey());
            updateTotal.executeUpdate();
            con.commit();
        }
    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
        if (con != null) {
            try {
                System.err.print("Transaction is being rolled back");
                con.rollback();
            } catch (SQLException excep) {
                JDBCTutorialUtilities.printSQLException(excep);
            }
        }
    } finally {
        if (updateSales != null) {
            updateSales.close();
        }
        if (updateTotal != null) {
            updateTotal.close();
        }
        con.setAutoCommit(true);
    }
}

From source file:net.dahanne.gallery.g2.java.client.business.G2Client.java

/**
 * //from w  w w .  j  a va  2  s  .  com
 * From an HashMap of albumProperties (obtained from the remote gallery),
 * returns a List of Albums
 * 
 * @param albumsProperties
 * @return List<Album>
 * @throws GalleryConnectionException 
 */
public Map<Integer, G2Album> extractAlbumFromProperties(HashMap<String, String> albumsProperties)
        throws GalleryConnectionException {
    int albumNumber = 0;
    Map<Integer, G2Album> albumsMap = new HashMap<Integer, G2Album>();
    List<Integer> tmpAlbumNumbers = new ArrayList<Integer>();

    for (Entry<String, String> entry : albumsProperties.entrySet()) {
        if (entry.getKey().contains("album") && !entry.getKey().contains("debug")
                && !entry.getKey().contains("album_count")) {
            // what is the album id of this field ?
            albumNumber = new Integer(entry.getKey().substring(entry.getKey().lastIndexOf(".") + 1));
            G2Album album = null;
            // a new album, let's create it!
            if (!tmpAlbumNumbers.contains(albumNumber)) {
                album = new G2Album();
                album.setId(albumNumber);
                albumsMap.put(albumNumber, album);
                tmpAlbumNumbers.add(albumNumber);

            }
            // a known album, let's get it back
            else {
                album = albumsMap.get(albumNumber);
            }
            try {
                if (entry.getKey().contains("album.title.")) {

                    String title = StringEscapeUtils.unescapeHtml(entry.getValue());
                    title = StringEscapeUtils.unescapeJava(title);
                    album.setTitle(title);
                } else if (entry.getKey().contains("album.name.")) {
                    album.setName(new Integer(entry.getValue()));
                } else if (entry.getKey().contains("album.summary.")) {
                    album.setSummary(entry.getValue());
                } else if (entry.getKey().contains("album.parent.")) {
                    album.setParentName(new Integer(entry.getValue()));
                } else if (entry.getKey().contains("album.info.extrafields.")) {
                    album.setExtrafields(entry.getValue());
                }

            } catch (NumberFormatException nfe) {
                throw new GalleryConnectionException(nfe);
            }
        }
    }

    return albumsMap;

}

From source file:com.microsoft.azure.storage.table.TableEncryptionPolicy.java

/**
 * Return a decrypted entity. This method is used for decrypting entity properties.
 *///from   ww  w  . j av  a  2  s.co  m
HashMap<String, EntityProperty> decryptEntity(HashMap<String, EntityProperty> properties,
        HashSet<String> encryptedPropertyDetailsSet, String partitionKey, String rowKey,
        Key contentEncryptionKey, EncryptionData encryptionData) throws StorageException {
    HashMap<String, EntityProperty> decryptedProperties = new HashMap<String, EntityProperty>();

    try {
        switch (encryptionData.getEncryptionAgent().getEncryptionAlgorithm()) {
        case AES_CBC_256:
            Cipher myAes = Cipher.getInstance("AES/CBC/PKCS5Padding");

            for (Map.Entry<String, EntityProperty> kvp : properties.entrySet()) {
                if (kvp.getKey() == Constants.EncryptionConstants.TABLE_ENCRYPTION_KEY_DETAILS
                        || kvp.getKey() == Constants.EncryptionConstants.TABLE_ENCRYPTION_PROPERTY_DETAILS) {
                    // Do nothing. Do not add to the result properties.
                } else if (encryptedPropertyDetailsSet.contains(kvp.getKey())) {
                    MessageDigest digest = MessageDigest.getInstance("SHA-256");
                    byte[] columnIVFull = digest
                            .digest(Utility.binaryAppend(encryptionData.getContentEncryptionIV(),
                                    (partitionKey + rowKey + kvp.getKey()).getBytes(Constants.UTF8_CHARSET)));

                    byte[] columnIV = new byte[16];
                    System.arraycopy(columnIVFull, 0, columnIV, 0, 16);

                    myAes.init(Cipher.DECRYPT_MODE, contentEncryptionKey, new IvParameterSpec(columnIV));

                    byte[] src = kvp.getValue().getValueAsByteArray();
                    byte[] dest = myAes.doFinal(src, 0, src.length);
                    String destString = new String(dest, Constants.UTF8_CHARSET);
                    decryptedProperties.put(kvp.getKey(), new EntityProperty(destString));
                } else {
                    decryptedProperties.put(kvp.getKey(), kvp.getValue());
                }
            }
            return decryptedProperties;

        default:
            throw new StorageException(StorageErrorCodeStrings.DECRYPTION_ERROR,
                    SR.INVALID_ENCRYPTION_ALGORITHM, null);
        }
    } catch (StorageException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new StorageException(StorageErrorCodeStrings.DECRYPTION_ERROR, SR.DECRYPTION_LOGIC_ERROR, ex);
    }
}

From source file:com.intuit.wasabi.api.pagination.filters.PaginationFilterTest.java

@Test
public void testTestFields() throws Exception {
    TestObjectFilter objectFilter = new TestObjectFilter();

    HashMap<String, Boolean> testCases = new HashMap<>();
    testCases.put("", true);
    testCases.put(null, true);/*  ww w. j a v a  2 s . c om*/
    testCases.put("hash=34", true);
    testCases.put("hash=23,string=match", true);
    testCases.put("hash=no match", false);
    testCases.put("hash=23,string=no match", false);
    testCases.put("hash=no match,string=match", false);
    testCases.put("hash=no match,string=no match", false);
    testCases.put("hash=no match,moreKeys=values", false); // since we fail fast, this does not throw!

    for (Map.Entry<String, Boolean> testCase : testCases.entrySet()) {
        objectFilter.replaceFilter(testCase.getKey(), "");
        try {
            Assert.assertEquals("Case handled incorrectly: " + testCase.getKey(), testCase.getValue(),
                    objectFilter.testFields(testObject, TestObjectFilter.Property.class));
        } catch (Exception exception) {
            Assert.fail("Failed due to exception: " + exception.getMessage() + " - Test was: "
                    + testCase.getKey() + " -> " + testCase.getValue());
        }
    }

    testCases.clear();
    testCases.put("moreKeys=values,hash=no match", false);
    testCases.put("hash=23,moreKeys=values", false);
    testCases.put("moreKeys=values,hash=23", false);

    for (Map.Entry<String, Boolean> testCase : testCases.entrySet()) {
        objectFilter.replaceFilter(testCase.getKey(), "");
        try {
            objectFilter.testFields(testObject, TestObjectFilter.Property.class);
            Assert.fail("Failed, no exception was thrown - Test was: " + testCase.getKey() + " -> "
                    + testCase.getValue());
        } catch (PaginationException ignored) {
            // this should happen
        } catch (Exception exception) {
            Assert.fail("Failed due to wrong exception: " + exception.getClass() + " = Test was: "
                    + testCase.getKey() + " -> " + testCase.getValue());
        }
    }
}