Example usage for java.util Iterator hasNext

List of usage examples for java.util Iterator hasNext

Introduction

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

Prototype

boolean hasNext();

Source Link

Document

Returns true if the iteration has more elements.

Usage

From source file:Main.java

public static String join(Collection<?> s, String delimiter) {
    StringBuilder builder = new StringBuilder();
    Iterator<?> iter = s.iterator();
    while (iter.hasNext()) {
        builder.append(iter.next());/*from   w  w  w  .  j  a va  2 s .c o  m*/
        if (iter.hasNext()) {
            builder.append(delimiter);
        }
    }
    return builder.toString();
}

From source file:Main.java

/**
 * Converts the given collection to a <code>java.util.List</code>.
 * @param collection The collection to convert to a list.
 * @return A <code>java.util.List</code> containing all of the elements from the
 *         supplied collection.//from   w  ww.j  a  v a  2  s  .co  m
 */
public static List toList(Collection collection) {
    if (collection instanceof List)
        return (List) collection;

    List list = new ArrayList();
    Iterator iterator = collection.iterator();
    while (iterator.hasNext()) {
        list.add(iterator.next());
    }
    return list;
}

From source file:Main.java

public static <T extends Collection<?>> void stripNulls(T collection) {
    Iterator<?> iterator = collection.iterator();
    while (iterator.hasNext()) {
        if (iterator.next() == null)
            iterator.remove();/*w ww. ja  v  a2s. c om*/
    }
}

From source file:Main.java

public static <T> List<T> listFromIterator(Iterator<T> i) {
    List<T> retval = new ArrayList<T>();
    while (i.hasNext())
        retval.add(i.next());/* w ww .  ja  v  a 2s .  c  o  m*/
    return retval;
}

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 ww  .  j a  v a 2 s. com
    return map;
}

From source file:Main.java

public static void removeNullValues(List<?> list) {

    Iterator<?> iterator = list.iterator();

    while (iterator.hasNext()) {

        Object value = iterator.next();

        if (value == null) {

            iterator.remove();//from   w  ww. java 2  s  . com
        }
    }
}

From source file:Main.java

public static <T> List<T> toList(Iterator<T> it) {
    List<T> result = new ArrayList<T>();
    while (it.hasNext())
        result.add(it.next());//ww w .  j av  a  2  s. co  m
    return result;
}

From source file:Main.java

public static String toString(Iterable<Object> pathItrb) {
    LinkedList<Object> list = new LinkedList<Object>();
    Iterator itr = pathItrb.iterator();
    while (itr.hasNext()) {
        list.addFirst(itr.next());/*ww  w . j av a2  s .c o  m*/
    }
    //
    StringBuilder sb = new StringBuilder();
    boolean isFirst = true;
    for (Object obj : list) {
        if (isFirst) {
            isFirst = false;
        } else {
            sb.append("/"); // NOI18N
        }
        sb.append(obj.toString());
    }
    //
    return sb.toString();
}

From source file:Main.java

/**
 * Joins a collection of strings to a single string, all parts are merged with a delimiter string.
 *
 * @param aContainer/*from www .  j a v a2 s.c  o  m*/
 * @param aDelimiter
 * @return
 */
public static String join(final Iterable<String> aContainer, final String aDelimiter) {
    StringBuilder builder = new StringBuilder();
    Iterator<String> it = aContainer.iterator();
    while (it.hasNext()) {
        builder.append(it.next());
        if (it.hasNext())
            builder.append(aDelimiter);
    }
    return builder.toString();
}

From source file:Main.java

protected static void checkPermittedEmail(Set permitted, String email) throws CertPathValidatorException {
    if (permitted.isEmpty()) {
        return;/*  w  ww.  ja  v a  2  s . c om*/
    }

    String sub = email.substring(email.indexOf('@') + 1);
    Iterator it = permitted.iterator();

    while (it.hasNext()) {
        String str = (String) it.next();

        if (sub.endsWith(str)) {
            return;
        }
    }

    throw new CertPathValidatorException("Subject email address is not from a permitted subtree");
}