001 /* 002 * Copyright 2002-2004 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.rules.closure.support; 017 018 import java.io.Serializable; 019 import java.util.Collection; 020 import java.util.Iterator; 021 022 import org.springframework.rules.closure.Closure; 023 024 /** 025 * Convenience implementation for the closure interface. Extends 026 * AlgorithmsAccessorSupport for convenient execution of various data structure 027 * processing algorithms taking advantage of closures and constraints. 028 * 029 * @author Keith Donald 030 */ 031 public abstract class AbstractClosure extends AlgorithmsAccessor implements Closure, Serializable { 032 033 /** 034 * Execute this closure for each element in the provided collection. 035 * 036 * @param collection The collection 037 */ 038 public final void forEach(Collection collection) { 039 forEach(collection, this); 040 } 041 042 /** 043 * Execute this closure for each element traversable via the provided 044 * iterator. 045 * 046 * @param it The iterator 047 */ 048 public final void forEach(Iterator it) { 049 forEach(it, this); 050 } 051 }