changeset 4719:7e592a11b492

Remove questionable List, Block methods
author briangoetz
date Fri, 30 Dec 2011 18:16:05 -0500
parents 9a0b17ea5292
children a1a106adff5f
files make/java/java/FILES_java.gmk src/share/classes/java/util/List.java src/share/classes/java/util/ListHelpers.java src/share/classes/java/util/functions/Block.java src/share/classes/java/util/functions/Blocks.java test-ng/tests/java/util/functions/BlocksTest.java
diffstat 6 files changed, 0 insertions(+), 289 deletions(-) [+]
line wrap: on
line diff
--- a/make/java/java/FILES_java.gmk	Wed Dec 28 23:27:04 2011 -0500
+++ b/make/java/java/FILES_java.gmk	Fri Dec 30 18:16:05 2011 -0500
@@ -241,7 +241,6 @@
             java/util/SortedSet.java \
                 java/util/NavigableSet.java \
         java/util/List.java \
-     java/util/ListHelpers.java \
 	java/util/Queue.java \
 	    java/util/Deque.java \
     java/util/AbstractCollection.java \
--- a/src/share/classes/java/util/List.java	Wed Dec 28 23:27:04 2011 -0500
+++ b/src/share/classes/java/util/List.java	Fri Dec 30 18:16:05 2011 -0500
@@ -600,55 +600,6 @@
      */
     List<E> subList(int fromIndex, int toIndex);
 
-    /**
-     * Return index of the first element matching the provided predicate.
-     *
-     * @param match the predicate which elements must match.
-     * @return index of the matching element or {@code -1} if no element
-     * matched.
-     */
-    int firstIndexOf(Predicate<? super E> match) default {
-        return ListHelpers.<E>firstIndexOf(this, match);
-     }
-
-    /**
-     * Return index of the first element matching the provided predicate.
-     *
-     * @param match the predicate which elements must match.
-     * @param pos the matching element must be at or follow this index position
-     * in the list (inclusive).
-     * @return index of the matching element or {@code -1} if no element
-     * matched.
-     */
-    int nextIndexOf(Predicate<? super E> match, int pos) default {
-        return ListHelpers.<E>nextIndexOf(this, match, pos);
-    }
-
-    /**
-     * Return index of the last element matching the provided predicate
-     * occurring before the specified position in the list.
-     *
-     * @param match the predicate which elements must match.
-     * @param pos the matching element must preceed this index position in the
-     * list. (exclusive).
-     * @return index of the matching element or {@code -1} if no element
-     * matched.
-     */
-    int priorIndexOf(Predicate<? super E> match, int pos) default {
-        return ListHelpers.<E>priorIndexOf(this, match, pos);
-            }
-
-    /**
-     * Return index of the last element matching the provided predicate.
-     *
-     * @param match the predicate which elements must match.
-     * @return index of the first matching element or {@code -1} if no element
-     * matched.
-     */
-    int lastIndexOf(Predicate<? super E> match) default {
-        return ListHelpers.<E>lastIndexOf(this, match);
-    }
-
     // public void sort() default Collections.<E>sort;
 
     public void sort(Comparator<? super E> c) default {
--- a/src/share/classes/java/util/ListHelpers.java	Wed Dec 28 23:27:04 2011 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package java.util;
-
-import java.util.functions.Predicate;
-
-/**
- * Extension method helpers for {@code List}.
- */
-public final class ListHelpers {
-
-    /**
-     * Return index of the first element matching the provided predicate.
-     *
-     * @param <T> type of list elements.
-     * @param list the list to be searched.
-     * @param match the predicate which elements must match.
-     * @return index of the matching element or {@code -1} if no element
-     * matched.
-     */
-    public static <T> int firstIndexOf(List<T> list, Predicate<? super T> match) {
-        ListIterator<T> it = list.listIterator();
-
-        while (it.hasNext())
-            if (match.eval(it.next()))
-                return it.previousIndex();
-
-        return -1;
-    }
-
-    /**
-     * Return index of the first element matching the provided predicate.
-     *
-     * @param <T> type of list elements.
-     * @param list the list to be searched.
-     * @param match the predicate which elements must match.
-     * @param pos the matching element must be at or follow this index position
-     * in the list (inclusive).
-     * @return index of the matching element or {@code -1} if no element
-     * matched.
-     */
-    public static <T> int nextIndexOf(List<T> list, Predicate<? super T> match, int pos) {
-        ListIterator<T> it = list.subList(pos, list.size()).listIterator();
-
-        while (it.hasNext())
-            if (match.eval(it.next()))
-                return pos + it.previousIndex();
-
-        return -1;
-    }
-
-    /**
-     * Return index of the last element matching the provided predicate
-     * occurring before the specified position in the list.
-     *
-     * @param <T> type of list elements.
-     * @param list the list to be searched.
-     * @param match the predicate which elements must match.
-     * @param pos the matching element must preceed this index position in the
-     * list. (exclusive).
-     * @return index of the matching element or {@code -1} if no element
-     * matched.
-     */
-    public static <T> int priorIndexOf(List<T> list, Predicate<? super T> match, int pos) {
-        ListIterator<T> it = list.subList(0, pos).listIterator(pos);
-
-        while (it.hasPrevious())
-                if (match.eval(it.previous()))
-                    return it.nextIndex();
-
-        return -1;
-    }
-
-    /**
-     * Return index of the last element matching the provided predicate.
-     *
-     * @param <T> type of list elements.
-     * @param list the list to be searched.
-     * @param match the predicate which elements must match.
-     * @return index of the matching element or {@code -1} if no element
-     * matched.
-     */
-    public static <T> int lastIndexOf(List<T> list, Predicate<? super T> match) {
-        ListIterator<T> it = list.listIterator(list.size());
-
-        while (it.hasPrevious())
-                if (match.eval(it.previous()))
-                    return it.nextIndex();
-
-        return -1;
-    }
-
-}
--- a/src/share/classes/java/util/functions/Block.java	Wed Dec 28 23:27:04 2011 -0500
+++ b/src/share/classes/java/util/functions/Block.java	Fri Dec 30 18:16:05 2011 -0500
@@ -87,42 +87,4 @@
     Block<T> chain(Iterable<? extends Block<? super T>> sequence) default {
         return Blocks.chain(this, sequence);
     }
-
-    /**
-     * Returns a Block which repeatedly performs the {@code apply} method of
-     * this Block.
-     *
-     * @param count number of repetitions of the {@code apply} method to perform.
-     * @return a Block which repeatedly performs the {@code apply} method of
-     * this Block.
-     */
-    Block<T> repeat(int count) default {
-        return Blocks.repeat(this, count);
-    }
-
-    /**
-     * Returns a Block which repeatedly performs the {@code apply} method of
-     * this Block. The repetitions are terminated when the provided predicate
-     * returns {@code false}. The predicate is tested before each iteration.
-     *
-     * @param decider determines when to terminate calling the Block.
-     * @return a Block which repeatedly performs the {@code apply} method of
-     * this Block.
-     */
-    Block<T> whileRepeat(Predicate<? super T> decider) default {
-        return Blocks.whileRepeat(this, decider);
-    }
-
-    /**
-     * Returns a Block which repeatedly performs the {@code apply} method of
-     * this Block. The repetitions are terminated when the provided predicate
-     * returns {@code false}. The predicate is tested after each iteration.
-     *
-     * @param decider determines when to terminate calling the Block.
-     * @return a Block which repeatedly performs the {@code apply} method of
-     * this Block.
-     */
-    Block<T> repeatUntil(Predicate<? super T> decider) default {
-        return Blocks.repeatUntil(this, decider);
-    }
 }
