/** Return the keeps the user is allowed to access */ @RequestMapping(method = RequestMethod.GET) public ResponseEntity<ArrayNode> findAll() { List<Keep> keeps = new ArrayList<Keep>(); Iterator<Keep> keepsIt = keepDAO.findAll().iterator(); keepsIt.forEachRemaining(keeps::add); ArrayNode keepsJ = KeepMapper.toJson(keeps); return new ResponseEntity<ArrayNode>(keepsJ, HttpStatus.OK); }
public static void main(String[] args) { Collection<String> names = new ArrayList<>(); names.add("XML"); names.add("HTML"); names.add("CSS"); // sout(names); names.remove("CSS"); // removes CSS // sout(names.size()); Iterator<String> nameIterator = names.iterator(); while (nameIterator.hasNext()) { sout(nameIterator.next()); // nameIterator.remove(); // Almost same result } // iterator gets sucked // so we have to renew iterator nameIterator = names.iterator(); newLine(); nameIterator.forEachRemaining(System.out::println); }
private static void addAll(Graph srcGraph, Graph dstGraph) { Iterator<Triple> triples = srcGraph.find(Node.ANY, Node.ANY, Node.ANY); triples.forEachRemaining(dstGraph::add); }
default Mappings parseLines(Iterator<String> lines) { LineProcessor<Mappings> lineProcessor = createLineProcessor(); lines.forEachRemaining(Exceptions.sneakyThrowing(lineProcessor::processLine)); return lineProcessor.getResult(); }
private MultiException(int size, Iterator<? extends Throwable> exceptions) { super( size + " exceptions were thrown. The first exception is listed as a cause.", exceptions.next()); exceptions.forEachRemaining(this::addSuppressed); }
public static void main(String[] args) { // 创建集合、添加元素的代码与前一个程序相同 Collection books = new HashSet(); books.add("轻量级Java EE企业应用实战"); books.add("疯狂Java讲义"); books.add("疯狂Android讲义"); // 获取books集合对应的迭代器 Iterator it = books.iterator(); // 使用Lambda表达式(目标类型是Comsumer)来遍历集合元素 it.forEachRemaining(obj -> System.out.println("迭代集合元素:" + obj)); }
@Override public ClosureCreationStruct<V> expand(final ListStruct form, final Environment environment) { final Iterator<LispStruct> iterator = form.iterator(); iterator.next(); // Closure Expander SYMBOL if (!iterator.hasNext()) { throw new ProgramErrorException( expanderName + ": Incorrect number of arguments: 0. Expected at least 1 argument."); } final LispStruct first = iterator.next(); if (!(first instanceof ListStruct)) { throw new TypeErrorException(expanderName + ": PARAMETER-LIST must be a List. Got: " + first); } final ListStruct parameters = (ListStruct) first; final Environment closureEnvironment = new Environment(environment); final List<LispStruct> forms = new ArrayList<>(); iterator.forEachRemaining(forms::add); final BodyProcessingResult bodyProcessingResult = bodyWithDeclaresAnalyzer.analyze(forms); final ListStruct fullDeclaration = LispStructFactory.toProperList(bodyProcessingResult.getDeclares()); final DeclareStruct declare = declareExpander.expand(fullDeclaration, closureEnvironment); final List<V> vars = parameters .stream() .map(e -> getVar(e, declare, closureEnvironment)) .collect(Collectors.toList()); final List<SpecialDeclarationStruct> specialDeclarations = declare.getSpecialDeclarations(); specialDeclarations .stream() .map(SpecialDeclarationStruct::getVar) .map(Binding::new) .forEach(closureEnvironment::addDynamicBinding); final List<LispStruct> bodyForms = bodyProcessingResult.getBodyForms(); final List<LispStruct> analyzedBodyForms = bodyForms .stream() .map(e -> formAnalyzer.analyze(e, closureEnvironment)) .collect(Collectors.toList()); return getClosureCreationStruct(vars, new PrognStruct(analyzedBodyForms), closureEnvironment); }