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:org.jasper.collectionspace.smk.datasource.JsonCSDataSource.java

public void moveFirst() throws JRException {
    if (jsonTree == null || jsonTree.isMissingNode()) {
        throw new JRException("No JSON data to operate on!");
    }/*from   ww w  .  ja  v  a  2s  . c  o  m*/

    currentJsonNode = null;
    JsonNode result = getJsonData(jsonTree, selectExpression);
    if (result != null && result.isObject()) {
        //System.out.println("result is object");
        final List<JsonNode> list = new ArrayList<JsonNode>();
        list.add(result);
        jsonNodesIterator = new Iterator<JsonNode>() {
            private int count = -1;

            public void remove() {
                list.remove(count);
            }

            public JsonNode next() {
                count++;
                return list.get(count);
            }

            public boolean hasNext() {
                return count < list.size() - 1;
            }
        };
    } else if (result != null && result.isArray()) {
        jsonNodesIterator = result.getElements();
    }
}

From source file:act.installer.brenda.SQLConnection.java

private Iterator<BrendaRxnEntry> runSPQuery(final boolean isNatural) throws SQLException {
    String query = isNatural ? QUERY_NATURAL_SUBSTRATES_PRODUCTS : QUERY_SUBSTRATES_PRODUCTS;
    final PreparedStatement stmt = brendaConn.prepareStatement(query);
    final ResultSet results = stmt.executeQuery();

    return new Iterator<BrendaRxnEntry>() {
        @Override//from www  .  ja v  a2s. co  m
        public boolean hasNext() {
            return hasNextHelper(results, stmt);
        }

        @Override
        public BrendaRxnEntry next() {
            try {
                results.next();
                Integer literatureSubstrates = results.getInt(4);

                if (results.wasNull()) {
                    literatureSubstrates = null;
                }
                BrendaRxnEntry sp = new BrendaRxnEntry(results.getString(1), results.getString(2),
                        results.getString(3),
                        literatureSubstrates == null ? null : literatureSubstrates.toString(),
                        results.getString(5), results.getString(6), results.getString(7), results.getInt(8),
                        isNatural);
                return sp;
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }

        }
    };
}

From source file:MicroMap.java

/**
 * @see java.util.Map#entrySet()/*w  ww .ja v  a  2  s  .c o m*/
 */
public Set<Entry<K, V>> entrySet() {
    return new AbstractSet<Entry<K, V>>() {
        @Override
        public Iterator<Entry<K, V>> iterator() {
            return new Iterator<Entry<K, V>>() {
                public boolean hasNext() {
                    return index < MicroMap.this.size();
                }

                public Entry<K, V> next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    index++;

                    return new Map.Entry<K, V>() {
                        public K getKey() {
                            return key;
                        }

                        public V getValue() {
                            return value;
                        }

                        public V setValue(final V value) {
                            final V oldValue = MicroMap.this.value;

                            MicroMap.this.value = value;

                            return oldValue;
                        }
                    };
                }

                public void remove() {
                    clear();
                }

                int index = 0;
            };
        }

        @Override
        public int size() {
            return MicroMap.this.size();
        }
    };
}

From source file:com.trenako.values.DeliveryDate.java

private static Iterable<Integer> inverseRange(final int start, final int end) {
    return new Iterable<Integer>() {
        @Override//from  www  . j  av a  2 s.  c  o m
        public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                private int current = end;

                @Override
                public boolean hasNext() {
                    return current >= start;
                }

                @Override
                public Integer next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    int n = current;
                    current--;
                    return n;
                }

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

From source file:com.atomicleopard.thundr.ftp.FtpSession.java

/**
 * List remote contents in batches - includes both files and directories
 * /*from   www . j  a v  a 2s .c  o m*/
 * @param directory
 * @param batchSize
 * @return
 */
public Iterable<FTPFile[]> listBatch(final String directory, final int batchSize) {
    return timeLogAndCatch("List files in batch", new Callable<Iterable<FTPFile[]>>() {
        @Override
        public Iterable<FTPFile[]> call() throws Exception {
            final FTPListParseEngine engine = preparedClient.initiateListParsing(directory);
            return new Iterable<FTPFile[]>() {
                @Override
                public Iterator<FTPFile[]> iterator() {
                    return new Iterator<FTPFile[]>() {

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

                        @Override
                        public FTPFile[] next() {
                            return engine.getNext(batchSize);
                        }

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

From source file:SortUtils.java

/**
 * Answer iterator, which iterates over specified data array according
 * to the specified permutation, that is
 * <code>data[p[0]],..,data[p[data.length-1]]</code>
 */// w  w w  .  j av  a  2  s.  c om
public static Iterator getIterator(final int[] p, final Object[] data) {
    return new Iterator() {
        int pos = 0;

        public boolean hasNext() {
            return pos < data.length;
        }

        public Object next() {
            return data[p[pos++]];
        }

        public void remove() {
            throw new UnsupportedOperationException("Cannot remove from immutable iterator!");
        }
    };
}

From source file:org.apache.hadoop.yarn.server.api.records.impl.pb.NodeStatusPBImpl.java

private synchronized void addContainerMemoryStatusesToProto() {
    maybeInitBuilder();//from www. j a v  a 2  s.c o  m
    builder.clearContainerMemoryStatuses();
    if (containerMemoryStatuses == null)
        return;
    Iterable<ContainerSqueezeUnitProto> iterable = new Iterable<ContainerSqueezeUnitProto>() {
        @Override
        public Iterator<ContainerSqueezeUnitProto> iterator() {
            return new Iterator<ContainerSqueezeUnitProto>() {

                Iterator<ContainerSqueezeUnit> iter = containerMemoryStatuses.iterator();

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

                @Override
                public ContainerSqueezeUnitProto next() {
                    return convertToProtoFormat(iter.next());
                }

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

                }
            };

        }
    };
    builder.addAllContainerMemoryStatuses(iterable);
}

From source file:com.intelligentsia.dowsers.entity.store.fs.FileEntityStore.java

@Override
public Iterable<Reference> find(final Class<?> expectedType) throws NullPointerException {
    final Collection<File> files = FileUtils.listFiles(root, new RegexFileFilter("^(.*?)"),
            DirectoryFileFilter.DIRECTORY);
    final Iterator<File> iterator = files.iterator();
    return new Iterable<Reference>() {

        @Override// w ww.  java  2s  .c o  m
        public Iterator<Reference> iterator() {
            return new Iterator<Reference>() {

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

                @Override
                public Reference next() {
                    return Reference.newReference(expectedType, iterator.next().getName());
                }

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

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

@Override
public Iterable<String> getStrings(String key) {
    try {//ww  w .jav  a2  s  .  c  om
        final JSONArray array = obj.getJSONArray(key);

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

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

                    @Override
                    public String next() {
                        try {
                            return (n > i) ? array.getString(i++) : null;
                        } catch (JSONException e) {
                            return null;
                        }
                    }

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

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

From source file:org.apache.bookkeeper.mledger.impl.ManagedCursorContainer.java

@Override
public Iterator<ManagedCursor> iterator() {
    final Iterator<Map.Entry<String, Item>> it = cursors.entrySet().iterator();
    return new Iterator<ManagedCursor>() {
        @Override//w ww. j a v a2s .  co m
        public boolean hasNext() {
            return it.hasNext();
        }

        @Override
        public ManagedCursor next() {
            return it.next().getValue().cursor;
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Cannot remove ManagedCursor form container");
        }
    };
}