Example usage for java.util Iterator next

List of usage examples for java.util Iterator next

Introduction

In this page you can find the example usage for java.util Iterator next.

Prototype

E next();

Source Link

Document

Returns the next element in the iteration.

Usage

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++;//w w w.ja v  a 2  s .c om
        }
    }
    return (double) containsCount / (double) strASet1.size();
}

From source file:Main.java

/**
 * Consumes all the elements of the iterator and
 * returns a list containing them. The iterator is
 * then unusable//from w  ww.  jav a  2s  .  co m
 *
 * @param it An iterator
 *
 * @return a list containing the elements remaining
 * on the iterator
 */
public static <T> List<T> toList(Iterator<T> it) {
    List<T> list = new ArrayList<>();
    while (it.hasNext()) {
        list.add(it.next());
    }
    return list;
}

From source file:Main.java

/**
 * Returns a String representation of the elements delimited with the specified delimiter 
 * //from  w w  w  . ja va2s.c  om
 * @param elements the elements to build the String out of
 * @param delimiter the specified delimiter
 * @return the delimited String
 */
public static <T> String asDelimitedString(Collection<T> elements, String delimiter) {
    StringBuilder sb = new StringBuilder();
    Iterator<T> iterator = elements.iterator();
    while (iterator.hasNext()) {
        sb.append(iterator.next().toString());
        sb.append(iterator.hasNext() ? delimiter : EMPTY_STRING);
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Returns the string that represents the content of a given style map.
 * @param styleMap Map with the styles values
 * @return string that represents the style.
 *///from   ww  w .j  a  v  a 2 s.c o  m
public static String getStyleString(Map<String, Object> styleMap, String asig) {
    String style = "";
    Iterator<Object> it = styleMap.values().iterator();
    Iterator<String> kit = styleMap.keySet().iterator();

    while (kit.hasNext()) {
        String key = kit.next();
        Object value = it.next();
        style = style + key + asig + value + ";";
    }
    return style;
}

From source file:Main.java

public static Map<String, Object> toMap(JSONObject object) throws JSONException {
    Map<String, Object> map = new HashMap();
    Iterator keys = object.keys();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        map.put(key, fromJson(object.get(key)));
    }/*from w w  w  . jav a2 s . com*/
    return map;
}

From source file:Main.java

public static <T> T getObjInList(Class<T> clazz, Collection<T> all, String valueStr, String propName)
        throws Exception {
    if (all.isEmpty() || valueStr == null) {
        return null;
    }/* ww  w  .  j  a v  a2  s  .co  m*/
    T obj = null;
    Iterator<T> iter = all.iterator();
    for (; iter.hasNext();) {
        T temp = iter.next();
        Object match = null;
        if (propName == null) {
            match = temp.toString();
        } else {
            Field field = clazz.getField(propName);
            field.setAccessible(true);
            match = field.get(temp);
        }
        if (valueStr.equals(match)) {
            obj = temp;
            break;
        }
    }
    return obj;
}

From source file:Main.java

public static String buildValuesString(List<Object> values) {
    StringBuilder sb = new StringBuilder();
    Iterator<Object> valueIt = values.iterator();
    while (valueIt.hasNext()) {
        sb.append(valueIt.next());
        if (valueIt.hasNext()) {
            sb.append(";");
        }/*from   www .j a  va  2 s .co m*/
    }
    return sb.toString();
}

From source file:Main.java

public static <T> Iterator<T> dump(Iterator<T> it) {
    List<T> list = new ArrayList<T>();
    while (it.hasNext()) {
        list.add(it.next());
    }//from w w  w. j ava 2 s  .com

    System.out.println(list);
    return list.iterator();
}

From source file:Main.java

/**
 * Returns a hashcode that is computed irrespective of the order of the collection.  This method should be used
 * to compute a hashcode of a collection field when <code>unorderedListEquals</code> or
 * <code>unorderedCollectionEquals</code> is used for that field in the object's equals method. 
 * /*from   ww  w  .j  ava 2 s . c  o  m*/
 * @param c the <code>Collection</code>
 * @return the hashcode
 */
public static int unorderedCollectionHashCode(Collection<?> c) {
    if (c == null)
        return 0;

    int h = 0;
    Iterator<?> i = c.iterator();
    while (i.hasNext()) {
        Object o = i.next();
        if (o != null)
            h += o.hashCode();
    }
    return h;
}

From source file:Main.java

public static String getReqPama(Map<String, String> params) {
    StringBuffer sBuffer = new StringBuffer();
    Iterator<?> iterator = params.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        sBuffer.append(key + "=" + params.get(key) + "&");
    }/*from   ww w.j  a  va 2  s.c o m*/
    String reqString = sBuffer.toString();
    return reqString.substring(0, reqString.length() - 1);
}