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.k42b3.neodym.oauth.Oauth.java

private String buildAuthString(HashMap<String, String> values) {
    StringBuilder authString = new StringBuilder();

    Iterator<Entry<String, String>> it = values.entrySet().iterator();

    while (it.hasNext()) {
        Entry<String, String> e = it.next();

        authString.append(urlEncode(e.getKey()) + "=\"" + urlEncode(e.getValue()) + "\", ");
    }/*w w w.j  av a  2  s .co  m*/

    String str = authString.toString();

    // remove ", " from string
    str = str.substring(0, str.length() - 2);

    return str;
}

From source file:foam.littlej.android.app.net.ReportsHttpClient.java

/**
 * Upload files to server 0 - success, 1 - missing parameter, 2 - invalid
 * parameter, 3 - post failed, 5 - access denied, 6 - access limited, 7 - no
 * data, 8 - api disabled, 9 - no task found, 10 - json is wrong
 *//*from   w w w .  j av a 2 s .  c o  m*/
public boolean PostFileUpload(String URL, HashMap<String, String> params) throws IOException {
    log("PostFileUpload(): upload file to server.");

    apiUtils.updateDomain();
    entity = new MultipartEntity();
    // Dipo Fix
    try {
        // wrap try around because this constructor can throw Error
        final HttpPost httpost = new HttpPost(URL);

        if (params != null) {

            for (Entry<String, String> en : params.entrySet()) {
                String key = en.getKey();
                if (key == null || "".equals(key)) {
                    continue;
                }
                String val = en.getValue();
                if (!"filename".equals(key)) {
                    entity.addPart(key, new StringBody(val, Charset.forName("UTF-8")));
                    continue;
                }

                if (!TextUtils.isEmpty(val)) {
                    String filenames[] = val.split(",");
                    log("filenames " + ImageManager.getPhotoPath(context, filenames[0]));
                    for (int i = 0; i < filenames.length; i++) {
                        if (ImageManager.getPhotoPath(context, filenames[i]) != null) {
                            File file = new File(ImageManager.getPhotoPath(context, filenames[i]));
                            if (file.exists()) {
                                entity.addPart("incident_photo[]", new FileBody(file));
                            }
                        }
                    }
                }
            }

            // NEED THIS NOW TO FIX ERROR 417
            httpost.getParams().setBooleanParameter("http.protocol.expect-continue", false);
            httpost.setEntity(entity);

            HttpResponse response = httpClient.execute(httpost);
            Preferences.httpRunning = false;

            HttpEntity respEntity = response.getEntity();
            if (respEntity != null) {
                UshahidiApiResponse resp = GsonHelper.fromStream(respEntity.getContent(),
                        UshahidiApiResponse.class);
                return resp.getErrorCode() == 0;
            }
        }

    } catch (MalformedURLException ex) {
        log("PostFileUpload(): MalformedURLException", ex);

        return false;
        // fall through and return false
    } catch (IllegalArgumentException ex) {
        log("IllegalArgumentException", ex);
        // invalid URI
        return false;
    } catch (ConnectTimeoutException ex) {
        //connection timeout
        log("ConnectionTimeoutException");
        return false;
    } catch (SocketTimeoutException ex) {
        log("SocketTimeoutException");
    } catch (IOException e) {
        log("IOException", e);
        // timeout
        return false;
    }
    return false;
}

From source file:com.clustercontrol.accesscontrol.dialog.RoleSettingDialog.java

/**
 * ???????ID??//from   w ww .  j  ava2  s .com
 *
 * @param userMap HashMap
 * @return ID?
 */
private java.util.List<String> getUserIdList(java.util.HashMap<String, String> userMap) {
    java.util.List<String> resultList = new ArrayList<String>();
    for (Map.Entry<String, String> entry : userMap.entrySet()) {
        resultList.add(entry.getValue());
    }
    return resultList;
}

From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.opt.PerfTestTool.java

/**
 * //from w w  w . j a v  a  2s  .  c om
 * @param dname
 * @param IDMapping
 * @throws IOException
 */
private static void readRegressionModels(String dname, HashMap<Integer, Long> IDMapping) throws IOException {
    for (Entry<Integer, Long> e : IDMapping.entrySet()) {
        int count = e.getKey();
        long ID = e.getValue();
        int instID = IDHandler.extractIntIDFromLong(ID, 1);
        int tDefID = IDHandler.extractIntIDFromLong(ID, 2);

        //read file and parse
        LinkedList<Double> params = new LinkedList<Double>();
        CSVReader reader1 = new CSVReader(new FileReader(dname + count + "_out.csv"), ',');
        String[] nextline = null;
        while ((nextline = reader1.readNext()) != null) {
            params.add(Double.parseDouble(nextline[0]));
        }
        reader1.close();

        double[] dparams = new double[params.size()];
        int i = 0;
        for (Double d : params) {
            dparams[i] = d;
            i++;
        }

        //create new cost function
        boolean multidim = _regTestDef.get(tDefID).getInternalVariables().length > 1;
        CostFunction cf = new CostFunction(dparams, multidim);

        //append to profile
        if (!_profile.containsKey(instID))
            _profile.put(instID, new HashMap<Integer, CostFunction>());
        _profile.get(instID).put(tDefID, cf);
    }
}

