Example usage for java.util HashMap keySet

List of usage examples for java.util HashMap keySet

Introduction

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

Prototype

public Set<K> keySet() 

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:com.projity.configuration.FieldDictionary.java

public static void setAliasMap(HashMap aliasMap) {
    if (aliasMap == null)
        return;//from ww w  . j a va  2 s.  c  om
    Iterator i = aliasMap.keySet().iterator();
    while (i.hasNext()) {
        String fieldId = (String) i.next();
        Field f = Configuration.getFieldFromId(fieldId);
        if (f != null)
            f.setAlias((String) aliasMap.get(fieldId));
    }
}

From source file:eu.scape_project.pc.tika.cli.TifowaCli.java

private static void displayMyTypes(HashMap<String, Integer> myCollection, int countAllCalls,
        int countAllGoodItems, int countAllFailedItems, long elapsedTimeSec) {

    Iterator<String> it = myCollection.keySet().iterator();

    System.out.println("************************************");
    System.out.println("Total file processing time (sec): " + elapsedTimeSec / 1000F);
    System.out.println("************************************");
    System.out.println("Total number of TIKA calls      : " + countAllCalls);
    System.out.println("************************************");
    System.out.println("Total number of files analyzed  : " + countAllGoodItems);
    System.out.println("************************************");
    System.out.println("Total number of FAILED files    : " + countAllFailedItems);
    System.out.println("************************************");
    System.out.println("*** You can import the data below into a CSV. Use # as the separator. ***");
    System.out.println();/*w  ww . j  a va  2s .  c o m*/
    System.out.println("TYPE#COUNT#PERCENTAGE");

    while (it.hasNext()) {

        String typeKey = it.next().toString();
        float typeValue = myCollection.get(typeKey);
        float myPerc = typeValue / countAllGoodItems * 100;
        //System.out.println(typeKey + " : " + typeValue + " => " + myPerc + "%");
        System.out.println(typeKey + "#" + (int) typeValue + "#" + myPerc);

    }

    //System.out.println("************************************");
    //System.out.println(myCollection);
    //System.out.println("************************************");
    System.out.println();

}

From source file:it.univaq.incipict.profilemanager.common.utility.Utility.java

public static Profile getBestProfile(HashMap<Profile, Double> distancesMap) {
    if (distancesMap.isEmpty() || distancesMap == null)
        return null;
    // return the first element because the distances map is sorted by values
    // REF: getEuclideanDistances() method
    return distancesMap.keySet().iterator().next();
}

From source file:com.csipsimple.utils.SipProfileJson.java

private static final JSONArray serializeSipProfiles(Context ctxt) {
    JSONArray jsonSipProfiles = new JSONArray();
    DBAdapter db = new DBAdapter(ctxt);
    db.open();/*  www  .ja v  a 2 s.co m*/
    List<SipProfile> accounts = db.getListAccounts();
    int i = 0;
    for (i = 0; i < accounts.size(); i++) {
        JSONObject p = serializeSipProfile(accounts.get(i), db);
        try {
            jsonSipProfiles.put(jsonSipProfiles.length(), p);
        } catch (JSONException e) {
            Log.e(THIS_FILE, "Impossible to add profile", e);
        }
    }

    // Add negative fake accounts

    HashMap<String, String> callHandlers = CallHandler.getAvailableCallHandlers(ctxt);
    for (String packageName : callHandlers.keySet()) {
        final Integer externalAccountId = CallHandler.getAccountIdForCallHandler(ctxt, packageName);
        SipProfile gsmProfile = new SipProfile();
        gsmProfile.id = externalAccountId;
        JSONObject p = serializeSipProfile(gsmProfile, db);
        try {
            jsonSipProfiles.put(jsonSipProfiles.length(), p);
        } catch (JSONException e) {
            Log.e(THIS_FILE, "Impossible to add profile", e);
        }
    }

    db.close();
    return jsonSipProfiles;
}

From source file:com.twosigma.beakerx.mimetype.MIMEContainer.java

private static String parseParams(HashMap paramsMap) {
    List iframeParamKeys = Arrays.asList("width", "height", "id");

    StringBuilder sb = new StringBuilder();
    for (Object key : paramsMap.keySet()) {
        if (iframeParamKeys.contains(key)) {
            continue;
        }/*from www  .ja  va 2  s. c  o m*/
        sb.append("&").append(key.toString()).append("=").append(paramsMap.get(key).toString());
    }
    String result = sb.toString().replaceFirst("&", "?");
    return result.length() > 0 ? result : "";
}

From source file:edu.umich.ctools.sectionsUtilityTool.Friend.java

