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 Optional<Characters> getCharacterEventOfElement(List<XMLEvent> events, String elementName) {
    Iterator<XMLEvent> iterator = events.iterator();

    while (iterator.hasNext()) {
        XMLEvent event = iterator.next();

        if (event.isStartElement() && event.asStartElement().getName().getLocalPart().equals(elementName)) {
            XMLEvent nextEvent = iterator.next();
            if (nextEvent.isCharacters())
                return Optional.of(nextEvent.asCharacters());
        }//ww  w .j a  va  2  s.c  o m

    }

    return Optional.empty();
}

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   w ww  . jav a 2s  . co 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 List getListFromIterator(Iterator thisIterator) {
    List listOfStuff = new ArrayList();
    while (thisIterator.hasNext()) {
        listOfStuff.add(thisIterator.next());
    }//w w  w.j av a 2 s.c o  m

    return listOfStuff;
}

From source file:Main.java

/**
 * Returns true if there is any element that is common to both collections.
 *//*www.  ja  v a2  s. co m*/
public static boolean containsAny(Collection c1, Collection c2) {
    // A better implementation here would be to use sets
    Collection smallCollection;
    Collection largeCollection;
    if (c1.size() < c2.size()) {
        smallCollection = c1;
        largeCollection = c2;
    } else {
        smallCollection = c2;
        largeCollection = c1;
    }
    boolean intersect = false;
    Iterator i = smallCollection.iterator();
    while (i.hasNext()) {
        if (largeCollection.contains(i.next())) {
            intersect = true;
            break;
        }
    }
    return intersect;
}

From source file:Main.java

public static String convert2XML(Map<String, String> params) {
    StringBuffer sb = new StringBuffer("<xml>");
    try {// w  w  w  .  j  a v a 2 s.  co m
        Iterator it = params.entrySet().iterator();
        while (it.hasNext()) {
            Entry entry = (Entry) it.next();
            sb.append("<" + entry.getKey() + ">");
            // sb.append("<![CDATA[" + entry.getValue() + "]]");
            sb.append(entry.getValue());
            sb.append("</" + entry.getKey() + ">");
        }
        sb.append("</xml>");

    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

From source file:Main.java

public static <T> List<T> ToList2(Collection<T> values) {
    List<T> alllist = new ArrayList<T>();
    Iterator<T> iterator = values.iterator();
    T obj = null;//from w  w w  . ja va  2  s  .  com
    while (iterator.hasNext()) {
        obj = iterator.next();
        alllist.add(obj);
    }
    return alllist;
}

From source file:Main.java

/**
 * Returns all objects of given type and its subtypes
 * @param clazz The class you want to return all of the instances of.
 * @param objects The collection you'd like to search.
 * @return A List of all of the instances of a specific Class found in a Collection.
 *//*w w w  .  java2  s .  co  m*/
public static List getAllInstances(Class clazz, Collection objects) {
    List allInstances = new ArrayList();
    if (objects != null && clazz != null) {
        Iterator objectsIterator = objects.iterator();
        while (objectsIterator.hasNext()) {
            Object instance = objectsIterator.next();
            if (instance != null) {
                if (clazz.isAssignableFrom(instance.getClass())) {
                    allInstances.add(instance);
                }
            }
        }
    }
    return allInstances;
}

From source file:Main.java

/**
 * Constructs a SortedSet&lt;T> with all the elements available from i
 * @param i an iterator to pull elements from
 * @param <T> The type of the elements
 * @return a SortedSet of the elements//w  ww  .ja va  2  s  . c o  m
 */
public static <T> SortedSet<T> sortedSetFromIterator(Iterator<T> i) {
    SortedSet<T> retval = new TreeSet<T>();
    while (i.hasNext())
        retval.add(i.next());
    return retval;
}

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;
    }//from  ww w .ja  v a  2s  .c om
    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

/**
 * Converts a List with org.w3c.dom.Element objects to an Array
 * with org.w3c.dom.Element objects.//from ww  w  .j av a 2  s . c  o m
 * @param list List containing org.w3c.dom.Element objects
 * @return Element[] Array with org.w3c.dom.Element objects
 */
public static Element[] asElementArray(List list) {

    Element[] elements = new Element[list.size()];

    int i = 0;
    Iterator detailIter = list.iterator();
    while (detailIter.hasNext()) {
        elements[i++] = (Element) detailIter.next();
    }

    return elements;
}