001/* 002 * Java Genetic Algorithm Library (jenetics-7.2.0). 003 * Copyright (c) 2007-2023 Franz Wilhelmstötter 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 * Author: 018 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com) 019 */ 020package io.jenetics.internal.util; 021 022import static java.util.Objects.requireNonNull; 023 024import java.util.Comparator; 025import java.util.Iterator; 026import java.util.Optional; 027import java.util.Spliterator; 028import java.util.function.BiConsumer; 029import java.util.function.BiFunction; 030import java.util.function.BinaryOperator; 031import java.util.function.Consumer; 032import java.util.function.Function; 033import java.util.function.IntFunction; 034import java.util.function.Predicate; 035import java.util.function.Supplier; 036import java.util.function.ToDoubleFunction; 037import java.util.function.ToIntFunction; 038import java.util.function.ToLongFunction; 039import java.util.stream.Collector; 040import java.util.stream.DoubleStream; 041import java.util.stream.IntStream; 042import java.util.stream.LongStream; 043import java.util.stream.Stream; 044 045/** 046 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a> 047 * @since 3.0 048 * @version 4.1 049 */ 050public abstract class StreamProxy<T> implements Stream<T> { 051 052 private final Stream<T> _self; 053 054 protected StreamProxy(final Stream<T> self) { 055 _self = requireNonNull(self); 056 } 057 058 @Override 059 public Stream<T> limit(final long maxSize) { 060 return _self.limit(maxSize); 061 } 062 063 @Override 064 public Stream<T> 065 filter(final Predicate<? super T> predicate) { 066 return _self.filter(predicate); 067 } 068 069 public boolean 070 allMatch(final Predicate<? super T> predicate) { 071 return _self.allMatch(predicate); 072 } 073 074 @Override 075 public boolean 076 anyMatch(final Predicate<? super T> predicate) { 077 return _self.anyMatch(predicate); 078 } 079 080 @Override 081 public <R, A> R 082 collect(final Collector<? super T, A, R> collector) { 083 return _self.collect(collector); 084 } 085 086 @Override 087 public <R> R collect( 088 final Supplier<R> supplier, 089 final BiConsumer<R, ? super T> accumulator, 090 final BiConsumer<R, R> combiner 091 ) { 092 return _self.collect(supplier, accumulator, combiner); 093 } 094 095 @Override 096 public long count() { 097 return _self.count(); 098 } 099 100 @Override 101 public Stream<T> distinct() { 102 return _self.distinct(); 103 } 104 105 @Override 106 public Optional<T> findAny() { 107 return _self.findAny(); 108 } 109 110 @Override 111 public Optional<T> findFirst() { 112 return _self.findFirst(); 113 } 114 115 @Override 116 public <R> Stream<R> flatMap( 117 final Function<? super T, ? extends Stream<? extends R>> mapper 118 ) { 119 return _self.flatMap(mapper); 120 } 121 122 @Override 123 public DoubleStream flatMapToDouble( 124 final Function<? super T, ? extends DoubleStream> mapper 125 ) { 126 return _self.flatMapToDouble(mapper); 127 } 128 129 @Override 130 public IntStream flatMapToInt( 131 final Function<? super T, ? extends IntStream> mapper 132 ) { 133 return _self.flatMapToInt(mapper); 134 } 135 136 @Override 137 public LongStream flatMapToLong( 138 final Function<? super T, ? extends LongStream> mapper 139 ) { 140 return _self.flatMapToLong(mapper); 141 } 142 143 @Override 144 public void forEach(final Consumer<? super T> action) { 145 _self.forEach(action); 146 } 147 148 @Override 149 public void forEachOrdered(final Consumer<? super T> action) { 150 _self.forEachOrdered(action); 151 } 152 153 @Override 154 public <R> Stream<R> map( 155 final Function<? super T, ? extends R> mapper 156 ) { 157 return _self.map(mapper); 158 } 159 160 @Override 161 public DoubleStream mapToDouble( 162 final ToDoubleFunction<? super T> mapper 163 ) { 164 return _self.mapToDouble(mapper); 165 } 166 167 @Override 168 public IntStream mapToInt( 169 final ToIntFunction<? super T> mapper 170 ) { 171 return _self.mapToInt(mapper); 172 } 173 174 @Override 175 public LongStream mapToLong( 176 final ToLongFunction<? super T> mapper 177 ) { 178 return _self.mapToLong(mapper); 179 } 180 181 @Override 182 public Optional<T> max( 183 final Comparator<? super T> comparator 184 ) { 185 return _self.max(comparator); 186 } 187 188 @Override 189 public Optional<T> min( 190 final Comparator<? super T> comparator 191 ) { 192 return _self.min(comparator); 193 } 194 195 @Override 196 public boolean noneMatch( 197 final Predicate<? super T> predicate 198 ) { 199 return _self.noneMatch(predicate); 200 } 201 202 @Override 203 public Stream<T> peek( 204 final Consumer<? super T> action 205 ) { 206 return _self.peek(action); 207 } 208 209 @Override 210 public Optional<T> reduce( 211 final BinaryOperator<T> accumulator 212 ) { 213 return _self.reduce(accumulator); 214 } 215 216 @Override 217 public T reduce( 218 final T identity, 219 final BinaryOperator<T> accumulator 220 ) { 221 return _self.reduce(identity, accumulator); 222 } 223 224 @Override 225 public <U> U reduce( 226 final U identity, 227 final BiFunction<U, ? super T, U> accumulator, 228 final BinaryOperator<U> combiner 229 ) { 230 return _self.reduce(identity, accumulator, combiner); 231 } 232 233 @Override 234 public Stream<T> skip(final long n) { 235 return _self.skip(n); 236 } 237 238 @Override 239 public Stream<T> sorted() { 240 return _self.sorted(); 241 } 242 243 @Override 244 public Stream<T> sorted( 245 final Comparator<? super T> comparator 246 ) { 247 return _self.sorted(comparator); 248 } 249 250 @Override 251 public Object[] toArray() { 252 return _self.toArray(); 253 } 254 255 @Override 256 public <A> A[] toArray(IntFunction<A[]> generator) { 257 return _self.toArray(generator); 258 } 259 260 @Override 261 public void close() { 262 _self.close(); 263 } 264 265 @Override 266 public boolean isParallel() { 267 return _self.isParallel(); 268 } 269 270 @Override 271 public Iterator<T> iterator() { 272 return _self.iterator(); 273 } 274 275 @Override 276 public Stream<T> onClose(final Runnable closeHandler) { 277 return _self.onClose(closeHandler); 278 } 279 280 @Override 281 public Stream<T> parallel() { 282 return _self.parallel(); 283 } 284 285 @Override 286 public Stream<T> sequential() { 287 return _self.sequential(); 288 } 289 290 @Override 291 public Spliterator<T> spliterator() { 292 return _self.spliterator(); 293 } 294 295 @Override 296 public Stream<T> unordered() { 297 return _self.unordered(); 298 } 299 300 @Override 301 public Stream<T> takeWhile(final Predicate<? super T> predicate) { 302 return _self.takeWhile(predicate); 303 } 304 305 @Override 306 public Stream<T> dropWhile(final Predicate<? super T> predicate) { 307 return _self.dropWhile(predicate); 308 } 309 310}