Skip to content

Commit

Permalink
Remove a couple of APIs scheduled for removal in January 2018.
Browse files Browse the repository at this point in the history
For other APIs scheduled for removal, give them a stay of execution until April so their existing usages can be cleaned up. Also update a few methods that were scheduled for removal in February to April, since we won't be doing @beta removals in February.

ALSO update the java7 version of TreeTraveserTest to match changes that were made at some point in the past to the mainline version but not merged.

RELNOTES:
  - `collect`: Removed `BinaryTreeTraverser`.
  - `concurrent`: Removed `Futures#dereference` and `MoreExecutors#sequentialExecutor`.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182827661
  • Loading branch information
cgdecker authored and cpovirk committed Jan 22, 2018
1 parent 7b65f8e commit f91ef6c
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 1,108 deletions.
Expand Up @@ -18,13 +18,13 @@
import com.google.caliper.Benchmark;
import com.google.caliper.Param;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints;
import java.util.List;
import java.util.Random;

/**
* Benchmarks for the {@code TreeTraverser} and optimized {@code BinaryTreeTraverser} operations on
* binary trees.
* Benchmarks for the {@code TreeTraverser} operations on binary trees.
*
* @author Louis Wasserman
*/
Expand Down Expand Up @@ -110,25 +110,11 @@ private Optional<BinaryNode> createTreap(List<Integer> keys) {
abstract Optional<BinaryNode> createTree(int size, Random rng);
}

private static final BinaryTreeTraverser<BinaryNode> BINARY_VIEWER =
new BinaryTreeTraverser<BinaryNode>() {

@Override
public Optional<BinaryNode> leftChild(BinaryNode node) {
return node.left;
}

@Override
public Optional<BinaryNode> rightChild(BinaryNode node) {
return node.right;
}
};

private static final TreeTraverser<BinaryNode> VIEWER =
new TreeTraverser<BinaryNode>() {
@Override
public Iterable<BinaryNode> children(BinaryNode root) {
return BINARY_VIEWER.children(root);
return Optional.presentInstances(ImmutableList.of(root.left, root.right));
}
};

