org.apache.commons.collections.iterators.ArrayIterator Java Examples

The following examples show how to use org.apache.commons.collections.iterators.ArrayIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThingHelper.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Ensures that there are no duplicate channels in the array (i.e. not using the same ChannelUID)
 *
 * @param channels the channels to check
 * @throws IllegalArgumentException in case there are duplicate channels found
 */
public static void ensureUniqueChannels(final Channel[] channels) {
    @SuppressWarnings("unchecked")
    final Iterator<Channel> it = new ArrayIterator(channels);

    ensureUniqueChannels(it, new HashSet<UID>(channels.length));
}
 
Example #2
Source File: IteratorUtils.java    From Penetration_Testing_POC with Apache License 2.0 4 votes vote down vote up
/** 
 * Gets a suitable Iterator for the given object.
 * <p>
 * This method can handles objects as follows
 * <ul>
 * <li>null - empty iterator
 * <li>Iterator - returned directly
 * <li>Enumeration - wrapped
 * <li>Collection - iterator from collection returned
 * <li>Map - values iterator returned
 * <li>Dictionary - values (elements) enumeration returned as iterator
 * <li>array - iterator over array returned
 * <li>object with iterator() public method accessed by reflection
 * <li>object - singleton iterator
 * </ul>
 * 
 * @param obj  the object to convert to an iterator
 * @return a suitable iterator, never null
 */
public static Iterator getIterator(Object obj) {
    if (obj == null) {
        return emptyIterator();
        
    } else if (obj instanceof Iterator) {
        return (Iterator) obj;
        
    } else if (obj instanceof Collection) {
        return ((Collection) obj).iterator();
        
    } else if (obj instanceof Object[]) {
        return new ObjectArrayIterator((Object[]) obj);
        
    } else if (obj instanceof Enumeration) {
        return new EnumerationIterator((Enumeration) obj);
        
    } else if (obj instanceof Map) {
        return ((Map) obj).values().iterator();
        
    } else if (obj instanceof Dictionary) {
        return new EnumerationIterator(((Dictionary) obj).elements());
        
    } else if (obj != null && obj.getClass().isArray()) {
        return new ArrayIterator(obj);
        
    } else {
        try {
            Method method = obj.getClass().getMethod("iterator", null);
            if (Iterator.class.isAssignableFrom(method.getReturnType())) {
                Iterator it = (Iterator) method.invoke(obj, null);
                if (it != null) {
                    return it;
                }
            }
        } catch (Exception ex) {
            // ignore
        }
        return singletonIterator(obj);
    }
}
 
Example #3
Source File: IteratorUtils.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets an iterator over an object or primitive array.
 * <p>
 * This method will handle primitive arrays as well as object arrays.
 * The primitives will be wrapped in the appropriate wrapper class.
 *
 * @param array  the array over which to iterate
 * @return  an iterator over the array
 * @throws IllegalArgumentException if the array is not an array
 * @throws NullPointerException if array is null
 */
public static ResettableIterator arrayIterator(Object array) {
    return new ArrayIterator(array);
}
 
Example #4
Source File: IteratorUtils.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets an iterator over the end part of an object or primitive array.
 * <p>
 * This method will handle primitive arrays as well as object arrays.
 * The primitives will be wrapped in the appropriate wrapper class.
 *
 * @param array  the array over which to iterate
 * @param start  the index to start iterating at
 * @return an iterator over part of the array
 * @throws IllegalArgumentException if the array is not an array
 * @throws IndexOutOfBoundsException if start is less than zero or greater
 *  than the length of the array
 * @throws NullPointerException if array is null
 */
public static ResettableIterator arrayIterator(Object array, int start) {
    return new ArrayIterator(array, start);
}
 
Example #5
Source File: IteratorUtils.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets an iterator over part of an object or primitive array.
 * <p>
 * This method will handle primitive arrays as well as object arrays.
 * The primitives will be wrapped in the appropriate wrapper class.
 *
 * @param array  the array over which to iterate
 * @param start  the index to start iterating at
 * @param end  the index to finish iterating at
 * @return an iterator over part of the array
 * @throws IllegalArgumentException if the array is not an array
 * @throws IndexOutOfBoundsException if array bounds are invalid
 * @throws IllegalArgumentException if end is before start
 * @throws NullPointerException if array is null
 */
public static ResettableIterator arrayIterator(Object array, int start, int end) {
    return new ArrayIterator(array, start, end);
}