001/*
002 * ============================================================================
003 * Copyright © 2002-2025 by Thomas Thrien.
004 * All Rights Reserved.
005 * ============================================================================
006 * Licensed to the public under the agreements of the GNU Lesser General Public
007 * License, version 3.0 (the "License"). You may obtain a copy of the License at
008 *
009 *      http://www.gnu.org/licenses/lgpl.html
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, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017
018package org.tquadrat.foundation.stream;
019
020import static org.apiguardian.api.API.Status.STABLE;
021import static org.tquadrat.foundation.lang.Objects.requireNonNullArgument;
022
023import java.util.Comparator;
024import java.util.Iterator;
025import java.util.Optional;
026import java.util.Spliterator;
027import java.util.function.BiConsumer;
028import java.util.function.BiFunction;
029import java.util.function.BinaryOperator;
030import java.util.function.Consumer;
031import java.util.function.Function;
032import java.util.function.IntFunction;
033import java.util.function.Predicate;
034import java.util.function.Supplier;
035import java.util.function.ToDoubleFunction;
036import java.util.function.ToIntFunction;
037import java.util.function.ToLongFunction;
038import java.util.stream.Collector;
039import java.util.stream.DoubleStream;
040import java.util.stream.IntStream;
041import java.util.stream.LongStream;
042import java.util.stream.Stream;
043
044import org.apiguardian.api.API;
045import org.tquadrat.foundation.annotation.ClassVersion;
046import org.tquadrat.foundation.annotation.MountPoint;
047import org.tquadrat.foundation.annotation.NotRecord;
048
049/**
050 *  This class allows to intercept the calls to the methods of
051 *  {@link Stream}. The default implementations of the methods will just
052 *  delegate to the wrapped stream.
053 *
054 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
055 *  @version $Id: StreamAdapter.java 1151 2025-10-01 21:32:15Z tquadrat $
056 *  @since 0.0.7
057 *
058 *  @param  <T> The type of the stream's elements.
059 *
060 *  @UMLGraph.link
061 */
062@ClassVersion( sourceVersion = "$Id: StreamAdapter.java 1151 2025-10-01 21:32:15Z tquadrat $" )
063@API( status = STABLE, since = "0.0.7" )
064@NotRecord
065public class StreamAdapter<T> implements Stream<T>
066{
067        /*------------*\
068    ====** Attributes **=======================================================
069        \*------------*/
070    /**
071     *  The wrapped stream.
072     */
073    private final Stream<T> m_Wrapped;
074
075        /*--------------*\
076    ====** Constructors **=====================================================
077        \*--------------*/
078    /**
079     *  Creates a new {@code StreamAdapter} instance.
080     *
081     *  @param  wrapped The stream that is wrapped by this adapter.
082     */
083    public StreamAdapter( final Stream<T> wrapped )
084    {
085        m_Wrapped = requireNonNullArgument( wrapped, "wrapped" );
086    }   //  StreamAdapter()
087
088        /*---------*\
089    ====** Methods **==========================================================
090        \*---------*/
091    /**
092     *  {@inheritDoc}
093     */
094    @MountPoint
095    @Override
096    public boolean allMatch( final Predicate<? super T> predicate ) { return m_Wrapped.allMatch( predicate ); }
097
098    /**
099     *  {@inheritDoc}
100     */
101    @MountPoint
102    @Override
103    public boolean anyMatch( final Predicate<? super T> predicate ) { return m_Wrapped.anyMatch( predicate ); }
104
105    /**
106     *  {@inheritDoc}
107     */
108    @MountPoint
109    @Override
110    public void close() { m_Wrapped.close(); }
111
112    /**
113     *  {@inheritDoc}
114     */
115    @MountPoint
116    @Override
117    public <R,A> R collect( final Collector<? super T,A,R> collector ) { return m_Wrapped.collect( collector ); }
118
119    /**
120     *  {@inheritDoc}
121     */
122    @MountPoint
123    @Override
124    public <R> R collect( final Supplier<R> supplier, final BiConsumer<R,? super T> accumulator, final BiConsumer<R,R> combiner ) { return m_Wrapped.collect( supplier, accumulator, combiner ); }
125
126    /**
127     *  {@inheritDoc}
128     */
129    @MountPoint
130    @Override
131    public long count() { return m_Wrapped.count(); }
132
133    /**
134     *  {@inheritDoc}
135     */
136    @MountPoint
137    @Override
138    public Stream<T> distinct() { return m_Wrapped.distinct(); }
139
140    /**
141     *  {@inheritDoc}
142     */
143    @MountPoint
144    @Override
145    public Stream<T> dropWhile( final Predicate<? super T> predicate ) { return m_Wrapped.dropWhile( predicate ); }
146
147    /**
148     *  {@inheritDoc}
149     */
150    @MountPoint
151    @Override
152    public Stream<T> filter( final Predicate<? super T> predicate ) { return m_Wrapped.filter( predicate ); }
153
154    /**
155     *  {@inheritDoc}
156     */
157    @MountPoint
158    @Override
159    public Optional<T> findAny() { return m_Wrapped.findAny(); }
160
161    /**
162     *  {@inheritDoc}
163     */
164    @MountPoint
165    @Override
166    public Optional<T> findFirst() { return m_Wrapped.findFirst(); }
167
168    /**
169     *  {@inheritDoc}
170     */
171    @MountPoint
172    @Override
173    public <R> Stream<R> flatMap( final Function<? super T,? extends Stream<? extends R>> mapper ) { return m_Wrapped.flatMap( mapper ); }
174
175    /**
176     *  {@inheritDoc}
177     */
178    @MountPoint
179    @Override
180    public DoubleStream flatMapToDouble( final Function<? super T,? extends DoubleStream> mapper ) { return m_Wrapped.flatMapToDouble( mapper ); }
181
182    /**
183     *  {@inheritDoc}
184     */
185    @MountPoint
186    @Override
187    public IntStream flatMapToInt( final Function<? super T,? extends IntStream> mapper ) { return m_Wrapped.flatMapToInt( mapper ); }
188
189    /**
190     *  {@inheritDoc}
191     */
192    @MountPoint
193    @Override
194    public LongStream flatMapToLong( final Function<? super T,? extends LongStream> mapper ) { return m_Wrapped.flatMapToLong( mapper ); }
195
196    /**
197     *  {@inheritDoc}
198     */
199    @MountPoint
200    @Override
201    public void forEach( final Consumer<? super T> action ) { m_Wrapped.forEach( action ); }
202
203    /**
204     *  {@inheritDoc}
205     */
206    @MountPoint
207    @Override
208    public void forEachOrdered( final Consumer<? super T> action ) { m_Wrapped.forEachOrdered( action ); }
209
210    /**
211     *  {@inheritDoc}
212     */
213    @MountPoint
214    @Override
215    public boolean isParallel() { return m_Wrapped.isParallel(); }
216
217    /**
218     *  {@inheritDoc}
219     */
220    @MountPoint
221    @Override
222    public Iterator<T> iterator() { return m_Wrapped.iterator(); }
223
224    /**
225     *  {@inheritDoc}
226     */
227    @MountPoint
228    @Override
229    public Stream<T> limit( final long maxSize ) { return m_Wrapped.limit( maxSize ); }
230
231    /**
232     *  {@inheritDoc}
233     */
234    @MountPoint
235    @Override
236    public <R> Stream<R> map( final Function<? super T,? extends R> mapper ) { return m_Wrapped.map( mapper ); }
237
238    /**
239     *  {@inheritDoc}
240     */
241    @MountPoint
242    @Override
243    public DoubleStream mapToDouble( final ToDoubleFunction<? super T> mapper ) { return m_Wrapped.mapToDouble( mapper ); }
244
245    /**
246     *  {@inheritDoc}
247     */
248    @MountPoint
249    @Override
250    public IntStream mapToInt( final ToIntFunction<? super T> mapper ) { return m_Wrapped.mapToInt( mapper ); }
251
252    /**
253     *  {@inheritDoc}
254     */
255    @MountPoint
256    @Override
257    public LongStream mapToLong( final ToLongFunction<? super T> mapper ) { return m_Wrapped.mapToLong( mapper ); }
258
259    /**
260     *  {@inheritDoc}
261     */
262    @MountPoint
263    @Override
264    public Optional<T> max( final Comparator<? super T> comparator ) { return m_Wrapped.max( comparator ); }
265
266    /**
267     *  {@inheritDoc}
268     */
269    @MountPoint
270    @Override
271    public Optional<T> min( final Comparator<? super T> comparator ) { return m_Wrapped.min( comparator ); }
272
273    /**
274     *  {@inheritDoc}
275     */
276    @MountPoint
277    @Override
278    public boolean noneMatch( final Predicate<? super T> predicate ) { return m_Wrapped.noneMatch( predicate ); }
279
280    /**
281     *  {@inheritDoc}
282     */
283    @MountPoint
284    @Override
285    public Stream<T> onClose( final Runnable closeHandler ) { return m_Wrapped.onClose( closeHandler ); }
286
287    /**
288     *  {@inheritDoc}
289     */
290    @MountPoint
291    @Override
292    public Stream<T> parallel() { return m_Wrapped.parallel(); }
293
294    /**
295     *  {@inheritDoc}
296     */
297    @MountPoint
298    @Override
299    public Stream<T> peek( final Consumer<? super T> action ) { return m_Wrapped.peek( action ); }
300
301    /**
302     *  {@inheritDoc}
303     */
304    @MountPoint
305    @Override
306    public Optional<T> reduce( final BinaryOperator<T> accumulator ) { return m_Wrapped.reduce( accumulator ); }
307
308    /**
309     *  {@inheritDoc}
310     */
311    @MountPoint
312    @Override
313    public T reduce( final T identity, final BinaryOperator<T> accumulator ) { return m_Wrapped.reduce( identity, accumulator ); }
314
315    /**
316     *  {@inheritDoc}
317     */
318    @MountPoint
319    @Override
320    public <U> U reduce( final U identity, final BiFunction<U,? super T,U> accumulator, final BinaryOperator<U> combiner ) { return m_Wrapped.reduce( identity, accumulator, combiner ); }
321
322    /**
323     *  {@inheritDoc}
324     */
325    @MountPoint
326    @Override
327    public Stream<T> sequential() { return m_Wrapped.sequential(); }
328
329    /**
330     *  {@inheritDoc}
331     */
332    @MountPoint
333    @Override
334    public Stream<T> skip( final long n ) { return m_Wrapped.skip( n ); }
335
336    /**
337     *  {@inheritDoc}
338     */
339    @MountPoint
340    @Override
341    public Stream<T> sorted() { return m_Wrapped.sorted(); }
342
343    /**
344     *  {@inheritDoc}
345     */
346    @MountPoint
347    @Override
348    public Stream<T> sorted( final Comparator<? super T> comparator ) { return m_Wrapped.sorted( comparator ); }
349
350    /**
351     *  {@inheritDoc}
352     */
353    @MountPoint
354    @Override
355    public Spliterator<T> spliterator() { return m_Wrapped.spliterator(); }
356
357    /**
358     *  {@inheritDoc}
359     */
360    @MountPoint
361    @Override
362    public Stream<T> takeWhile( final Predicate<? super T> predicate ) { return m_Wrapped.takeWhile( predicate ); }
363
364    /**
365     *  {@inheritDoc}
366     */
367    @MountPoint
368    @Override
369    public Object [] toArray() { return m_Wrapped.toArray(); }
370
371    /**
372     *  {@inheritDoc}
373     */
374    @MountPoint
375    @Override
376    public <A> A [] toArray( final IntFunction<A []> generator ) { return m_Wrapped.toArray( generator ); }
377
378    /**
379     *  {@inheritDoc}
380     */
381    @MountPoint
382    @Override
383    public Stream<T> unordered() { return m_Wrapped.unordered(); }
384}
385//  class StreamAdapter
386
387/*
388 *  End of File
389 */