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.util.Collection; 019 import java.util.Iterator; 020 021 import org.springframework.rules.closure.Closure; 022 import org.springframework.rules.constraint.Constraint; 023 024 /** 025 * Algorithms accessor support class, for convenient extending by subclasses. 026 * 027 * @author Keith Donald 028 */ 029 public abstract class AlgorithmsAccessor { 030 /** 031 * @return Algorithms instance. 032 */ 033 protected Algorithms getAlgorithms() { 034 return Algorithms.instance(); 035 } 036 037 /** 038 * @see Algorithms#findFirst(Collection, Constraint) 039 */ 040 public Object findFirst(Collection collection, Constraint constraint) { 041 return getAlgorithms().findFirst(collection, constraint); 042 } 043 044 /** 045 * @see Algorithms#findFirst(Iterator, Constraint) 046 */ 047 public Object findFirst(Iterator it, Constraint constraint) { 048 return getAlgorithms().findFirst(it, constraint); 049 } 050 051 /** 052 * @see Algorithms#findAll(Collection, org.springframework.rules.constraint.Constraint) 053 */ 054 public Collection findAll(Collection collection, Constraint constraint) { 055 return getAlgorithms().findAll(collection, constraint); 056 } 057 058 /** 059 * @see Algorithms#findAll(Iterator, org.springframework.rules.constraint.Constraint) 060 */ 061 public Collection findAll(Iterator it, Constraint constraint) { 062 return getAlgorithms().findAll(it, constraint); 063 } 064 065 /** 066 * @see Algorithms#allTrue(Collection, Constraint) 067 */ 068 public boolean allTrue(Collection collection, Constraint constraint) { 069 return getAlgorithms().allTrue(collection, constraint); 070 } 071 072 /** 073 * @see Algorithms#allTrue(Iterator, Constraint) 074 */ 075 public boolean allTrue(Iterator it, Constraint constraint) { 076 return getAlgorithms().allTrue(it, constraint); 077 } 078 079 /** 080 * @see Algorithms#anyTrue(Collection, org.springframework.rules.constraint.Constraint) 081 */ 082 public boolean anyTrue(Collection collection, Constraint constraint) { 083 return getAlgorithms().anyTrue(collection, constraint); 084 } 085 086 /** 087 * @see Algorithms#anyTrue(Iterator, Constraint) 088 */ 089 public boolean anyTrue(Iterator it, Constraint constraint) { 090 return getAlgorithms().anyTrue(it, constraint); 091 } 092 093 /** 094 * @see Algorithms#forEach(Collection, org.springframework.rules.closure.Closure) 095 */ 096 public void forEach(Collection collection, Closure closure) { 097 getAlgorithms().forEach(collection, closure); 098 } 099 100 /** 101 * @see Algorithms#forEach(Iterator, org.springframework.rules.closure.Closure) 102 */ 103 public void forEach(Iterator it, Closure closure) { 104 getAlgorithms().forEach(it, closure); 105 } 106 107 }