< prev index next >

src/java.base/share/classes/java/util/stream/Collectors.java

Print this page




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.util.stream;
  26 
  27 import java.util.AbstractMap;
  28 import java.util.AbstractSet;
  29 import java.util.ArrayList;
  30 import java.util.Arrays;
  31 import java.util.Collection;
  32 import java.util.Collections;
  33 import java.util.Comparator;
  34 import java.util.DoubleSummaryStatistics;
  35 import java.util.EnumSet;
  36 import java.util.HashMap;
  37 import java.util.HashSet;
  38 import java.util.IntSummaryStatistics;
  39 import java.util.Iterator;
  40 import java.util.List;
  41 import java.util.LongSummaryStatistics;
  42 import java.util.Map;
  43 import java.util.Objects;
  44 import java.util.Optional;
  45 import java.util.Set;
  46 import java.util.StringJoiner;
  47 import java.util.concurrent.ConcurrentHashMap;
  48 import java.util.concurrent.ConcurrentMap;
  49 import java.util.function.BiConsumer;
  50 import java.util.function.BiFunction;


1703                 (r, t) -> r.accept(mapper.applyAsDouble(t)),
1704                 (l, r) -> { l.combine(r); return l; }, CH_ID);
1705     }
1706 
1707     /**
1708      * Implementation class used by partitioningBy.
1709      */
1710     private static final class Partition<T>
1711             extends AbstractMap<Boolean, T>
1712             implements Map<Boolean, T> {
1713         final T forTrue;
1714         final T forFalse;
1715 
1716         Partition(T forTrue, T forFalse) {
1717             this.forTrue = forTrue;
1718             this.forFalse = forFalse;
1719         }
1720 
1721         @Override
1722         public Set<Map.Entry<Boolean, T>> entrySet() {
1723             return new AbstractSet<Map.Entry<Boolean, T>>() {
1724                 @Override
1725                 public Iterator<Map.Entry<Boolean, T>> iterator() {
1726                     Map.Entry<Boolean, T> falseEntry = new SimpleImmutableEntry<>(false, forFalse);
1727                     Map.Entry<Boolean, T> trueEntry = new SimpleImmutableEntry<>(true, forTrue);
1728                     return Arrays.asList(falseEntry, trueEntry).iterator();
1729                 }
1730 
1731                 @Override
1732                 public int size() {
1733                     return 2;
1734                 }
1735             };
1736         }
1737     }
1738 }


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.util.stream;
  26 
  27 import java.util.AbstractMap;
  28 import java.util.AbstractSet;
  29 import java.util.ArrayList;

  30 import java.util.Collection;
  31 import java.util.Collections;
  32 import java.util.Comparator;
  33 import java.util.DoubleSummaryStatistics;
  34 import java.util.EnumSet;
  35 import java.util.HashMap;
  36 import java.util.HashSet;
  37 import java.util.IntSummaryStatistics;
  38 import java.util.Iterator;
  39 import java.util.List;
  40 import java.util.LongSummaryStatistics;
  41 import java.util.Map;
  42 import java.util.Objects;
  43 import java.util.Optional;
  44 import java.util.Set;
  45 import java.util.StringJoiner;
  46 import java.util.concurrent.ConcurrentHashMap;
  47 import java.util.concurrent.ConcurrentMap;
  48 import java.util.function.BiConsumer;
  49 import java.util.function.BiFunction;


1702                 (r, t) -> r.accept(mapper.applyAsDouble(t)),
1703                 (l, r) -> { l.combine(r); return l; }, CH_ID);
1704     }
1705 
1706     /**
1707      * Implementation class used by partitioningBy.
1708      */
1709     private static final class Partition<T>
1710             extends AbstractMap<Boolean, T>
1711             implements Map<Boolean, T> {
1712         final T forTrue;
1713         final T forFalse;
1714 
1715         Partition(T forTrue, T forFalse) {
1716             this.forTrue = forTrue;
1717             this.forFalse = forFalse;
1718         }
1719 
1720         @Override
1721         public Set<Map.Entry<Boolean, T>> entrySet() {
1722             return new AbstractSet<>() {
1723                 @Override
1724                 public Iterator<Map.Entry<Boolean, T>> iterator() {
1725                     Map.Entry<Boolean, T> falseEntry = new SimpleImmutableEntry<>(false, forFalse);
1726                     Map.Entry<Boolean, T> trueEntry = new SimpleImmutableEntry<>(true, forTrue);
1727                     return List.of(falseEntry, trueEntry).iterator();
1728                 }
1729 
1730                 @Override
1731                 public int size() {
1732                     return 2;
1733                 }
1734             };
1735         }
1736     }
1737 }
< prev index next >