Example usage for java.util Iterator Iterator

List of usage examples for java.util Iterator Iterator

Introduction

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

Prototype

Iterator

Source Link

Usage

From source file:eu.eidas.auth.commons.PersonalAttributeList.java

/**
 * {@inheritDoc}/*  w w w  . j  a v a2  s. c o  m*/
 */
@Nonnull
@Override
public Iterator<PersonalAttribute> iterator() {
    final Iterator<ConcurrentLinkedQueue<PersonalAttribute>> outerIterator = map.values().iterator();
    Iterator<PersonalAttribute> personalAttributeIterator = new Iterator<PersonalAttribute>() {

        Iterator<PersonalAttribute> currentInnerIterator;

        @Override
        public boolean hasNext() {
            return (currentInnerIterator != null && currentInnerIterator.hasNext()) || outerIterator.hasNext();
        }

        @Override
        public PersonalAttribute next() {
            if (null == currentInnerIterator || !currentInnerIterator.hasNext()) {
                currentInnerIterator = outerIterator.next().iterator();

            }
            return currentInnerIterator.next();
        }

        @Override
        public void remove() {
            if (null != currentInnerIterator) {
                currentInnerIterator.remove();
            }
            if (null != currentInnerIterator && !currentInnerIterator.hasNext() && null != outerIterator) {
                outerIterator.remove();
            }
        }
    };
    return personalAttributeIterator;
}

From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram1D.java

/**
 * This iterator acts on the underlying collection of scans in
 * Chromatogram1D, so be careful with concurrent access / modification!
 */// w ww .  j  av  a 2 s .c  om
@Override
public Iterator<IScan1D> iterator() {

    final Iterator<IScan1D> iter = new Iterator<IScan1D>() {
        private int currentPos = 0;

        @Override
        public boolean hasNext() {
            return this.currentPos < getScans().size() - 1;
        }

        @Override
        public IScan1D next() {
            return getScan(this.currentPos++);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Can not remove scans with iterator!");
        }
    };
    return iter;
}

From source file:WeakValueHashMap.java

/**
 * Returns a <code>Collection</code> view of the values contained
 * in this map.<p>/*  w ww . j av a 2s.  c om*/
 * @return a <code>Collection</code> view of the values contained
 * in this map.
 */
public Collection values() {
    // delegates to entrySet, because super method returns
    // WeakValues instead of value objects
    if (values == null) {
        values = new AbstractCollection() {
            public Iterator iterator() {
                return new Iterator() {
                    private Iterator i = entrySet().iterator();

                    public boolean hasNext() {
                        return i.hasNext();
                    }

                    public Object next() {
                        return ((Entry) i.next()).getValue();
                    }

                    public void remove() {
                        i.remove();
                    }
                };
            }

            public int size() {
                return WeakValueHashMap.this.size();
            }

            public boolean contains(Object v) {
                return WeakValueHashMap.this.containsValue(v);
            }
        };
    }
    return values;
}

From source file:org.deegree.feature.persistence.geocouch.GeoCouchFeatureStore.java

