001/* 002 * ============================================================================ 003 * Copyright © 2014 by Alexis Cartier, Dominic Fox. 004 * All Rights Reserved. 005 * ============================================================================ 006 * The MIT License (MIT) 007 * 008 * Permission is hereby granted, free of charge, to any person obtaining a copy 009 * of this software and associated documentation files (the "Software"), to 010 * deal in the Software without restriction, including without limitation the 011 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 012 * sell copies of the Software, and to permit persons to whom the Software is 013 * furnished to do so, subject to the following conditions: 014 * 015 * The above copyright notice and this permission notice shall be included in 016 * all copies or substantial portions of the Software. 017 * 018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 020 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 023 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 024 * IN THE SOFTWARE. 025 */ 026 027package org.tquadrat.foundation.stream.internal; 028 029import static org.apiguardian.api.API.Status.INTERNAL; 030import static org.tquadrat.foundation.lang.Objects.requireNonNullArgument; 031 032import java.util.Comparator; 033import java.util.Iterator; 034import java.util.Map.Entry; 035import java.util.Optional; 036import java.util.Spliterator; 037import java.util.function.BiConsumer; 038import java.util.function.BiFunction; 039import java.util.function.BinaryOperator; 040import java.util.function.Consumer; 041import java.util.function.Function; 042import java.util.function.IntFunction; 043import java.util.function.Predicate; 044import java.util.function.Supplier; 045import java.util.function.ToDoubleFunction; 046import java.util.function.ToIntFunction; 047import java.util.function.ToLongFunction; 048import java.util.stream.Collector; 049import java.util.stream.DoubleStream; 050import java.util.stream.IntStream; 051import java.util.stream.LongStream; 052import java.util.stream.Stream; 053 054import org.apiguardian.api.API; 055import org.tquadrat.foundation.annotation.ClassVersion; 056import org.tquadrat.foundation.annotation.NotRecord; 057import org.tquadrat.foundation.stream.MapStream; 058 059/** 060 * The default implementation for 061 * {@link MapStream MapStream}. 062 * 063 * @param <K> The type of the map keys. 064 * @param <V> The type of the map values. 065 * 066 * @author Alexis Cartier (alexcrt) 067 * @author Dominic Fox 068 * @modified Thomas Thrien - thomas.thrien@tquadrat.org 069 * @version $Id: DefaultMapStream.java 1151 2025-10-01 21:32:15Z tquadrat $ 070 * @since 0.0.7 071 * 072 * @UMLGraph.link 073 */ 074@ClassVersion( sourceVersion = "$Id: DefaultMapStream.java 1151 2025-10-01 21:32:15Z tquadrat $" ) 075@API( status = INTERNAL, since = "0.0.7" ) 076@NotRecord 077public final class DefaultMapStream<K,V> implements MapStream<K,V> 078{ 079 /*------------*\ 080 ====** Attributes **======================================================= 081 \*------------*/ 082 /** 083 * The wrapped stream. 084 */ 085 private final Stream<Entry<K,V>> m_Delegate; 086 087 /*--------------*\ 088 ====** Constructors **===================================================== 089 \*--------------*/ 090 /** 091 * Creates a new {@code DefaultMapStream} instance from the provided 092 * stream. 093 * 094 * @param stream The stream to wrap. 095 */ 096 public DefaultMapStream( final Stream<Entry<K,V>> stream ) { m_Delegate = requireNonNullArgument( stream, "stream" ); } 097 098 /*---------*\ 099 ====** Methods **========================================================== 100 \*---------*/ 101 /** 102 * {@inheritDoc} 103 */ 104 @Override 105 public final boolean allMatch( final Predicate<? super Entry<K,V>> predicate ) { return m_Delegate.allMatch( predicate ); } 106 107 /** 108 * {@inheritDoc} 109 */ 110 @Override 111 public final boolean anyMatch( final Predicate<? super Entry<K,V>> predicate ) { return m_Delegate.anyMatch( predicate ); } 112 113 /** 114 * {@inheritDoc} 115 */ 116 @Override 117 public final void close() { m_Delegate.close(); } 118 119 /** 120 * {@inheritDoc} 121 */ 122 @Override 123 public final <R,A> R collect( final Collector<? super Entry<K,V>,A,R> collector ) { return m_Delegate.collect( collector ); } 124 125 /** 126 * {@inheritDoc} 127 */ 128 @Override 129 public final <R> R collect( final Supplier<R> supplier, final BiConsumer<R,? super Entry<K,V>> accumulator, final BiConsumer<R,R> combiner ) 130 { 131 return m_Delegate.collect( supplier, accumulator, combiner ); 132 } // collect() 133 134 /** 135 * {@inheritDoc} 136 */ 137 @Override 138 public final long count() { return m_Delegate.count(); } 139 140 /** 141 * {@inheritDoc} 142 */ 143 @Override 144 public final MapStream<K,V> distinct() { return new DefaultMapStream<>( m_Delegate.distinct() ); } 145 146 /** 147 * {@inheritDoc} 148 */ 149 @Override 150 public final MapStream<K,V> filter( final Predicate<? super Entry<K,V>> predicate ) 151 { 152 return new DefaultMapStream<>( m_Delegate.filter( predicate ) ); 153 } // filter() 154 155 /** 156 * {@inheritDoc} 157 */ 158 @Override 159 public final Optional<Entry<K,V>> findAny() { return m_Delegate.findAny(); } 160 161 /** 162 * {@inheritDoc} 163 */ 164 @Override 165 public final Optional<Entry<K,V>> findFirst() { return m_Delegate.findFirst(); } 166 167 /** 168 * {@inheritDoc} 169 */ 170 @Override 171 public final <R> Stream<R> flatMap( final Function<? super Entry<K,V>,? extends Stream<? extends R>> mapper ) 172 { 173 return m_Delegate.flatMap( mapper ); 174 } // flatMap() 175 176 /** 177 * {@inheritDoc} 178 */ 179 @Override 180 public final DoubleStream flatMapToDouble( final Function<? super Entry<K,V>,? extends DoubleStream> mapper ) 181 { 182 return m_Delegate.flatMapToDouble( mapper ); 183 } // flatMapToDouble() 184 185 /** 186 * {@inheritDoc} 187 */ 188 @Override 189 public final IntStream flatMapToInt( final Function<? super Entry<K,V>,? extends IntStream> mapper ) 190 { 191 return m_Delegate.flatMapToInt( mapper ); 192 } // flatMapToInt() 193 194 /** 195 * {@inheritDoc} 196 */ 197 @Override 198 public final LongStream flatMapToLong( final Function<? super Entry<K,V>,? extends LongStream> mapper ) 199 { 200 return m_Delegate.flatMapToLong( mapper ); 201 } // flatMapToLong() 202 203 /** 204 * {@inheritDoc} 205 */ 206 @Override 207 public final void forEach( final Consumer<? super Entry<K,V>> action ) { m_Delegate.forEach( action ); } 208 209 /** 210 * {@inheritDoc} 211 */ 212 @Override 213 public final void forEachOrdered( final Consumer<? super Entry<K,V>> action ) { m_Delegate.forEachOrdered( action ); } 214 215 /** 216 * {@inheritDoc} 217 */ 218 @Override 219 public final boolean isParallel() { return m_Delegate.isParallel(); } 220 221 /** 222 * {@inheritDoc} 223 */ 224 @Override 225 public final Iterator<Entry<K,V>> iterator() { return m_Delegate.iterator(); } 226 227 /** 228 * {@inheritDoc} 229 */ 230 @Override 231 public final MapStream<K,V> limit( final long limit ) { return new DefaultMapStream<>( m_Delegate.limit( limit ) ); } 232 233 /** 234 * {@inheritDoc} 235 */ 236 @Override 237 public final <R> Stream<R> map( final Function<? super Entry<K,V>,? extends R> mapper ) { return m_Delegate.map( mapper ); } 238 239 /** 240 * {@inheritDoc} 241 */ 242 @Override 243 public final DoubleStream mapToDouble( final ToDoubleFunction<? super Entry<K,V>> mapper ) { return m_Delegate.mapToDouble( mapper ); } 244 245 /** 246 * {@inheritDoc} 247 */ 248 @Override 249 public final IntStream mapToInt( final ToIntFunction<? super Entry<K,V>> mapper ) { return m_Delegate.mapToInt( mapper ); } 250 251 /** 252 * {@inheritDoc} 253 */ 254 @Override 255 public final LongStream mapToLong( final ToLongFunction<? super Entry<K,V>> mapper ) { return m_Delegate.mapToLong( mapper ); } 256 257 /** 258 * {@inheritDoc} 259 */ 260 @Override 261 public final Optional<Entry<K,V>> max( final Comparator<? super Entry<K,V>> comparator ) { return m_Delegate.max( comparator ); } 262 263 /** 264 * {@inheritDoc} 265 */ 266 @Override 267 public final Optional<Entry<K,V>> min( final Comparator<? super Entry<K,V>> comparator ) { return m_Delegate.min( comparator ); } 268 269 /** 270 * {@inheritDoc} 271 */ 272 @Override 273 public final boolean noneMatch( final Predicate<? super Entry<K,V>> predicate ) { return m_Delegate.noneMatch( predicate ); } 274 275 /** 276 * {@inheritDoc} 277 */ 278 @Override 279 public final MapStream<K,V> onClose( final Runnable closeHandler ) { return new DefaultMapStream<>( m_Delegate.onClose( closeHandler ) ); } 280 281 /** 282 * {@inheritDoc} 283 */ 284 @Override 285 public final MapStream<K,V> parallel() { return new DefaultMapStream<>( m_Delegate.parallel() ); } 286 287 /** 288 * {@inheritDoc} 289 */ 290 @Override 291 public final MapStream<K,V> peek( final Consumer<? super Entry<K,V>> action ) { return new DefaultMapStream<>( m_Delegate.peek( action ) ); } 292 293 /** 294 * {@inheritDoc} 295 */ 296 @Override 297 public final Optional<Entry<K,V>> reduce( final BinaryOperator<Entry<K,V>> accumulator ) { return m_Delegate.reduce( accumulator ); } 298 299 /** 300 * {@inheritDoc} 301 */ 302 @Override 303 public final Entry<K,V> reduce( final Entry<K,V> identity, final BinaryOperator<Entry<K,V>> accumulator ) 304 { 305 return m_Delegate.reduce( identity, accumulator ); 306 } // reduce() 307 308 /** 309 * {@inheritDoc} 310 */ 311 @Override 312 public final <U> U reduce( final U identity, final BiFunction<U,? super Entry<K,V>,U> accumulator, final BinaryOperator<U> combiner ) 313 { 314 return m_Delegate.reduce( identity, accumulator, combiner ); 315 } // reduce() 316 317 /** 318 * {@inheritDoc} 319 */ 320 @Override 321 public final MapStream<K,V> sequential() { return new DefaultMapStream<>( m_Delegate.sequential() ); } 322 323 /** 324 * {@inheritDoc} 325 */ 326 @Override 327 public final MapStream<K,V> skip( final long n ) { return new DefaultMapStream<>( m_Delegate.skip( n ) ); } 328 329 /** 330 * {@inheritDoc} 331 */ 332 @Override 333 public final MapStream<K,V> sorted() { return new DefaultMapStream<>( m_Delegate.sorted() ); } 334 335 /** 336 * {@inheritDoc} 337 */ 338 @Override 339 public final MapStream<K,V> sorted( final Comparator<? super Entry<K,V>> comparator ) { return new DefaultMapStream<>( m_Delegate.sorted( comparator ) ); } 340 341 /** 342 * {@inheritDoc} 343 * @see java.util.stream.BaseStream#spliterator() 344 */ 345 @Override 346 public final Spliterator<Entry<K,V>> spliterator() { return m_Delegate.spliterator(); } 347 348 /** 349 * {@inheritDoc} 350 */ 351 @Override 352 public final Object [] toArray() { return m_Delegate.toArray(); } 353 354 /** 355 * {@inheritDoc} 356 */ 357 @Override 358 public final <A> A [] toArray( final IntFunction<A []> generator ) { return m_Delegate.toArray( generator ); } 359 360 /** 361 * {@inheritDoc} 362 */ 363 @Override 364 public final MapStream<K,V> unordered() { return new DefaultMapStream<>( m_Delegate.unordered() ); } 365} 366// class DefaultMapStream 367 368/* 369 * End of File 370 */