Example usage for java.util Set iterator

List of usage examples for java.util Set iterator

Introduction

In this page you can find the example usage for java.util Set iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:SetUtils.java

public static Set intersection(Set a, Set b) {
    Set c = new HashSet();
    for (Iterator iter = b.iterator(); iter.hasNext();) {
        Object e = iter.next();/*from   w  ww .  java2s  .  co m*/
        if (a.contains(e)) {
            c.add(e);
        }
    }
    return c;
}

From source file:Main.java

private static void organizeAndStart(Activity activity, Class<?> classes, Map<String, String> paramMap) {
    intent = new Intent(activity, classes);
    if (null != paramMap) {
        Set<String> set = paramMap.keySet();
        for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) {
            String key = iterator.next();
            intent.putExtra(key, paramMap.get(key));
        }/* ww  w . ja va  2 s.c  om*/
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    activity.startActivity(intent);
}

From source file:Main.java

public static String getKeyWithMaxValue(final Map<String, Double> pMap) {
    final Set<String> tempSet = pMap.keySet();
    final Iterator<String> iter = tempSet.iterator();
    double max = Integer.MIN_VALUE;
    String maxValsKey = "";
    String temp = "";
    while (iter.hasNext()) {
        temp = iter.next();/* w w w. ja  va2 s  .  c o  m*/
        if (pMap.get(temp) > max) {
            max = pMap.get(temp);
            maxValsKey = temp;
        }
    }
    return maxValsKey + "\t" + max;
}

From source file:Main.java

/**
 * <p>/* w ww .j  ava 2 s .  c  om*/
 * This method returns the <tt>Iterator</tt> of a passed map instance
 * </p>
 * 
 * @param mapObj
 *       A map instance whose iterator needs to be returned
 * 
 * @return
 *       an instance of <tt>Iterator</tt>
 */
public static Iterator<? extends Object> getIteratorForMap(Map<? extends Object, ? extends Object> mapObj) {
    Set<? extends Object> keySet = mapObj.keySet();

    return keySet.iterator();
}

From source file:Main.java

static String generateURLForm(HashMap<String, String> data) throws UnsupportedEncodingException {
    Set<String> keys = data.keySet();
    Iterator<String> keyIterator = keys.iterator();
    String content = "";
    for (int i = 0; keyIterator.hasNext(); i++) {
        String key = keyIterator.next();
        if (i != 0) {
            content += "&";
        }//from  w w w.j  ava2  s. co  m
        content += key + "=" + URLEncoder.encode(data.get(key), "UTF-8");
    }
    return content;
}

From source file:Main.java

private static void organizeAndStart(Context context, Class<?> classes, Map<String, String> paramMap) {
    intent = new Intent(context, classes);

    if (null != paramMap) {
        Set<String> set = paramMap.keySet();
        for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) {
            String key = iterator.next();
            intent.putExtra(key, paramMap.get(key));
        }//from   www .  j  av a  2  s .c  o  m
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);
}

From source file:Main.java

/**
 * Converts a HashMap to a 2d array for JSON Reading
 *
 * @param map//  w w  w .j ava 2 s. co  m
 *
 * @return an array that can be read in JSON as an array
 */
public static Object[][] HashMapToArray(HashMap map) {
    Object[][] map2D = new Object[map.size()][2];
    Set entries = map.entrySet();
    Iterator entriesIterator = entries.iterator();
    int i = 0;
    while (entriesIterator.hasNext()) {

        Map.Entry mapping = (Map.Entry) entriesIterator.next();
        map2D[i][0] = mapping.getKey();
        map2D[i][1] = mapping.getValue();
        i++;
    }

    return map2D;
}

From source file:Main.java

/**
 * Convert an Android bundle to a hashtable
 * @param bundle/*from w ww  .  jav a2s .c  om*/
 * @return
 */
public static Hashtable bundleToHashtable(Bundle bundle) {
    Hashtable retVal = new Hashtable();
    Set<String> keys = bundle.keySet();
    Iterator<String> iterator = keys.iterator();

    String key;
    Object val;
    while (iterator.hasNext()) {
        key = iterator.next();
        val = bundle.get(key);
        if (val instanceof String) {
            retVal.put(key, val);
        } else if (val instanceof Integer) {
            retVal.put(key, val);
        }
    }

    return retVal;
}

From source file:Main.java

public static double calcStrSetSimilarity(final Set<String> strASet1, final Set<String> strASet2) {
    int containsCount = 0;
    final Iterator<String> iter = strASet2.iterator();
    while (iter.hasNext()) {
        if (strASet1.contains(iter.next())) {
            containsCount++;/*from ww  w.  j  a v  a 2 s.c o  m*/
        }
    }
    return (double) containsCount / (double) strASet1.size();
}

From source file:Main.java

public static boolean processReadySet(Set readySet) throws Exception {
    Iterator iterator = readySet.iterator();
    while (iterator.hasNext()) {
        SelectionKey key = (SelectionKey) iterator.next();
        iterator.remove();//from  ww  w .  ja v a 2 s  .c  om
        if (key.isConnectable()) {
            boolean connected = processConnect(key);
            if (!connected) {
                return true; // Exit
            }
        }
        if (key.isReadable()) {
            String msg = processRead(key);
            System.out.println("[Server]: " + msg);
        }
        if (key.isWritable()) {
            System.out.print("Please enter a message(Bye to quit):");
            String msg = userInputReader.readLine();

            if (msg.equalsIgnoreCase("bye")) {
                return true; // Exit
            }
            SocketChannel sChannel = (SocketChannel) key.channel();
            ByteBuffer buffer = ByteBuffer.wrap(msg.getBytes());
            sChannel.write(buffer);
        }
    }
    return false; // Not done yet
}