--- a/src/share/classes/java/util/functions/Blocks.java	Wed Dec 28 23:27:04 2011 -0500
+++ b/src/share/classes/java/util/functions/Blocks.java	Fri Dec 30 18:16:05 2011 -0500
@@ -192,68 +192,4 @@
                 block.apply(t);
         };
     }
-
-    /**
-     * Returns a Block which repeatedly performs the {@code apply} method of
-     * this Block.
-     *
-     * @param block Block to {@code apply} repeatedly
-     * @param times number of repetitions of the {@code apply} method to perform.
-     * @return a Block which repeatedly performs the {@code apply} method of
-     * this Block
-     */
-    public static <T> Block<T> repeat(Block<? super T> block, int times) {
-        Objects.requireNonNull(block);
-        if(times < 0) { throw new IllegalArgumentException("negative times");}
-
-        return t -> {
-            for (int i = 0; i < times; i++) {
-                block.apply(t);
-            }
-        };
-    }
-
-    /**
-     * Returns a Block which repeatedly performs the {@code apply} method of
-     * this Block. The repetitions are terminated when the provided predicate
-     * returns {@code false}. The predicate is tested after each iteration.
-     *
-     * @param block Block to {@code apply} repeatedly
-     * @param decider a predicate which determines whether to continue
-     * calling the {@code apply} method
-     * @return a Block which repeatedly performs the {@code apply} method of
-     * this Block.
-     */
-    public static <T> Block<T> whileRepeat(Block<? super T> block, Predicate<? super T> decider) {
-        Objects.requireNonNull(block);
-        Objects.requireNonNull(decider);
-
-        return t -> {
-            while (decider.eval(t)) {
-                block.apply(t);
-            }
-        };
-    }
-
-    /**
-     * Returns a Block which repeatedly performs the {@code apply} method of
-     * this Block. The repetitions are terminated when the provided predicate
-     * returns {@code false}. The predicate is tested after each iteration.
-     *
-     * @param block Block to {@code apply} repeatedly.
-     * @param decider a predicate which determines whether to continue
-     * calling the {@code apply} method.
-     * @return a Block which repeatedly performs the {@code apply} method of
-     * this Block.
-     */
-    public static <T> Block<T> repeatUntil(Block<? super T> block, Predicate<? super T> decider) {
-        Objects.requireNonNull(block);
-        Objects.requireNonNull(decider);
-
-        return t -> {
-            do {
-                block.apply(t);
-            } while (decider.eval(t));
-        };
-    }
 }
--- a/test-ng/tests/java/util/functions/BlocksTest.java	Wed Dec 28 23:27:04 2011 -0500
+++ b/test-ng/tests/java/util/functions/BlocksTest.java	Fri Dec 30 18:16:05 2011 -0500
@@ -123,26 +123,4 @@
             listed).apply(true);
         assert (results[0] && results[1] && results[2]);
     }
-
-    @Test
-    public void testRepeatTimes() {
-        final int results[] = new int[] { 0 };
-
-        Blocks.repeat( (Block<Integer>) x -> { results[0] += x; }, 5).apply(1);
-        assert(results[0] == 5);
-    }
-
-    @Test
-    public void testRepeatPredicate() {
-        final int results[] = new int[] { 0 };
-
-        Blocks.whileRepeat( (Block<Integer>) x -> { results[0] += x; },
-            (Predicate<Integer>) x -> results[0] < 5).apply(1);
-        assert (results[0] == 5);
-
-        results[0] = 0;
-        Blocks.repeatUntil( (Block<Integer>) x -> { results[0] += x; },
-            (Predicate<Integer>) x -> results[0] < 5).apply(1);
-        assert(results[0] == 5);
-    }
 }