Expand Down Expand Up @@ -164,16 +150,12 @@ <T> Iterable<T> view(T root, TreeTraverser<T> viewer) {

@Param Traversal traversal;

@Param boolean useBinaryTraverser;

@Param({"1234"})
SpecialRandom rng;

@BeforeExperiment
void setUp() {
this.view =
traversal.view(
topology.createTree(size, rng).get(), useBinaryTraverser ? BINARY_VIEWER : VIEWER);
this.view = traversal.view(topology.createTree(size, rng).get(), VIEWER);
}

@Benchmark
Expand Down
Expand Up @@ -19,12 +19,10 @@
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.testing.NullPointerTester;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Tests for {@code TreeTraverser}.
Expand All @@ -33,25 +31,20 @@
*/
@GwtCompatible(emulated = true)
public class TreeTraverserTest extends TestCase {
private static final class Tree {
private static class Node {
final char value;
final List<Tree> children;

public Tree(char value, Tree... children) {
Node(char value) {
this.value = value;
this.children = Arrays.asList(children);
}
}

private static final class BinaryTree {
final char value;
@NullableDecl final BinaryTree left;
@NullableDecl final BinaryTree right;
private static final class Tree extends Node {
final List<Tree> children;

private BinaryTree(char value, BinaryTree left, BinaryTree right) {
this.value = value;
this.left = left;
this.right = right;
public Tree(char value, Tree... children) {
super(value);
this.children = Arrays.asList(children);
}
}

Expand All @@ -72,20 +65,6 @@ public Iterable<Tree> apply(Tree node) {
}
});

private static final BinaryTreeTraverser<BinaryTree> BIN_ADAPTER =
new BinaryTreeTraverser<BinaryTree>() {

@Override
public Optional<BinaryTree> leftChild(BinaryTree node) {
return Optional.fromNullable(node.left);
}

@Override
public Optional<BinaryTree> rightChild(BinaryTree node) {
return Optional.fromNullable(node.right);
}
};

// h
// / | \
// / e \
Expand All @@ -102,54 +81,24 @@ public Optional<BinaryTree> rightChild(BinaryTree node) {
static final Tree g = new Tree('g', f);
static final Tree h = new Tree('h', d, e, g);

// d
// / \
// b e
// / \ \
// a c f
// /
// g
static final BinaryTree ba = new BinaryTree('a', null, null);
static final BinaryTree bc = new BinaryTree('c', null, null);
static final BinaryTree bb = new BinaryTree('b', ba, bc);
static final BinaryTree bg = new BinaryTree('g', null, null);
static final BinaryTree bf = new BinaryTree('f', bg, null);
static final BinaryTree be = new BinaryTree('e', null, bf);
static final BinaryTree bd = new BinaryTree('d', bb, be);

static String iterationOrder(Iterable<Tree> iterable) {
StringBuilder builder = new StringBuilder();
for (Tree t : iterable) {
builder.append(t.value);
}
return builder.toString();
}

static String binaryIterationOrder(Iterable<BinaryTree> iterable) {
static String iterationOrder(Iterable<? extends Node> iterable) {
StringBuilder builder = new StringBuilder();
for (BinaryTree t : iterable) {
for (Node t : iterable) {
builder.append(t.value);
}
return builder.toString();
}

public void testPreOrder() {
assertThat(iterationOrder(ADAPTER.preOrderTraversal(h))).isEqualTo("hdabcegf");
assertThat(binaryIterationOrder(BIN_ADAPTER.preOrderTraversal(bd))).isEqualTo("dbacefg");
}

public void testPostOrder() {
assertThat(iterationOrder(ADAPTER.postOrderTraversal(h))).isEqualTo("abcdefgh");
assertThat(binaryIterationOrder(BIN_ADAPTER.postOrderTraversal(bd))).isEqualTo("acbgfed");
}

public void testBreadthOrder() {
assertThat(iterationOrder(ADAPTER.breadthFirstTraversal(h))).isEqualTo("hdegabcf");
assertThat(binaryIterationOrder(BIN_ADAPTER.breadthFirstTraversal(bd))).isEqualTo("dbeacfg");
}

public void testInOrder() {
assertThat(binaryIterationOrder(BIN_ADAPTER.inOrderTraversal(bd))).isEqualTo("abcdegf");
}

public void testUsing() {
Expand All @@ -160,6 +109,5 @@ public void testUsing() {
public void testNulls() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicInstanceMethods(ADAPTER);
tester.testAllPublicInstanceMethods(BIN_ADAPTER);
}
}
Expand Up @@ -27,7 +27,6 @@
import static com.google.common.util.concurrent.Futures.allAsList;
import static com.google.common.util.concurrent.Futures.catching;
import static com.google.common.util.concurrent.Futures.catchingAsync;
import static com.google.common.util.concurrent.Futures.dereference;
import static com.google.common.util.concurrent.Futures.getDone;
import static com.google.common.util.concurrent.Futures.immediateCancelledFuture;
import static com.google.common.util.concurrent.Futures.immediateCheckedFuture;
Expand Down Expand Up @@ -2082,58 +2081,6 @@ public ListenableFuture<T> call() {
};
}

public void testDereference_genericsWildcard() throws Exception {
ListenableFuture<?> inner = immediateFuture(null);
@SuppressWarnings("FutureReturnValueIgnored")
ListenableFuture<ListenableFuture<?>> outer =
Futures.<ListenableFuture<?>>immediateFuture(inner);
ListenableFuture<?> dereferenced = dereference(outer);
assertNull(getDone(dereferenced));
}

public void testDereference_genericsHierarchy() throws Exception {
FooChild fooChild = new FooChild();
ListenableFuture<FooChild> inner = immediateFuture(fooChild);
@SuppressWarnings("FutureReturnValueIgnored")
ListenableFuture<ListenableFuture<FooChild>> outer = immediateFuture(inner);
ListenableFuture<Foo> dereferenced = Futures.<Foo>dereference(outer);
assertSame(fooChild, getDone(dereferenced));
}

public void testDereference_resultCancelsOuter() throws Exception {
@SuppressWarnings("FutureReturnValueIgnored")
ListenableFuture<ListenableFuture<Foo>> outer = SettableFuture.create();
ListenableFuture<Foo> dereferenced = dereference(outer);
dereferenced.cancel(true);
assertTrue(outer.isCancelled());
}

public void testDereference_resultCancelsInner() throws Exception {
ListenableFuture<Foo> inner = SettableFuture.create();
@SuppressWarnings("FutureReturnValueIgnored")
ListenableFuture<ListenableFuture<Foo>> outer = immediateFuture(inner);
ListenableFuture<Foo> dereferenced = dereference(outer);
dereferenced.cancel(true);
assertTrue(inner.isCancelled());
}

public void testDereference_outerCancelsResult() throws Exception {
@SuppressWarnings("FutureReturnValueIgnored")
ListenableFuture<ListenableFuture<Foo>> outer = SettableFuture.create();
ListenableFuture<Foo> dereferenced = dereference(outer);
outer.cancel(true);
assertTrue(dereferenced.isCancelled());
}

public void testDereference_innerCancelsResult() throws Exception {
ListenableFuture<Foo> inner = SettableFuture.create();
@SuppressWarnings("FutureReturnValueIgnored")
ListenableFuture<ListenableFuture<Foo>> outer = immediateFuture(inner);
ListenableFuture<Foo> dereferenced = dereference(outer);
inner.cancel(true);
assertTrue(dereferenced.isCancelled());
}

/** Runnable which can be called a single time, and only after {@link #expectCall} is called. */
// TODO(cpovirk): top-level class?
private static class SingleCallListener implements Runnable {
Expand Down
3 changes: 2 additions & 1 deletion android/guava/src/com/google/common/base/Predicates.java
Expand Up @@ -190,9 +190,10 @@ public static Predicate<Object> instanceOf(Class<?> clazz) {
* <p>The returned predicate does not allow null inputs.
*
* @deprecated Use the correctly-named method {@link #subtypeOf} instead. This method is scheduled
* to be removed in January 2018.
* to be removed in April 2018.
* @since 10.0
*/
// TODO(b/72241559): Remove by 2018-04
@GwtIncompatible // Class.isAssignableFrom
@Beta
@Deprecated
Expand Down

6 comments on commit f91ef6c

@reschke
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. Futures.dereference() wasn't deprecated in 23.0, and is gone in 24.0? Even the latest API docs for 23 do not mention the removal: https://google.github.io/guava/releases/23.0/api/docs/com/google/common/util/concurrent/Futures.html#dereference-com.google.common.util.concurrent.ListenableFuture-

@cpovirk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was deprecated in 23.1, released September 27, before being removed in 24.0, released February 1. That was a difference of 4 months, clearing the 3 months that we aim for (but, I should note, don't guarantee) for changes to @Beta types.

Deprecating an API in a minor version is what Semantic Versioning specifies.

@reschke
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, but isn't it unfortunate that the latest published API docs still document this method, and do not mention any deprecation or pending removal?

@ronshapiro
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpovirk's link was to the 23.1 javadocs, which did deprecate. There were also javadocs published for 23.{1-6} published that all had it deprecated

@cpovirk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be getting bit by our change to our version naming scheme:

If you start with the URL for 23.0...

https://google.github.io/guava/releases/23.0/api/docs/com/google/common/util/concurrent/Futures.html#dereference-com.google.common.util.concurrent.ListenableFuture-

...and bump the minor version number...

https://google.github.io/guava/releases/23.1/api/docs/com/google/common/util/concurrent/Futures.html#dereference-com.google.common.util.concurrent.ListenableFuture-

...you can get a 404, suggesting that the docs for 23.1 aren't available (or even that it hasn't been released). That's because the next version is called "23.1-jre":

https://google.github.io/guava/releases/23.1-jre/api/docs/com/google/common/util/concurrent/Futures.html#dereference-com.google.common.util.concurrent.ListenableFuture-

The docs for 23.1-jre through 23.6-jre have been linked from the home page under "Latest release" as each has become available.

@reschke
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Thanks for the explanation.

Please sign in to comment.