public static String replacePlaceHolders(String message, HashMap<String, String> map) {

    Iterator<String> keySetIterator = map.keySet().iterator();

    while (keySetIterator.hasNext()) {
        String key = keySetIterator.next();
        message = message.replace(key, map.get(key));
    }//from  w w w. j  a  va  2  s  .  co m

    return message;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils.java

/** Make a copy of a Map<String,String> */
public static Map<String, String> copyMap(Map<String, String> source) {
    HashMap<String, String> map = new HashMap<String, String>();
    Set<String> keys = map.keySet();
    for (String key : keys) {
        if (source.get(key) != null)
            map.put(new String(key), new String(source.get(key)));
        else/*w  w  w .  ja  v a 2s . co m*/
            map.put(new String(key), null);
    }
    return map;
}

From source file:com.app.server.util.ClassLoaderUtil.java

public static boolean cleanupJarFileFactory(CopyOnWriteArrayList setJarFileNames2Close) {
    boolean res = false;
    Class classJarURLConnection = null;
    try {/*from w  w w.j ava  2s  . co  m*/
        classJarURLConnection = Class.forName("sun.net.www.protocol.jar.JarURLConnection");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    if (classJarURLConnection == null) {
        return res;
    }
    Field f = null;
    try {
        f = classJarURLConnection.getDeclaredField("factory");
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
    if (f == null) {
        return res;
    }
    f.setAccessible(true);
    Object obj = null;
    try {
        obj = f.get(null);
    } catch (IllegalAccessException e) {
        // ignore
    }
    if (obj == null) {
        return res;
    }
    Class classJarFileFactory = obj.getClass();
    //
    HashMap fileCache = null;
    try {
        f = classJarFileFactory.getDeclaredField("fileCache");
        f.setAccessible(true);
        obj = f.get(null);
        if (obj instanceof HashMap) {
            fileCache = (HashMap) obj;
        }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    HashMap urlCache = null;
    try {
        f = classJarFileFactory.getDeclaredField("urlCache");
        f.setAccessible(true);
        obj = f.get(null);
        if (obj instanceof HashMap) {
            urlCache = (HashMap) obj;
        }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    if (urlCache != null) {
        HashMap urlCacheTmp = (HashMap) urlCache.clone();
        Iterator it = urlCacheTmp.keySet().iterator();
        while (it.hasNext()) {
            obj = it.next();
            if (!(obj instanceof JarFile)) {
                continue;
            }
            JarFile jarFile = (JarFile) obj;
            if (setJarFileNames2Close.contains(jarFile.getName().trim().toUpperCase())) {
                try {
                    jarFile.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (fileCache != null) {
                    fileCache.remove(jarFile);
                }
                urlCache.remove(jarFile);
            }
        }
        res = true;
    } else if (fileCache != null) {
        // urlCache := null
        HashMap fileCacheTmp = (HashMap) fileCache.clone();
        Iterator it = fileCacheTmp.keySet().iterator();
        while (it.hasNext()) {
            Object key = it.next();
            obj = fileCache.get(key);
            if (!(obj instanceof JarFile)) {
                continue;
            }
            JarFile jarFile = (JarFile) obj;

            try {
                jarFile.close();
            } catch (IOException e) {
                // ignore
            }
            fileCache.remove(key);

        }
        res = true;
    }
    setJarFileNames2Close.clear();
    return res;
}

From source file:info.plugmania.mazemania.Util.java

public static String getStorePlayerNames(HashMap<Player, PlayerStore> ps) {
    List<String> names = new ArrayList<String>();

    for (Player p : ps.keySet()) {
        names.add(p.getName());/*w  ww.  j a v a2  s .  c  o  m*/
    }
    return StringUtils.join(names, ", ");
}

From source file:utilities.itext.Turnover.java

private static Paragraph createTablesWithoutDetails(HashMap<String, BigDecimal> expenseData)
        throws DocumentException {
    Paragraph paragraph = new Paragraph();

    PdfPTable expense = new PdfPTable(2);
    float[] colWidths = { 1f, 3f };
    expense.setWidths(colWidths);//from  ww  w  .  java 2 s.  c o m

    for (String cat : expenseData.keySet()) {
        Paragraph contentCell1 = new Paragraph(cat);
        PdfPCell cell1 = new PdfPCell(contentCell1);

        Paragraph contentCell2 = new Paragraph(formatter.format(expenseData.get(cat)));
        PdfPCell cell2 = new PdfPCell(contentCell2);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cell1.setPaddingBottom(4f);
        cell2.setPaddingBottom(4f);

        expense.addCell(cell1);
        expense.addCell(cell2);
    }

    paragraph.add(expense);
    return paragraph;
}