@Override
public FeatureInputStream query(final Query[] queries) throws FeatureStoreException, FilterEvaluationException {

    // check for most common case: multiple featuretypes, same bbox (WMS), no filter
    boolean wmsStyleQuery = false;
    Envelope env = queries[0].getPrefilterBBoxEnvelope();
    if (queries[0].getFilter() == null && queries[0].getSortProperties().length == 0) {
        wmsStyleQuery = true;//from  w  w  w. j a v  a2s.  c om
        for (int i = 1; i < queries.length; i++) {
            Envelope queryBBox = queries[i].getPrefilterBBoxEnvelope();
            if (queryBBox != env && queries[i].getFilter() != null && queries[i].getSortProperties() != null) {
                wmsStyleQuery = false;
                break;
            }
        }
    }

    if (wmsStyleQuery) {
        // return queryMultipleFts( queries, env );
    }

    Iterator<FeatureInputStream> rsIter = new Iterator<FeatureInputStream>() {
        int i = 0;

        @Override
        public boolean hasNext() {
            return i < queries.length;
        }

        @Override
        public FeatureInputStream next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            FeatureInputStream rs;
            try {
                rs = query(queries[i++]);
            } catch (Throwable e) {
                LOG.debug(e.getMessage(), e);
                throw new RuntimeException(e.getMessage(), e);
            }
            return rs;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new CombinedFeatureInputStream(rsIter);
}

From source file:com.slytechs.capture.file.editor.AbstractRawIterator.java

public Iterator<ByteBuffer> iterator() {
    final RawIterator i = this;
    return new Iterator<ByteBuffer>() {

        /* (non-Javadoc)
        * @see java.util.Iterator#hasNext()
        *//*from  w  w  w .jav a  2 s .  com*/
        public boolean hasNext() {
            try {
                return i.hasNext();
            } catch (IOException e) {
                throw new RuntimeIOException(e);
            }
        }

        /* (non-Javadoc)
        * @see java.util.Iterator#next()
        */
        public ByteBuffer next() {
            try {
                return i.next();
            } catch (IOException e) {
                throw new RuntimeIOException(e);
            }
        }

        /* (non-Javadoc)
        * @see java.util.Iterator#remove()
        */
        public void remove() {
            try {
                i.remove();
            } catch (IOException e) {
                throw new RuntimeIOException(e);
            }
        }

    };
}

From source file:org.apache.phoenix.util.PhoenixRuntime.java

/**
 * Get the list of uncommitted KeyValues for the connection. Currently used to write an
 * Phoenix-compliant HFile from a map/reduce job.
 * @param conn an open JDBC connection/*  w w  w.ja v a2s.  c  o m*/
 * @return the list of HBase mutations for uncommitted data
 * @throws SQLException
 */
public static Iterator<Pair<byte[], List<KeyValue>>> getUncommittedDataIterator(Connection conn,
        boolean includeMutableIndexes) throws SQLException {
    final PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
    final Iterator<Pair<byte[], List<Mutation>>> iterator = pconn.getMutationState()
            .toMutations(includeMutableIndexes);
    return new Iterator<Pair<byte[], List<KeyValue>>>() {

        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public Pair<byte[], List<KeyValue>> next() {
            Pair<byte[], List<Mutation>> pair = iterator.next();
            List<KeyValue> keyValues = Lists.newArrayListWithExpectedSize(pair.getSecond().size() * 5); // Guess-timate 5 key values per row
            for (Mutation mutation : pair.getSecond()) {
                for (List<Cell> keyValueList : mutation.getFamilyCellMap().values()) {
                    for (Cell keyValue : keyValueList) {
                        keyValues.add(org.apache.hadoop.hbase.KeyValueUtil.ensureKeyValue(keyValue));
                    }
                }
            }
            Collections.sort(keyValues, pconn.getKeyValueBuilder().getKeyValueComparator());
            return new Pair<byte[], List<KeyValue>>(pair.getFirst(), keyValues);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

    };
}

From source file:Base64InputStream.java

/**
 * Returns an iterator over this buffer's elements.
 *
 * @return an iterator over this buffer's elements
 *///from w w w. j a v  a  2s  . co m
public Iterator<Byte> iterator() {
    return new Iterator<Byte>() {

        private int index = head;
        private int lastReturnedIndex = -1;

        public boolean hasNext() {
            return index != tail;

        }

        public Byte next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            lastReturnedIndex = index;
            index = increment(index);
            return new Byte(buffer[lastReturnedIndex]);
        }

        public void remove() {
            if (lastReturnedIndex == -1) {
                throw new IllegalStateException();
            }

            // First element can be removed quickly
            if (lastReturnedIndex == head) {
                UnboundedFifoByteBuffer.this.remove();
                lastReturnedIndex = -1;
                return;
            }

            // Other elements require us to shift the subsequent elements
            int i = lastReturnedIndex + 1;
            while (i != tail) {
                if (i >= buffer.length) {
                    buffer[i - 1] = buffer[0];
                    i = 0;
                } else {
                    buffer[i - 1] = buffer[i];
                    i++;
                }
            }

            lastReturnedIndex = -1;
            tail = decrement(tail);
            buffer[tail] = 0;
            index = decrement(index);
        }

    };
}

From source file:oculus.aperture.common.JSONProperties.java

@Override
public Iterable<Properties> getPropertiesSets(String key) {
    try {/*w w  w.j a  v a  2 s . c  o  m*/
        final JSONArray array = obj.getJSONArray(key);

        return new Iterable<Properties>() {
            @Override
            public Iterator<Properties> iterator() {
                return new Iterator<Properties>() {
                    private final int n = array.length();
                    private int i = 0;

                    @Override
                    public boolean hasNext() {
                        return n > i;
                    }

                    @Override
                    public Properties next() {
                        try {
                            return (n > i) ? new JSONProperties(array.getJSONObject(i++)) : null;
                        } catch (JSONException e) {
                            return null;
                        }
                    }

                    @Override
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }
        };

    } catch (JSONException e) {
        return EmptyIterable.instance();
    }
}

From source file:com.addthis.hydra.data.io.DiskBackedList2.java

public Iterator<byte[]> getEncodedData() {
    return new Iterator<byte[]>() {
        final Iterator<K> iter = listIterator();

        @Override//from w w  w  . j  a v  a 2 s .c o  m
        public boolean hasNext() {
            return iter.hasNext();
        }

        @Override
        public byte[] next() {
            try {
                return codec.encode(iter.next());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:com.github.jsonj.JsonArray.java

@Override
public Iterator<JsonElement> iterator() {
    if (immutable) {
        Iterator<JsonElement> it = super.iterator();
        return new Iterator<JsonElement>() {

            @Override/* www .ja v a 2  s .c om*/
            public boolean hasNext() {
                return it.hasNext();
            }

            @Override
            public JsonElement next() {
                return it.next();
            }

            @Override
            public void remove() {
                throw new IllegalStateException("object is immutable");
            }
        };
    } else {
        return super.iterator();
    }
}