From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java

/**
 * ??? PUT./*from w w  w.j  a  v  a  2s  .co m*/
 * @param url URL
 * @param data ??
 * @param headers ??
 * @return DcResponse
 * @throws DcException DAO
 */
public final DcResponse put(final String url, final String data, final HashMap<String, String> headers)
        throws DcException {
    String contentType = headers.get(HttpHeaders.CONTENT_TYPE);
    HttpUriRequest req = makePutRequest(url, data, contentType);
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        req.setHeader(entry.getKey(), entry.getValue());
    }
    req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion());

    debugHttpRequest(req, data);
    DcResponse res = request(req);
    return res;
}

From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java

/**
 * ??? POST.//  w  w w  . j  ava 2 s .  co m
 * @param url URL
 * @param data ??
 * @param headers ??
 * @return DcResponse
 * @throws DcException DAO
 */
public final DcResponse post(final String url, final String data, final HashMap<String, String> headers)
        throws DcException {
    String contentType = headers.get(HttpHeaders.CONTENT_TYPE);
    HttpUriRequest req = makePostRequest(url, data, contentType);
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        req.setHeader(entry.getKey(), entry.getValue());
    }
    req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion());

    debugHttpRequest(req, data);
    DcResponse res = request(req);
    return res;
}

From source file:net.geant.edugain.filter.EduGAINFilter.java

private void addAttributes(HashMap<String, String> attrs, HttpSession session) {
    Iterator it = attrs.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, String> entry = (Entry<String, String>) it.next();
        session.setAttribute(entry.getKey(), entry.getValue());
    }//from w  w  w.  ja  v  a2s.  co m
}

From source file:biocode.fims.ezid.EzidService.java

/**
 * Serialize a HashMap of metadata name/value pairs as an ANVL String value. If the
 * HashMap is null, or if it has no entries, then return a null string.
 *
 * @param metadata the Map of metadata name/value pairs
 *
 * @return an ANVL serialize String//from  w w w.  j  av  a2s  .c  o m
 */
private String serializeAsANVL(HashMap<String, String> metadata) {
    StringBuffer buffer = new StringBuffer();
    if (metadata != null && metadata.size() > 0) {
        for (Map.Entry<String, String> entry : metadata.entrySet()) {
            buffer.append(escape(entry.getKey()) + ": " + escape(entry.getValue()) + "\n");
        }
    }
    String anvl = null;
    if (buffer != null) {
        anvl = buffer.toString();
    }
    return anvl;
}

From source file:fr.eoidb.util.ImageDownloader.java

@SuppressWarnings("unchecked")
public void loadImageCache(Context context) {
    if (BuildConfig.DEBUG)
        Log.v(LOG_TAG, "Loading image cache...");
    File cacheFile = new File(context.getCacheDir(), cacheFileName);

    if (cacheFile.exists() && cacheFile.length() > 0) {
        ObjectInputStream ois = null;
        try {//from   w w  w.  ja va2 s.co  m
            HashMap<String, String> cacheDescription = new HashMap<String, String>();
            ois = new ObjectInputStream(new FileInputStream(cacheFile));
            cacheDescription = (HashMap<String, String>) ois.readObject();

            for (Entry<String, String> cacheDescEntry : cacheDescription.entrySet()) {
                loadSingleCacheFile(cacheDescEntry.getKey(), context);
            }
        } catch (StreamCorruptedException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } catch (FileNotFoundException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } catch (EOFException e) {
            //delete the corrupted cache file
            Log.w(LOG_TAG, "Deleting the corrupted cache file.", e);
            cacheFile.delete();
        } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } catch (ClassNotFoundException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } finally {
            if (ois != null) {
                try {
                    ois.close();
                } catch (IOException e) {
                    Log.e(LOG_TAG, e.getMessage(), e);
                }
            }
        }
    }
}

From source file:gemlite.shell.admin.dao.AdminDao.java

public void processReadRegion(ClientCache clientCache, String rr) {
    try {/*w  w w. j a  va 2 s. co  m*/
        FileWriter writer = new FileWriter(rr, true);
        Region region = clientCache.getRegion(rr);
        Set set = region.keySetOnServer();
        HashMap map = (HashMap) region.getAll(set);
        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            writer.write(it.next().toString() + "\n");
        }
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}