Upgraded Guava to unmodified jdk5-backport-v17.0-post
This simply copies the Guava source for jdk5-backport-v17.0-post
straight from the github repository into this one.
See https://github.com/google/guava.git
Additional commits will be made which will allow this to compile
on Android.
BUG=19672715
Change-Id: If822daced0fc352f01bf9ecac1e994da08358f72
diff --git a/guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Stopwatch.java b/guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Stopwatch.java
index 931a2df..07f674e 100644
--- a/guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Stopwatch.java
+++ b/guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Stopwatch.java
@@ -122,11 +122,10 @@
* Creates (but does not start) a new stopwatch using {@link System#nanoTime}
* as its time source.
*
- * @deprecated Use {@link Stopwatch#createUnstarted()} instead. This
- * constructor is scheduled to be removed in Guava release 17.0.
+ * @deprecated Use {@link Stopwatch#createUnstarted()} instead.
*/
@Deprecated
- public Stopwatch() {
+ Stopwatch() {
this(Ticker.systemTicker());
}
@@ -134,11 +133,10 @@
* Creates (but does not start) a new stopwatch, using the specified time
* source.
*
- * @deprecated Use {@link Stopwatch#createUnstarted(Ticker)} instead. This
- * constructor is scheduled to be removed in Guava release 17.0.
+ * @deprecated Use {@link Stopwatch#createUnstarted(Ticker)} instead.
*/
@Deprecated
- public Stopwatch(Ticker ticker) {
+ Stopwatch(Ticker ticker) {
this.ticker = checkNotNull(ticker, "ticker");
}
@@ -252,4 +250,3 @@
}
}
}
-
diff --git a/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/FluentIterable.java b/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/FluentIterable.java
index 7cf2a0a..42ae486 100644
--- a/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/FluentIterable.java
+++ b/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/FluentIterable.java
@@ -413,64 +413,6 @@
}
/**
- * Returns an {@code ImmutableList} containing all of the elements from this
- * fluent iterable in proper sequence.
- *
- * @deprecated Use {@link #toList()} instead. This method is scheduled for removal in Guava 15.0.
- */
- @Deprecated
- public final ImmutableList<E> toImmutableList() {
- return toList();
- }
-
- /**
- * Returns an {@code ImmutableList} containing all of the elements from this
- * {@code FluentIterable} in the order specified by {@code comparator}. To produce an
- * {@code ImmutableList} sorted by its natural ordering, use
- * {@code toSortedImmutableList(Ordering.natural())}.
- *
- * @param comparator the function by which to sort list elements
- * @throws NullPointerException if any element is null
- * @since 13.0
- * @deprecated Use {@link #toSortedList(Comparator)} instead. This method is scheduled for removal
- * in Guava 15.0.
- */
- @Deprecated
- public final ImmutableList<E> toSortedImmutableList(
- Comparator<? super E> comparator) {
- return toSortedList(comparator);
- }
-
- /**
- * Returns an {@code ImmutableSet} containing all of the elements from this
- * fluent iterable with duplicates removed.
- *
- * @deprecated Use {@link #toSet()} instead. This method is scheduled for removal in Guava 15.0.
- */
- @Deprecated
- public final ImmutableSet<E> toImmutableSet() {
- return toSet();
- }
-
- /**
- * Returns an {@code ImmutableSortedSet} containing all of the elements from this
- * {@code FluentIterable} in the order specified by {@code comparator}, with duplicates
- * (determined by {@code comparator.compare(x, y) == 0}) removed. To produce an
- * {@code ImmutableSortedSet} sorted by its natural ordering, use
- * {@code toImmutableSortedSet(Ordering.natural())}.
- *
- * @param comparator the function by which to sort set elements
- * @throws NullPointerException if any element is null
- * @deprecated Use {@link #toSortedSet(Comparator)} instead. This method is scheduled for removal
- * in Guava 15.0.
- */
- @Deprecated
- public final ImmutableSortedSet<E> toImmutableSortedSet(
- Comparator<? super E> comparator) {
- return toSortedSet(comparator);
- }
-
- /**
* Copies all the elements from this fluent iterable to {@code collection}. This is equivalent to
* calling {@code Iterables.addAll(collection, this)}.
*
diff --git a/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/GenericMapMaker.java b/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/GenericMapMaker.java
index 03ba0c0..6240625 100644
--- a/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/GenericMapMaker.java
+++ b/guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/GenericMapMaker.java
@@ -37,12 +37,12 @@
* "Generic" equivalent; simple use {@code CacheBuilder} naturally. For general migration
* instructions, see the <a
* href="http://code.google.com/p/guava-libraries/wiki/MapMakerMigration">MapMaker Migration
- * Guide</a>. This class is scheduled for removal in Guava 16.0.
+ * Guide</a>.
*/
@Beta
@Deprecated
@GwtCompatible(emulated = true)
-public abstract class GenericMapMaker<K0, V0> {
+abstract class GenericMapMaker<K0, V0> {
// Set by MapMaker, but sits in this class to preserve the type relationship
@@ -83,6 +83,6 @@
* See {@link MapMaker#makeComputingMap}.
*/
@Deprecated
- public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
+ abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
Function<? super K, ? extends V> computingFunction);
}
diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ConstraintsTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ConstraintsTest.java
deleted file mode 100644
index 9dda41f..0000000
--- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ConstraintsTest.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * Copyright (C) 2007 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect;
-
-import static java.util.Arrays.asList;
-import static org.truth0.Truth.ASSERT;
-
-import com.google.common.annotations.GwtCompatible;
-
-import junit.framework.TestCase;
-
-import java.util.AbstractCollection;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.RandomAccess;
-import java.util.Set;
-import java.util.SortedSet;
-
-/**
- * Tests for {@code Constraints}.
- *
- * @author Mike Bostock
- * @author Jared Levy
- */
-@GwtCompatible(emulated = true)
-public class ConstraintsTest extends TestCase {
-
- private static final String TEST_ELEMENT = "test";
-
- private static final class TestElementException
- extends IllegalArgumentException {
- private static final long serialVersionUID = 0;
- }
-
- private static final Constraint<String> TEST_CONSTRAINT
- = new Constraint<String>() {
- @Override
- public String checkElement(String element) {
- if (TEST_ELEMENT.equals(element)) {
- throw new TestElementException();
- }
- return element;
- }
- };
-
- public void testNotNull() {
- Constraint<? super String> constraint = Constraints.notNull();
- assertSame(TEST_ELEMENT, constraint.checkElement(TEST_ELEMENT));
- try {
- constraint.checkElement(null);
- fail("NullPointerException expected");
- } catch (NullPointerException expected) {}
- assertEquals("Not null", constraint.toString());
- }
-
- public void testConstrainedCollectionLegal() {
- Collection<String> collection = Lists.newArrayList("foo", "bar");
- Collection<String> constrained = Constraints.constrainedCollection(
- collection, TEST_CONSTRAINT);
- collection.add(TEST_ELEMENT);
- constrained.add("qux");
- constrained.addAll(asList("cat", "dog"));
- /* equals and hashCode aren't defined for Collection */
- ASSERT.that(collection).has()
- .exactly("foo", "bar", TEST_ELEMENT, "qux", "cat", "dog").inOrder();
- ASSERT.that(constrained).has()
- .exactly("foo", "bar", TEST_ELEMENT, "qux", "cat", "dog").inOrder();
- }
-
- public void testConstrainedCollectionIllegal() {
- Collection<String> collection = Lists.newArrayList("foo", "bar");
- Collection<String> constrained = Constraints.constrainedCollection(
- collection, TEST_CONSTRAINT);
- try {
- constrained.add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.addAll(asList("baz", TEST_ELEMENT));
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- ASSERT.that(constrained).has().exactly("foo", "bar").inOrder();
- ASSERT.that(collection).has().exactly("foo", "bar").inOrder();
- }
-
- public void testConstrainedSetLegal() {
- Set<String> set = Sets.newLinkedHashSet(asList("foo", "bar"));
- Set<String> constrained = Constraints.constrainedSet(set, TEST_CONSTRAINT);
- set.add(TEST_ELEMENT);
- constrained.add("qux");
- constrained.addAll(asList("cat", "dog"));
- assertTrue(set.equals(constrained));
- assertTrue(constrained.equals(set));
- assertEquals(set.toString(), constrained.toString());
- assertEquals(set.hashCode(), constrained.hashCode());
- ASSERT.that(set).has().exactly("foo", "bar", TEST_ELEMENT, "qux", "cat", "dog").inOrder();
- ASSERT.that(constrained).has()
- .exactly("foo", "bar", TEST_ELEMENT, "qux", "cat", "dog").inOrder();
- }
-
- public void testConstrainedSetIllegal() {
- Set<String> set = Sets.newLinkedHashSet(asList("foo", "bar"));
- Set<String> constrained = Constraints.constrainedSet(set, TEST_CONSTRAINT);
- try {
- constrained.add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.addAll(asList("baz", TEST_ELEMENT));
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- ASSERT.that(constrained).has().exactly("foo", "bar").inOrder();
- ASSERT.that(set).has().exactly("foo", "bar").inOrder();
- }
-
- public void testConstrainedSortedSetLegal() {
- SortedSet<String> sortedSet = Sets.newTreeSet(asList("foo", "bar"));
- SortedSet<String> constrained = Constraints.constrainedSortedSet(
- sortedSet, TEST_CONSTRAINT);
- sortedSet.add(TEST_ELEMENT);
- constrained.add("qux");
- constrained.addAll(asList("cat", "dog"));
- assertTrue(sortedSet.equals(constrained));
- assertTrue(constrained.equals(sortedSet));
- assertEquals(sortedSet.toString(), constrained.toString());
- assertEquals(sortedSet.hashCode(), constrained.hashCode());
- ASSERT.that(sortedSet).has().exactly("bar", "cat", "dog", "foo", "qux", TEST_ELEMENT).inOrder();
- ASSERT.that(constrained).has()
- .exactly("bar", "cat", "dog", "foo", "qux", TEST_ELEMENT).inOrder();
- assertNull(constrained.comparator());
- assertEquals("bar", constrained.first());
- assertEquals(TEST_ELEMENT, constrained.last());
- }
-
- public void testConstrainedSortedSetIllegal() {
- SortedSet<String> sortedSet = Sets.newTreeSet(asList("foo", "bar"));
- SortedSet<String> constrained = Constraints.constrainedSortedSet(
- sortedSet, TEST_CONSTRAINT);
- try {
- constrained.add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.subSet("bar", "foo").add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.headSet("bar").add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.tailSet("foo").add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.addAll(asList("baz", TEST_ELEMENT));
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- ASSERT.that(constrained).has().exactly("bar", "foo").inOrder();
- ASSERT.that(sortedSet).has().exactly("bar", "foo").inOrder();
- }
-
- public void testConstrainedListLegal() {
- List<String> list = Lists.newArrayList("foo", "bar");
- List<String> constrained = Constraints.constrainedList(
- list, TEST_CONSTRAINT);
- list.add(TEST_ELEMENT);
- constrained.add("qux");
- constrained.addAll(asList("cat", "dog"));
- constrained.add(1, "cow");
- constrained.addAll(4, asList("box", "fan"));
- constrained.set(2, "baz");
- assertTrue(list.equals(constrained));
- assertTrue(constrained.equals(list));
- assertEquals(list.toString(), constrained.toString());
- assertEquals(list.hashCode(), constrained.hashCode());
- ASSERT.that(list).has().exactly(
- "foo", "cow", "baz", TEST_ELEMENT, "box", "fan", "qux", "cat", "dog").inOrder();
- ASSERT.that(constrained).has().exactly(
- "foo", "cow", "baz", TEST_ELEMENT, "box", "fan", "qux", "cat", "dog").inOrder();
- ListIterator<String> iterator = constrained.listIterator();
- iterator.next();
- iterator.set("sun");
- constrained.listIterator(2).add("sky");
- ASSERT.that(list).has().exactly(
- "sun", "cow", "sky", "baz", TEST_ELEMENT, "box", "fan", "qux", "cat", "dog").inOrder();
- ASSERT.that(constrained).has().exactly(
- "sun", "cow", "sky", "baz", TEST_ELEMENT, "box", "fan", "qux", "cat", "dog").inOrder();
- assertTrue(constrained instanceof RandomAccess);
- }
-
- public void testConstrainedListRandomAccessFalse() {
- List<String> list = Lists.newLinkedList(asList("foo", "bar"));
- List<String> constrained = Constraints.constrainedList(
- list, TEST_CONSTRAINT);
- list.add(TEST_ELEMENT);
- constrained.add("qux");
- assertFalse(constrained instanceof RandomAccess);
- }
-
- public void testConstrainedListIllegal() {
- List<String> list = Lists.newArrayList("foo", "bar");
- List<String> constrained = Constraints.constrainedList(
- list, TEST_CONSTRAINT);
- try {
- constrained.add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.listIterator().add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.listIterator(1).add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.listIterator().set(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.listIterator(1).set(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.subList(0, 1).add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.add(1, TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.set(1, TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.addAll(asList("baz", TEST_ELEMENT));
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.addAll(1, asList("baz", TEST_ELEMENT));
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- ASSERT.that(constrained).has().exactly("foo", "bar").inOrder();
- ASSERT.that(list).has().exactly("foo", "bar").inOrder();
- }
-
- public void testConstrainedMultisetLegal() {
- Multiset<String> multiset = HashMultiset.create(asList("foo", "bar"));
- Multiset<String> constrained = Constraints.constrainedMultiset(
- multiset, TEST_CONSTRAINT);
- multiset.add(TEST_ELEMENT);
- constrained.add("qux");
- constrained.addAll(asList("cat", "dog"));
- constrained.add("cow", 2);
- assertTrue(multiset.equals(constrained));
- assertTrue(constrained.equals(multiset));
- assertEquals(multiset.toString(), constrained.toString());
- assertEquals(multiset.hashCode(), constrained.hashCode());
- ASSERT.that(multiset).has().exactly(
- "foo", "bar", TEST_ELEMENT, "qux", "cat", "dog", "cow", "cow");
- ASSERT.that(constrained).has().exactly(
- "foo", "bar", TEST_ELEMENT, "qux", "cat", "dog", "cow", "cow");
- assertEquals(1, constrained.count("foo"));
- assertEquals(1, constrained.remove("foo", 3));
- assertEquals(2, constrained.setCount("cow", 0));
- ASSERT.that(multiset).has().exactly("bar", TEST_ELEMENT, "qux", "cat", "dog");
- ASSERT.that(constrained).has().exactly("bar", TEST_ELEMENT, "qux", "cat", "dog");
- }
-
- public void testConstrainedMultisetIllegal() {
- Multiset<String> multiset = HashMultiset.create(asList("foo", "bar"));
- Multiset<String> constrained = Constraints.constrainedMultiset(
- multiset, TEST_CONSTRAINT);
- try {
- constrained.add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.add(TEST_ELEMENT, 2);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.addAll(asList("baz", TEST_ELEMENT));
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- ASSERT.that(constrained).has().exactly("foo", "bar");
- ASSERT.that(multiset).has().exactly("foo", "bar");
- }
-
- public void testNefariousAddAll() {
- List<String> list = Lists.newArrayList("foo", "bar");
- List<String> constrained = Constraints.constrainedList(
- list, TEST_CONSTRAINT);
- Collection<String> onceIterable = onceIterableCollection("baz");
- constrained.addAll(onceIterable);
- ASSERT.that(constrained).has().exactly("foo", "bar", "baz").inOrder();
- ASSERT.that(list).has().exactly("foo", "bar", "baz").inOrder();
- }
-
- /**
- * Returns a "nefarious" collection, which permits only one call to
- * iterator(). This verifies that the constrained collection uses a defensive
- * copy instead of potentially checking the elements in one snapshot and
- * adding the elements from another.
- *
- * @param element the element to be contained in the collection
- */
- static <E> Collection<E> onceIterableCollection(final E element) {
- return new AbstractCollection<E>() {
- boolean iteratorCalled;
- @Override public int size() {
- /*
- * We could make the collection empty, but that seems more likely to
- * trigger special cases (so maybe we should test both empty and
- * nonempty...).
- */
- return 1;
- }
- @Override public Iterator<E> iterator() {
- assertFalse("Expected only one call to iterator()", iteratorCalled);
- iteratorCalled = true;
- return Collections.singleton(element).iterator();
- }
- };
- }
-}
-
diff --git a/guava-gwt/test/com/google/common/collect/ConstraintsTest_gwt.java b/guava-gwt/test/com/google/common/collect/ConstraintsTest_gwt.java
index 36300ec..6c091b2 100644
--- a/guava-gwt/test/com/google/common/collect/ConstraintsTest_gwt.java
+++ b/guava-gwt/test/com/google/common/collect/ConstraintsTest_gwt.java
@@ -43,16 +43,6 @@
testCase.testConstrainedListRandomAccessFalse();
}
-public void testConstrainedMultisetIllegal() throws Exception {
- com.google.common.collect.ConstraintsTest testCase = new com.google.common.collect.ConstraintsTest();
- testCase.testConstrainedMultisetIllegal();
-}
-
-public void testConstrainedMultisetLegal() throws Exception {
- com.google.common.collect.ConstraintsTest testCase = new com.google.common.collect.ConstraintsTest();
- testCase.testConstrainedMultisetLegal();
-}
-
public void testConstrainedSetIllegal() throws Exception {
com.google.common.collect.ConstraintsTest testCase = new com.google.common.collect.ConstraintsTest();
testCase.testConstrainedSetIllegal();
@@ -77,9 +67,4 @@
com.google.common.collect.ConstraintsTest testCase = new com.google.common.collect.ConstraintsTest();
testCase.testNefariousAddAll();
}
-
-public void testNotNull() throws Exception {
- com.google.common.collect.ConstraintsTest testCase = new com.google.common.collect.ConstraintsTest();
- testCase.testNotNull();
-}
}
diff --git a/guava-tests/benchmark/com/google/common/primitives/UnsignedBytesBenchmark.java b/guava-tests/benchmark/com/google/common/primitives/UnsignedBytesBenchmark.java
index 9b1cac2..19511fc 100644
--- a/guava-tests/benchmark/com/google/common/primitives/UnsignedBytesBenchmark.java
+++ b/guava-tests/benchmark/com/google/common/primitives/UnsignedBytesBenchmark.java
@@ -36,6 +36,7 @@
private byte[] ba3;
private byte[] ba4;
private Comparator<byte[]> javaImpl;
+ private Comparator<byte[]> unsafeImpl;
// 4, 8, 64, 1K, 1M, 1M (unaligned), 64M, 64M (unaligned)
//@Param({"4", "8", "64", "1024", "1048576", "1048577", "6710884", "6710883"})
@@ -55,6 +56,8 @@
ba4[ba1.length - 1] = (byte) 42;
javaImpl = UnsignedBytes.lexicographicalComparatorJavaImpl();
+ unsafeImpl =
+ UnsignedBytes.LexicographicalComparatorHolder.UnsafeComparator.INSTANCE;
}
@Benchmark void longEqualJava(int reps) {
@@ -65,6 +68,14 @@
}
}
+ @Benchmark void longEqualUnsafe(int reps) {
+ for (int i = 0; i < reps; ++i) {
+ if (unsafeImpl.compare(ba1, ba2) != 0) {
+ throw new Error(); // deoptimization
+ }
+ }
+ }
+
@Benchmark void diffLastJava(int reps) {
for (int i = 0; i < reps; ++i) {
if (javaImpl.compare(ba3, ba4) == 0) {
@@ -73,6 +84,14 @@
}
}
+ @Benchmark void diffLastUnsafe(int reps) {
+ for (int i = 0; i < reps; ++i) {
+ if (unsafeImpl.compare(ba3, ba4) == 0) {
+ throw new Error(); // deoptimization
+ }
+ }
+ }
+
/*
try {
UnsignedBytesBenchmark bench = new UnsignedBytesBenchmark();
diff --git a/guava-tests/test/com/google/common/collect/ConstraintsTest.java b/guava-tests/test/com/google/common/collect/ConstraintsTest.java
index 08a2866..cd24240 100644
--- a/guava-tests/test/com/google/common/collect/ConstraintsTest.java
+++ b/guava-tests/test/com/google/common/collect/ConstraintsTest.java
@@ -20,8 +20,6 @@
import static org.truth0.Truth.ASSERT;
import com.google.common.annotations.GwtCompatible;
-import com.google.common.annotations.GwtIncompatible;
-import com.google.common.testing.SerializableTester;
import junit.framework.TestCase;
@@ -41,7 +39,7 @@
* @author Mike Bostock
* @author Jared Levy
*/
-@GwtCompatible(emulated = true)
+@GwtCompatible
public class ConstraintsTest extends TestCase {
private static final String TEST_ELEMENT = "test";
@@ -62,16 +60,6 @@
}
};
- public void testNotNull() {
- Constraint<? super String> constraint = Constraints.notNull();
- assertSame(TEST_ELEMENT, constraint.checkElement(TEST_ELEMENT));
- try {
- constraint.checkElement(null);
- fail("NullPointerException expected");
- } catch (NullPointerException expected) {}
- assertEquals("Not null", constraint.toString());
- }
-
public void testConstrainedCollectionLegal() {
Collection<String> collection = Lists.newArrayList("foo", "bar");
Collection<String> constrained = Constraints.constrainedCollection(
@@ -265,49 +253,6 @@
ASSERT.that(list).has().exactly("foo", "bar").inOrder();
}
- public void testConstrainedMultisetLegal() {
- Multiset<String> multiset = HashMultiset.create(asList("foo", "bar"));
- Multiset<String> constrained = Constraints.constrainedMultiset(
- multiset, TEST_CONSTRAINT);
- multiset.add(TEST_ELEMENT);
- constrained.add("qux");
- constrained.addAll(asList("cat", "dog"));
- constrained.add("cow", 2);
- assertTrue(multiset.equals(constrained));
- assertTrue(constrained.equals(multiset));
- assertEquals(multiset.toString(), constrained.toString());
- assertEquals(multiset.hashCode(), constrained.hashCode());
- ASSERT.that(multiset).has().exactly(
- "foo", "bar", TEST_ELEMENT, "qux", "cat", "dog", "cow", "cow");
- ASSERT.that(constrained).has().exactly(
- "foo", "bar", TEST_ELEMENT, "qux", "cat", "dog", "cow", "cow");
- assertEquals(1, constrained.count("foo"));
- assertEquals(1, constrained.remove("foo", 3));
- assertEquals(2, constrained.setCount("cow", 0));
- ASSERT.that(multiset).has().exactly("bar", TEST_ELEMENT, "qux", "cat", "dog");
- ASSERT.that(constrained).has().exactly("bar", TEST_ELEMENT, "qux", "cat", "dog");
- }
-
- public void testConstrainedMultisetIllegal() {
- Multiset<String> multiset = HashMultiset.create(asList("foo", "bar"));
- Multiset<String> constrained = Constraints.constrainedMultiset(
- multiset, TEST_CONSTRAINT);
- try {
- constrained.add(TEST_ELEMENT);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.add(TEST_ELEMENT, 2);
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- try {
- constrained.addAll(asList("baz", TEST_ELEMENT));
- fail("TestElementException expected");
- } catch (TestElementException expected) {}
- ASSERT.that(constrained).has().exactly("foo", "bar");
- ASSERT.that(multiset).has().exactly("foo", "bar");
- }
-
public void testNefariousAddAll() {
List<String> list = Lists.newArrayList("foo", "bar");
List<String> constrained = Constraints.constrainedList(
@@ -345,10 +290,5 @@
};
}
- @GwtIncompatible("SerializableTester")
- public void testSerialization() {
- // TODO: Test serialization of constrained collections.
- assertSame(Constraints.notNull(),
- SerializableTester.reserialize(Constraints.notNull()));
- }
+ // TODO: Test serialization of constrained collections.
}
diff --git a/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java b/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java
index ee47a1b..cfcdff7 100644
--- a/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java
+++ b/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java
@@ -72,10 +72,10 @@
random.nextBytes(bytes);
String s = new String(bytes, UTF_16LE.name()); // so all random strings are valid
assertEquals(
- new TestHasher().putString(s).hash(),
+ new TestHasher().putUnencodedChars(s).hash(),
new TestHasher().putBytes(s.getBytes(UTF_16LE.name())).hash());
assertEquals(
- new TestHasher().putString(s).hash(),
+ new TestHasher().putUnencodedChars(s).hash(),
new TestHasher().putString(s, UTF_16LE).hash());
}
}
diff --git a/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java b/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java
index e8a262e..a26be17 100644
--- a/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java
+++ b/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java
@@ -142,11 +142,6 @@
}
@Override
- public HashCode hashString(CharSequence input) {
- throw new UnsupportedOperationException();
- }
-
- @Override
public HashCode hashString(CharSequence input, Charset charset) {
throw new UnsupportedOperationException();
}
diff --git a/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java b/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java
index d4f2d2e..75eb13f 100644
--- a/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java
+++ b/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java
@@ -93,10 +93,10 @@
random.nextBytes(bytes);
String s = new String(bytes, UTF_16LE.name()); // so all random strings are valid
assertEquals(
- new Sink(4).putString(s).hash(),
+ new Sink(4).putUnencodedChars(s).hash(),
new Sink(4).putBytes(s.getBytes(UTF_16LE.name())).hash());
assertEquals(
- new Sink(4).putString(s).hash(),
+ new Sink(4).putUnencodedChars(s).hash(),
new Sink(4).putString(s, UTF_16LE).hash());
}
}
@@ -265,11 +265,6 @@
}
@Override
- public HashCode hashString(CharSequence input) {
- throw new UnsupportedOperationException();
- }
-
- @Override
public HashCode hashString(CharSequence input, Charset charset) {
throw new UnsupportedOperationException();
}
diff --git a/guava-tests/test/com/google/common/hash/HashCodeTest.java b/guava-tests/test/com/google/common/hash/HashCodeTest.java
index 121d983..196ef02 100644
--- a/guava-tests/test/com/google/common/hash/HashCodeTest.java
+++ b/guava-tests/test/com/google/common/hash/HashCodeTest.java
@@ -18,6 +18,7 @@
import static com.google.common.io.BaseEncoding.base16;
+import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.io.BaseEncoding;
import com.google.common.jdk5backport.Arrays;
@@ -168,7 +169,7 @@
}
public void testRoundTripHashCodeUsingBaseEncoding() {
- HashCode hash1 = Hashing.sha1().hashString("foo");
+ HashCode hash1 = Hashing.sha1().hashString("foo", Charsets.US_ASCII);
HashCode hash2 =
HashCode.fromBytes(BaseEncoding.base16().lowerCase().decode(hash1.toString()));
assertEquals(hash1, hash2);
@@ -201,18 +202,18 @@
}
public void testRoundTripHashCodeUsingFromString() {
- HashCode hash1 = Hashing.sha1().hashString("foo");
+ HashCode hash1 = Hashing.sha1().hashString("foo", Charsets.US_ASCII);
HashCode hash2 = HashCode.fromString(hash1.toString());
assertEquals(hash1, hash2);
}
public void testRoundTrip() {
for (ExpectedHashCode expected : expectedHashCodes) {
- String string = HashCodes.fromBytes(expected.bytes).toString();
+ String string = HashCode.fromBytes(expected.bytes).toString();
assertEquals(expected.toString, string);
assertEquals(
expected.toString,
- HashCodes.fromBytes(
+ HashCode.fromBytes(
BaseEncoding.base16().lowerCase().decode(string)).toString());
}
}
@@ -226,7 +227,7 @@
}
public void testFromStringFailsWithUpperCaseString() {
- String string = Hashing.sha1().hashString("foo").toString().toUpperCase();
+ String string = Hashing.sha1().hashString("foo", Charsets.US_ASCII).toString().toUpperCase();
try {
HashCode.fromString(string);
fail();
@@ -258,17 +259,17 @@
public void testIntWriteBytesTo() {
byte[] dest = new byte[4];
- HashCodes.fromInt(42).writeBytesTo(dest, 0, 4);
+ HashCode.fromInt(42).writeBytesTo(dest, 0, 4);
assertTrue(Arrays.equals(
- HashCodes.fromInt(42).asBytes(),
+ HashCode.fromInt(42).asBytes(),
dest));
}
public void testLongWriteBytesTo() {
byte[] dest = new byte[8];
- HashCodes.fromLong(42).writeBytesTo(dest, 0, 8);
+ HashCode.fromLong(42).writeBytesTo(dest, 0, 8);
assertTrue(Arrays.equals(
- HashCodes.fromLong(42).asBytes(),
+ HashCode.fromLong(42).asBytes(),
dest));
}
diff --git a/guava-tests/test/com/google/common/hash/HashingTest.java b/guava-tests/test/com/google/common/hash/HashingTest.java
index 2f369f2..89a2397 100644
--- a/guava-tests/test/com/google/common/hash/HashingTest.java
+++ b/guava-tests/test/com/google/common/hash/HashingTest.java
@@ -150,13 +150,6 @@
HashTestUtils.assertInvariants(Hashing.goodFastHash(256));
}
- public void testPadToLong() {
- assertEquals(0x1111111111111111L, Hashing.padToLong(HashCodes.fromLong(0x1111111111111111L)));
- assertEquals(0x9999999999999999L, Hashing.padToLong(HashCodes.fromLong(0x9999999999999999L)));
- assertEquals(0x0000000011111111L, Hashing.padToLong(HashCodes.fromInt(0x11111111)));
- assertEquals(0x0000000099999999L, Hashing.padToLong(HashCodes.fromInt(0x99999999)));
- }
-
public void testConsistentHash_correctness() {
long[] interestingValues = { -1, 0, 1, 2, Long.MAX_VALUE, Long.MIN_VALUE };
for (long h : interestingValues) {
diff --git a/guava-tests/test/com/google/common/io/ByteStreamsTest.java b/guava-tests/test/com/google/common/io/ByteStreamsTest.java
index 96a4ab0..fc5b99d 100644
--- a/guava-tests/test/com/google/common/io/ByteStreamsTest.java
+++ b/guava-tests/test/com/google/common/io/ByteStreamsTest.java
@@ -31,8 +31,6 @@
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
-import java.util.zip.CRC32;
-import java.util.zip.Checksum;
/**
* Unit test for {@link ByteStreams}.
@@ -386,21 +384,6 @@
assertEquals(bytes, out.toByteArray());
}
- public void testChecksum() throws IOException {
- InputSupplier<ByteArrayInputStream> asciiBytes =
- ByteStreams.newInputStreamSupplier(ASCII.getBytes(Charsets.US_ASCII.name()));
- InputSupplier<ByteArrayInputStream> i18nBytes =
- ByteStreams.newInputStreamSupplier(I18N.getBytes(Charsets.UTF_8.name()));
-
- Checksum checksum = new CRC32();
- assertEquals(0L, checksum.getValue());
- assertEquals(3145994718L, ByteStreams.getChecksum(asciiBytes, checksum));
- assertEquals(0L, checksum.getValue());
- assertEquals(3145994718L, ByteStreams.getChecksum(asciiBytes, checksum));
- assertEquals(1138302340L, ByteStreams.getChecksum(i18nBytes, checksum));
- assertEquals(0L, checksum.getValue());
- }
-
public void testNewDataOutput_BAOS() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayDataOutput out = ByteStreams.newDataOutput(baos);
diff --git a/guava-tests/test/com/google/common/io/CloseablesTest.java b/guava-tests/test/com/google/common/io/CloseablesTest.java
index a4cd1bb..e564e3c 100644
--- a/guava-tests/test/com/google/common/io/CloseablesTest.java
+++ b/guava-tests/test/com/google/common/io/CloseablesTest.java
@@ -67,14 +67,6 @@
doClose(mockCloseable, false);
}
- public void testCloseQuietly_closeableWithEatenException()
- throws IOException {
- // make sure that no exception is thrown by CloseQuietly when the mock does
- // throw an exception on close
- setupCloseable(true);
- Closeables.closeQuietly(mockCloseable);
- }
-
public void testCloseQuietly_inputStreamWithEatenException() throws IOException {
TestInputStream in = new TestInputStream(
new ByteArrayInputStream(new byte[1]), TestOption.CLOSE_THROWS);
@@ -91,7 +83,6 @@
public void testCloseNull() throws IOException {
Closeables.close(null, true);
Closeables.close(null, false);
- Closeables.closeQuietly((Closeable) null);
}
public void testCloseQuietlyNull_inputStream() {
diff --git a/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java b/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java
index c74e8a2..575eb7e 100644
--- a/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java
+++ b/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java
@@ -226,9 +226,9 @@
public void testLexicographicalComparatorDefaultChoice() {
Comparator<byte[]> defaultComparator =
UnsignedBytes.lexicographicalComparator();
- Comparator<byte[]> pureJavaComparator =
- UnsignedBytes.LexicographicalComparatorHolder.PureJavaComparator.INSTANCE;
- assertSame(defaultComparator, pureJavaComparator);
+ Comparator<byte[]> unsafeComparator =
+ UnsignedBytes.LexicographicalComparatorHolder.UnsafeComparator.INSTANCE;
+ assertSame(defaultComparator, unsafeComparator);
}
public void testLexicographicalComparator() {
diff --git a/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java b/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java
index 147ed64..1fc8756 100644
--- a/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java
+++ b/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java
@@ -433,22 +433,6 @@
return delegate.stopAsync();
}
- @Override public final ListenableFuture<State> start() {
- return delegate.start();
- }
-
- @Override public final ListenableFuture<State> stop() {
- return delegate.stop();
- }
-
- @Override public State startAndWait() {
- return delegate.startAndWait();
- }
-
- @Override public State stopAndWait() {
- return delegate.stopAndWait();
- }
-
@Override public final void awaitRunning() {
delegate.awaitRunning();
}
diff --git a/guava-tests/test/com/google/common/xml/XmlEscapersTest.java b/guava-tests/test/com/google/common/xml/XmlEscapersTest.java
index 5052962..148a719 100644
--- a/guava-tests/test/com/google/common/xml/XmlEscapersTest.java
+++ b/guava-tests/test/com/google/common/xml/XmlEscapersTest.java
@@ -82,8 +82,8 @@
assertUnescaped(xmlEscaper, ch);
}
} else {
- // and everything else is replaced with FFFD.
- assertEscaping(xmlEscaper, "\uFFFD", ch);
+ // and everything else is removed.
+ assertEscaping(xmlEscaper, "", ch);
}
}
@@ -109,13 +109,18 @@
}
}
- // Test that 0xFFFE and 0xFFFF are replaced with 0xFFFD
- assertEscaping(xmlEscaper, "\uFFFD", '\uFFFE');
- assertEscaping(xmlEscaper, "\uFFFD", '\uFFFF');
+ // TODO(user): Change once this escaper forbids \uFFFE and \uFFFF.
- assertEquals("0xFFFE is forbidden and should be replaced during escaping",
- "[\uFFFD]", xmlEscaper.escape("[\ufffe]"));
- assertEquals("0xFFFF is forbidden and should be replaced during escaping",
- "[\uFFFD]", xmlEscaper.escape("[\uffff]"));
+ assertUnescaped(xmlEscaper, '\uFFFE');
+ assertUnescaped(xmlEscaper, '\uFFFF');
+
+ // Test that 0xFFFE and 0xFFFF are removed
+ // assertEscaping(xmlEscaper, "", '\uFFFE');
+ // assertEscaping(xmlEscaper, "", '\uFFFF');
+
+ // assertEquals("0xFFFE is forbidden and should be removed during escaping",
+ // "[]", XmlEscapers.xmlEscaper().escape("[\ufffe]"));
+ // assertEquals("0xFFFF is forbidden and should be removed during escaping",
+ // "[]", XmlEscapers.xmlEscaper().escape("[\uffff]"));
}
}
diff --git a/guava/src/com/google/common/base/Stopwatch.java b/guava/src/com/google/common/base/Stopwatch.java
index 88e5543..bce13fd 100644
--- a/guava/src/com/google/common/base/Stopwatch.java
+++ b/guava/src/com/google/common/base/Stopwatch.java
@@ -120,11 +120,10 @@
* Creates (but does not start) a new stopwatch using {@link System#nanoTime}
* as its time source.
*
- * @deprecated Use {@link Stopwatch#createUnstarted()} instead. This
- * constructor is scheduled to be removed in Guava release 17.0.
+ * @deprecated Use {@link Stopwatch#createUnstarted()} instead.
*/
@Deprecated
- public Stopwatch() {
+ Stopwatch() {
this(Ticker.systemTicker());
}
@@ -132,11 +131,10 @@
* Creates (but does not start) a new stopwatch, using the specified time
* source.
*
- * @deprecated Use {@link Stopwatch#createUnstarted(Ticker)} instead. This
- * constructor is scheduled to be removed in Guava release 17.0.
+ * @deprecated Use {@link Stopwatch#createUnstarted(Ticker)} instead.
*/
@Deprecated
- public Stopwatch(Ticker ticker) {
+ Stopwatch(Ticker ticker) {
this.ticker = checkNotNull(ticker, "ticker");
}
diff --git a/guava/src/com/google/common/cache/Striped64.java b/guava/src/com/google/common/cache/Striped64.java
index bb95eb9..e045453 100644
--- a/guava/src/com/google/common/cache/Striped64.java
+++ b/guava/src/com/google/common/cache/Striped64.java
@@ -12,8 +12,6 @@
package com.google.common.cache;
import java.util.Random;
-import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
-import java.util.concurrent.atomic.AtomicLongFieldUpdater;
/**
* A package-local class holding common representation and mechanics
@@ -93,19 +91,29 @@
* form of CAS here, if it were provided.
*/
static final class Cell {
- @SuppressWarnings("UnusedDeclaration")
volatile long p0, p1, p2, p3, p4, p5, p6;
volatile long value;
- @SuppressWarnings("UnusedDeclaration")
volatile long q0, q1, q2, q3, q4, q5, q6;
Cell(long x) { value = x; }
final boolean cas(long cmp, long val) {
- return valueUpdater.compareAndSet(this, cmp, val);
+ return UNSAFE.compareAndSwapLong(this, valueOffset, cmp, val);
}
- private static final AtomicLongFieldUpdater<Cell> valueUpdater =
- AtomicLongFieldUpdater.newUpdater(Cell.class, "value");
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long valueOffset;
+ static {
+ try {
+ UNSAFE = getUnsafe();
+ Class<?> ak = Cell.class;
+ valueOffset = UNSAFE.objectFieldOffset
+ (ak.getDeclaredField("value"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
}
/**
@@ -165,14 +173,14 @@
* CASes the base field.
*/
final boolean casBase(long cmp, long val) {
- return baseUpdater.compareAndSet(this, cmp, val);
+ return UNSAFE.compareAndSwapLong(this, baseOffset, cmp, val);
}
/**
* CASes the busy field from 0 to 1 to acquire lock.
*/
final boolean casBusy() {
- return busyUpdater.compareAndSet(this, 0, 1);
+ return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
/**
@@ -238,7 +246,8 @@
try {
if (cells == as) { // Expand table unless stale
Cell[] rs = new Cell[n << 1];
- System.arraycopy(as, 0, rs, 0, n);
+ for (int i = 0; i < n; ++i)
+ rs[i] = as[i];
cells = rs;
}
} finally {
@@ -279,15 +288,60 @@
Cell[] as = cells;
base = initialValue;
if (as != null) {
- for (Cell a : as) {
+ int n = as.length;
+ for (int i = 0; i < n; ++i) {
+ Cell a = as[i];
if (a != null)
- a.value = initialValue;
+ a.value = initialValue;
}
}
}
- private static final AtomicLongFieldUpdater<Striped64> baseUpdater =
- AtomicLongFieldUpdater.newUpdater(Striped64.class, "base");
- private static final AtomicIntegerFieldUpdater<Striped64> busyUpdater =
- AtomicIntegerFieldUpdater.newUpdater(Striped64.class, "busy");
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long baseOffset;
+ private static final long busyOffset;
+ static {
+ try {
+ UNSAFE = getUnsafe();
+ Class<?> sk = Striped64.class;
+ baseOffset = UNSAFE.objectFieldOffset
+ (sk.getDeclaredField("base"));
+ busyOffset = UNSAFE.objectFieldOffset
+ (sk.getDeclaredField("busy"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ /**
+ * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package.
+ * Replace with a simple call to Unsafe.getUnsafe when integrating
+ * into a jdk.
+ *
+ * @return a sun.misc.Unsafe
+ */
+ private static sun.misc.Unsafe getUnsafe() {
+ try {
+ return sun.misc.Unsafe.getUnsafe();
+ } catch (SecurityException tryReflectionInstead) {}
+ try {
+ return java.security.AccessController.doPrivileged
+ (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
+ public sun.misc.Unsafe run() throws Exception {
+ Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
+ for (java.lang.reflect.Field f : k.getDeclaredFields()) {
+ f.setAccessible(true);
+ Object x = f.get(null);
+ if (k.isInstance(x))
+ return k.cast(x);
+ }
+ throw new NoSuchFieldError("the Unsafe");
+ }});
+ } catch (java.security.PrivilegedActionException e) {
+ throw new RuntimeException("Could not initialize intrinsics",
+ e.getCause());
+ }
+ }
+
}
diff --git a/guava/src/com/google/common/collect/Constraint.java b/guava/src/com/google/common/collect/Constraint.java
index 48b244b..d8f510a 100644
--- a/guava/src/com/google/common/collect/Constraint.java
+++ b/guava/src/com/google/common/collect/Constraint.java
@@ -16,9 +16,7 @@
package com.google.common.collect;
-import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
-import com.google.common.base.Preconditions;
/**
* A constraint that an element must satisfy in order to be added to a
@@ -40,21 +38,9 @@
* that all the collection's elements meet the constraint, since the constraint
* is only enforced when elements are added.
*
- * @see Constraints
- * @see MapConstraint
* @author Mike Bostock
- * @since 3.0
- * @deprecated Use {@link Preconditions} for basic checks. In place of
- * constrained collections, we encourage you to check your preconditions
- * explicitly instead of leaving that work to the collection implementation.
- * For the specific case of rejecting null, consider the immutable
- * collections.
- * This interface is scheduled for removal in Guava 16.0.
*/
-@Beta
-@Deprecated
@GwtCompatible
-public
interface Constraint<E> {
/**
* Throws a suitable {@code RuntimeException} if the specified element is
diff --git a/guava/src/com/google/common/collect/Constraints.java b/guava/src/com/google/common/collect/Constraints.java
index 169a40c..2b5da00 100644
--- a/guava/src/com/google/common/collect/Constraints.java
+++ b/guava/src/com/google/common/collect/Constraints.java
@@ -18,9 +18,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
-import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
-import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.List;
@@ -32,47 +30,13 @@
/**
* Factories and utilities pertaining to the {@link Constraint} interface.
*
- * @see MapConstraints
* @author Mike Bostock
* @author Jared Levy
- * @since 3.0
- * @deprecated Use {@link Preconditions} for basic checks. In place of
- * constrained collections, we encourage you to check your preconditions
- * explicitly instead of leaving that work to the collection implementation.
- * For the specific case of rejecting null, consider the immutable
- * collections.
- * This class is scheduled for removal in Guava 16.0.
*/
-@Beta
-@Deprecated
@GwtCompatible
-public final class Constraints {
+final class Constraints {
private Constraints() {}
- // enum singleton pattern
- private enum NotNullConstraint implements Constraint<Object> {
- INSTANCE;
-
- @Override
- public Object checkElement(Object element) {
- return checkNotNull(element);
- }
-
- @Override public String toString() {
- return "Not null";
- }
- }
-
- /**
- * Returns a constraint that verifies that the element is not null. If the
- * element is null, a {@link NullPointerException} is thrown.
- */
- // safe to narrow the type since checkElement returns its argument directly
- @SuppressWarnings("unchecked")
- public static <E> Constraint<E> notNull() {
- return (Constraint<E>) NotNullConstraint.INSTANCE;
- }
-
/**
* Returns a constrained view of the specified collection, using the specified
* constraint. Any operations that add new elements to the collection will
@@ -324,56 +288,6 @@
}
}
- /**
- * Returns a constrained view of the specified multiset, using the specified
- * constraint. Any operations that add new elements to the multiset will call
- * the provided constraint. However, this method does not verify that
- * existing elements satisfy the constraint.
- *
- * <p>The returned multiset is not serializable.
- *
- * @param multiset the multiset to constrain
- * @param constraint the constraint that validates added elements
- * @return a constrained view of the multiset
- */
- public static <E> Multiset<E> constrainedMultiset(
- Multiset<E> multiset, Constraint<? super E> constraint) {
- return new ConstrainedMultiset<E>(multiset, constraint);
- }
-
- /** @see Constraints#constrainedMultiset */
- static class ConstrainedMultiset<E> extends ForwardingMultiset<E> {
- private Multiset<E> delegate;
- private final Constraint<? super E> constraint;
-
- public ConstrainedMultiset(
- Multiset<E> delegate, Constraint<? super E> constraint) {
- this.delegate = checkNotNull(delegate);
- this.constraint = checkNotNull(constraint);
- }
- @Override protected Multiset<E> delegate() {
- return delegate;
- }
- @Override public boolean add(E element) {
- return standardAdd(element);
- }
- @Override public boolean addAll(Collection<? extends E> elements) {
- return delegate.addAll(checkElements(elements, constraint));
- }
- @Override public int add(E element, int occurrences) {
- constraint.checkElement(element);
- return delegate.add(element, occurrences);
- }
- @Override public int setCount(E element, int count) {
- constraint.checkElement(element);
- return delegate.setCount(element, count);
- }
- @Override public boolean setCount(E element, int oldCount, int newCount) {
- constraint.checkElement(element);
- return delegate.setCount(element, oldCount, newCount);
- }
- }
-
/*
* TODO(kevinb): For better performance, avoid making a copy of the elements
* by having addAll() call add() repeatedly instead.
diff --git a/guava/src/com/google/common/collect/FluentIterable.java b/guava/src/com/google/common/collect/FluentIterable.java
index 7883763..87a041a 100644
--- a/guava/src/com/google/common/collect/FluentIterable.java
+++ b/guava/src/com/google/common/collect/FluentIterable.java
@@ -425,64 +425,6 @@
}
/**
- * Returns an {@code ImmutableList} containing all of the elements from this
- * fluent iterable in proper sequence.
- *
- * @deprecated Use {@link #toList()} instead. This method is scheduled for removal in Guava 15.0.
- */
- @Deprecated
- public final ImmutableList<E> toImmutableList() {
- return toList();
- }
-
- /**
- * Returns an {@code ImmutableList} containing all of the elements from this
- * {@code FluentIterable} in the order specified by {@code comparator}. To produce an
- * {@code ImmutableList} sorted by its natural ordering, use
- * {@code toSortedImmutableList(Ordering.natural())}.
- *
- * @param comparator the function by which to sort list elements
- * @throws NullPointerException if any element is null
- * @since 13.0
- * @deprecated Use {@link #toSortedList(Comparator)} instead. This method is scheduled for removal
- * in Guava 15.0.
- */
- @Deprecated
- public final ImmutableList<E> toSortedImmutableList(
- Comparator<? super E> comparator) {
- return toSortedList(comparator);
- }
-
- /**
- * Returns an {@code ImmutableSet} containing all of the elements from this
- * fluent iterable with duplicates removed.
- *
- * @deprecated Use {@link #toSet()} instead. This method is scheduled for removal in Guava 15.0.
- */
- @Deprecated
- public final ImmutableSet<E> toImmutableSet() {
- return toSet();
- }
-
- /**
- * Returns an {@code ImmutableSortedSet} containing all of the elements from this
- * {@code FluentIterable} in the order specified by {@code comparator}, with duplicates
- * (determined by {@code comparator.compare(x, y) == 0}) removed. To produce an
- * {@code ImmutableSortedSet} sorted by its natural ordering, use
- * {@code toImmutableSortedSet(Ordering.natural())}.
- *
- * @param comparator the function by which to sort set elements
- * @throws NullPointerException if any element is null
- * @deprecated Use {@link #toSortedSet(Comparator)} instead. This method is scheduled for removal
- * in Guava 15.0.
- */
- @Deprecated
- public final ImmutableSortedSet<E> toImmutableSortedSet(
- Comparator<? super E> comparator) {
- return toSortedSet(comparator);
- }
-
- /**
* Returns an array containing all of the elements from this fluent iterable in iteration order.
*
* @param type the type of the elements
diff --git a/guava/src/com/google/common/collect/ForwardingSortedMap.java b/guava/src/com/google/common/collect/ForwardingSortedMap.java
index 55cd6ed..1235e56 100644
--- a/guava/src/com/google/common/collect/ForwardingSortedMap.java
+++ b/guava/src/com/google/common/collect/ForwardingSortedMap.java
@@ -22,7 +22,6 @@
import com.google.common.annotations.GwtCompatible;
import java.util.Comparator;
-import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.SortedMap;
@@ -144,43 +143,6 @@
}
/**
- * A sensible definition of {@link #remove} in terms of the {@code
- * iterator()} of the {@code entrySet()} of {@link #tailMap}. If you override
- * {@link #tailMap}, you may wish to override {@link #remove} to forward
- * to this implementation.
- *
- * @since 7.0
- * @deprecated This implementation is extremely awkward, is rarely worthwhile,
- * and has been discovered to interact badly with
- * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6467933 in Java 6
- * when used with certain null-friendly comparators. It is scheduled for
- * deletion in Guava 16.0.
- */
- @Deprecated
- @Override @Beta protected V standardRemove(@Nullable Object key) {
- try {
- // any CCE will be caught
- @SuppressWarnings("unchecked")
- SortedMap<Object, V> self = (SortedMap<Object, V>) this;
- Iterator<Entry<Object, V>> entryIterator =
- self.tailMap(key).entrySet().iterator();
- if (entryIterator.hasNext()) {
- Entry<Object, V> ceilingEntry = entryIterator.next();
- if (unsafeCompare(ceilingEntry.getKey(), key) == 0) {
- V value = ceilingEntry.getValue();
- entryIterator.remove();
- return value;
- }
- }
- } catch (ClassCastException e) {
- return null;
- } catch (NullPointerException e) {
- return null;
- }
- return null;
- }
-
- /**
* A sensible default implementation of {@link #subMap(Object, Object)} in
* terms of {@link #headMap(Object)} and {@link #tailMap(Object)}. In some
* situations, you may wish to override {@link #subMap(Object, Object)} to
diff --git a/guava/src/com/google/common/collect/GenericMapMaker.java b/guava/src/com/google/common/collect/GenericMapMaker.java
index b7b5fe3..a491489 100644
--- a/guava/src/com/google/common/collect/GenericMapMaker.java
+++ b/guava/src/com/google/common/collect/GenericMapMaker.java
@@ -42,12 +42,12 @@
* "Generic" equivalent; simple use {@code CacheBuilder} naturally. For general migration
* instructions, see the <a
* href="http://code.google.com/p/guava-libraries/wiki/MapMakerMigration">MapMaker Migration
- * Guide</a>. This class is scheduled for removal in Guava 16.0.
+ * Guide</a>.
*/
@Beta
@Deprecated
@GwtCompatible(emulated = true)
-public abstract class GenericMapMaker<K0, V0> {
+abstract class GenericMapMaker<K0, V0> {
@GwtIncompatible("To be supported")
enum NullListener implements RemovalListener<Object, Object> {
INSTANCE;
@@ -146,6 +146,6 @@
* See {@link MapMaker#makeComputingMap}.
*/
@Deprecated
- public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
+ abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
Function<? super K, ? extends V> computingFunction);
}
diff --git a/guava/src/com/google/common/collect/MapMaker.java b/guava/src/com/google/common/collect/MapMaker.java
index 82a66f9..b2f9283 100644
--- a/guava/src/com/google/common/collect/MapMaker.java
+++ b/guava/src/com/google/common/collect/MapMaker.java
@@ -578,11 +578,10 @@
* by {@link com.google.common.cache.CacheBuilder#build}. See the
* <a href="http://code.google.com/p/guava-libraries/wiki/MapMakerMigration">MapMaker
* Migration Guide</a> for more details.
- * <b>This method is scheduled for deletion after upgrading Android to Guava 17.0.</b>
*/
@Deprecated
@Override
- public <K, V> ConcurrentMap<K, V> makeComputingMap(
+ <K, V> ConcurrentMap<K, V> makeComputingMap(
Function<? super K, ? extends V> computingFunction) {
return (nullRemovalCause == null)
? new MapMaker.ComputingMapAdapter<K, V>(this, computingFunction)
diff --git a/guava/src/com/google/common/collect/Range.java b/guava/src/com/google/common/collect/Range.java
index d5c1d21..68a5d33 100644
--- a/guava/src/com/google/common/collect/Range.java
+++ b/guava/src/com/google/common/collect/Range.java
@@ -18,18 +18,15 @@
import static com.google.common.base.Preconditions.checkNotNull;
-import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Equivalence;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import java.io.Serializable;
-import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import java.util.Set;
import java.util.SortedSet;
import javax.annotation.Nullable;
@@ -431,7 +428,7 @@
* can't be constructed at all.)
*
* <p>Note that certain discrete ranges such as the integer range {@code (3..4)} are <b>not</b>
- * considered empty, even though they contain no actual values. In these cases, it may be
+ * considered empty, even though they contain no actual values. In these cases, it may be
* helpful to preprocess ranges with {@link #canonical(DiscreteDomain)}.
*/
public boolean isEmpty() {
@@ -532,9 +529,9 @@
*
* <p>The connectedness relation is both reflexive and symmetric, but does not form an {@linkplain
* Equivalence equivalence relation} as it is not transitive.
- *
+ *
* <p>Note that certain discrete ranges are not considered connected, even though there are no
- * elements "between them." For example, {@code [3, 5]} is not considered connected to {@code
+ * elements "between them." For example, {@code [3, 5]} is not considered connected to {@code
* [6, 10]}. In these cases, it may be desirable for both input ranges to be preprocessed with
* {@link #canonical(DiscreteDomain)} before testing for connectedness.
*/
@@ -599,33 +596,6 @@
}
/**
- * Returns an {@link ContiguousSet} containing the same values in the given domain
- * {@linkplain Range#contains contained} by this range.
- *
- * <p><b>Note:</b> {@code a.asSet(d).equals(b.asSet(d))} does not imply {@code a.equals(b)}! For
- * example, {@code a} and {@code b} could be {@code [2..4]} and {@code (1..5)}, or the empty
- * ranges {@code [3..3)} and {@code [4..4)}.
- *
- * <p><b>Warning:</b> Be extremely careful what you do with the {@code asSet} view of a large
- * range (such as {@code Range.greaterThan(0)}). Certain operations on such a set can be
- * performed efficiently, but others (such as {@link Set#hashCode} or {@link
- * Collections#frequency}) can cause major performance problems.
- *
- * <p>The returned set's {@link Object#toString} method returns a short-hand form of the set's
- * contents, such as {@code "[1..100]}"}.
- *
- * @throws IllegalArgumentException if neither this range nor the domain has a lower bound, or if
- * neither has an upper bound
- * @deprecated Use {@code ContiguousSet.create(range, domain)}. To be removed in Guava 16.0.
- */
- @Beta
- @GwtCompatible(serializable = false)
- @Deprecated
- public ContiguousSet<C> asSet(DiscreteDomain<C> domain) {
- return ContiguousSet.create(this, domain);
- }
-
- /**
* Returns the canonical form of this range in the given domain. The canonical form has the
* following properties:
*
diff --git a/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java b/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java
index c70422e..43d5fa9 100644
--- a/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java
+++ b/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java
@@ -122,14 +122,6 @@
return this;
}
- /**
- * @deprecated Use {@link Hasher#putUnencodedChars} instead.
- */
- @Deprecated
- @Override public Hasher putString(CharSequence chars) {
- return putUnencodedChars(chars);
- }
-
@Override public Hasher putUnencodedChars(CharSequence chars) {
for (Hasher hasher : hashers) {
hasher.putUnencodedChars(chars);
diff --git a/guava/src/com/google/common/hash/AbstractHasher.java b/guava/src/com/google/common/hash/AbstractHasher.java
index 60f4649..bbb3f17 100644
--- a/guava/src/com/google/common/hash/AbstractHasher.java
+++ b/guava/src/com/google/common/hash/AbstractHasher.java
@@ -37,14 +37,6 @@
return putInt(Float.floatToRawIntBits(f));
}
- /**
- * @deprecated Use {@link AbstractHasher#putUnencodedChars} instead.
- */
- @Deprecated
- @Override public Hasher putString(CharSequence charSequence) {
- return putUnencodedChars(charSequence);
- }
-
@Override public Hasher putUnencodedChars(CharSequence charSequence) {
for (int i = 0, len = charSequence.length(); i < len; i++) {
putChar(charSequence.charAt(i));
diff --git a/guava/src/com/google/common/hash/AbstractNonStreamingHashFunction.java b/guava/src/com/google/common/hash/AbstractNonStreamingHashFunction.java
index 1972759..35aae75 100644
--- a/guava/src/com/google/common/hash/AbstractNonStreamingHashFunction.java
+++ b/guava/src/com/google/common/hash/AbstractNonStreamingHashFunction.java
@@ -46,14 +46,6 @@
return newHasher().putObject(instance, funnel).hash();
}
- /**
- * @deprecated Use {@link AbstractNonStreamingHashFunction#hashUnencodedChars} instead.
- */
- @Deprecated
- @Override public HashCode hashString(CharSequence input) {
- return hashUnencodedChars(input);
- }
-
@Override public HashCode hashUnencodedChars(CharSequence input) {
int len = input.length();
Hasher hasher = newHasher(len * 2);
diff --git a/guava/src/com/google/common/hash/AbstractStreamingHashFunction.java b/guava/src/com/google/common/hash/AbstractStreamingHashFunction.java
index c34feaa..302399f 100644
--- a/guava/src/com/google/common/hash/AbstractStreamingHashFunction.java
+++ b/guava/src/com/google/common/hash/AbstractStreamingHashFunction.java
@@ -37,14 +37,6 @@
return newHasher().putObject(instance, funnel).hash();
}
- /**
- * @deprecated Use {@link AbstractStreamingHashFunction#hashUnencodedChars} instead.
- */
- @Deprecated
- @Override public HashCode hashString(CharSequence input) {
- return hashUnencodedChars(input);
- }
-
@Override public HashCode hashUnencodedChars(CharSequence input) {
return newHasher().putUnencodedChars(input).hash();
}
@@ -183,15 +175,6 @@
return this;
}
- /**
- * @deprecated Use {@link AbstractStreamingHasher#putUnencodedChars} instead.
- */
- @Deprecated
- @Override
- public final Hasher putString(CharSequence charSequence) {
- return putUnencodedChars(charSequence);
- }
-
@Override
public final Hasher putUnencodedChars(CharSequence charSequence) {
for (int i = 0; i < charSequence.length(); i++) {
diff --git a/guava/src/com/google/common/hash/Funnels.java b/guava/src/com/google/common/hash/Funnels.java
index 9058916..08b814a 100644
--- a/guava/src/com/google/common/hash/Funnels.java
+++ b/guava/src/com/google/common/hash/Funnels.java
@@ -63,17 +63,6 @@
return UnencodedCharsFunnel.INSTANCE;
}
- /**
- * Returns a funnel that extracts the characters from a {@code CharSequence}.
- *
- * @deprecated Use {@link Funnels#unencodedCharsFunnel} instead. This method is scheduled for
- * removal in Guava 16.0.
- */
- @Deprecated
- public static Funnel<CharSequence> stringFunnel() {
- return unencodedCharsFunnel();
- }
-
private enum UnencodedCharsFunnel implements Funnel<CharSequence> {
INSTANCE;
@@ -137,7 +126,7 @@
private Object readResolve() {
return stringFunnel(Charset.forName(charsetCanonicalName));
}
-
+
private static final long serialVersionUID = 0;
}
}
@@ -205,45 +194,45 @@
/**
* Returns a funnel for longs.
- *
+ *
* @since 13.0
*/
public static Funnel<Long> longFunnel() {
return LongFunnel.INSTANCE;
}
-
+
private enum LongFunnel implements Funnel<Long> {
INSTANCE;
-
+
public void funnel(Long from, PrimitiveSink into) {
into.putLong(from);
}
-
+
@Override public String toString() {
return "Funnels.longFunnel()";
}
}
-
+
/**
* Wraps a {@code PrimitiveSink} as an {@link OutputStream}, so it is easy to
* {@link Funnel#funnel funnel} an object to a {@code PrimitiveSink}
- * if there is already a way to write the contents of the object to an {@code OutputStream}.
- *
+ * if there is already a way to write the contents of the object to an {@code OutputStream}.
+ *
* <p>The {@code close} and {@code flush} methods of the returned {@code OutputStream}
* do nothing, and no method throws {@code IOException}.
- *
+ *
* @since 13.0
*/
public static OutputStream asOutputStream(PrimitiveSink sink) {
return new SinkAsStream(sink);
}
-
+
private static class SinkAsStream extends OutputStream {
final PrimitiveSink sink;
SinkAsStream(PrimitiveSink sink) {
this.sink = Preconditions.checkNotNull(sink);
}
-
+
@Override public void write(int b) {
sink.putByte((byte) b);
}
@@ -255,7 +244,7 @@
@Override public void write(byte[] bytes, int off, int len) {
sink.putBytes(bytes, off, len);
}
-
+
@Override public String toString() {
return "Funnels.asOutputStream(" + sink + ")";
}
diff --git a/guava/src/com/google/common/hash/HashCodes.java b/guava/src/com/google/common/hash/HashCodes.java
deleted file mode 100644
index 8de5970..0000000
--- a/guava/src/com/google/common/hash/HashCodes.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.google.common.hash;
-
-import com.google.common.annotations.Beta;
-
-import java.io.Serializable;
-
-/**
- * Static factories for creating {@link HashCode} instances; most users should never have to use
- * this. All returned instances are {@link Serializable}.
- *
- * @author Dimitris Andreou
- * @since 12.0
- * @deprecated Use the duplicated methods in {@link HashCode} instead. This class is scheduled
- * to be removed in Guava 16.0.
- */
-@Beta
-@Deprecated
-public final class HashCodes {
- private HashCodes() {}
-
- /**
- * Creates a 32-bit {@code HashCode}, of which the bytes will form the passed int, interpreted
- * in little endian order.
- *
- * @deprecated Use {@link HashCode#fromInt} instead. This method is scheduled to be removed in
- * Guava 16.0.
- */
- @Deprecated
- public static HashCode fromInt(int hash) {
- return HashCode.fromInt(hash);
- }
-
- /**
- * Creates a 64-bit {@code HashCode}, of which the bytes will form the passed long, interpreted
- * in little endian order.
- *
- * @deprecated Use {@link HashCode#fromLong} instead. This method is scheduled to be removed in
- * Guava 16.0.
- */
- @Deprecated
- public static HashCode fromLong(long hash) {
- return HashCode.fromLong(hash);
- }
-
- /**
- * Creates a {@code HashCode} from a byte array. The array is defensively copied to preserve
- * the immutability contract of {@code HashCode}. The array cannot be empty.
- *
- * @deprecated Use {@link HashCode#fromBytes} instead. This method is scheduled to be removed in
- * Guava 16.0.
- */
- @Deprecated
- public static HashCode fromBytes(byte[] bytes) {
- return HashCode.fromBytes(bytes);
- }
-}
diff --git a/guava/src/com/google/common/hash/HashFunction.java b/guava/src/com/google/common/hash/HashFunction.java
index 46a6ed9..2007ba8 100644
--- a/guava/src/com/google/common/hash/HashFunction.java
+++ b/guava/src/com/google/common/hash/HashFunction.java
@@ -194,18 +194,6 @@
HashCode hashUnencodedChars(CharSequence input);
/**
- * Shortcut for {@code newHasher().putUnencodedChars(input).hash()}. The implementation
- * <i>might</i> perform better than its longhand equivalent, but should not perform worse.
- * Note that no character encoding is performed; the low byte and high byte of each {@code char}
- * are hashed directly (in that order).
- *
- * @deprecated Use {@link HashFunction#hashUnencodedChars} instead. This method is scheduled for
- * removal in Guava 16.0.
- */
- @Deprecated
- HashCode hashString(CharSequence input);
-
- /**
* Shortcut for {@code newHasher().putString(input, charset).hash()}. Characters are encoded
* using the given {@link Charset}. The implementation <i>might</i> perform better than its
* longhand equivalent, but should not perform worse.
diff --git a/guava/src/com/google/common/hash/Hasher.java b/guava/src/com/google/common/hash/Hasher.java
index 1565bd4..2dd4a9a 100644
--- a/guava/src/com/google/common/hash/Hasher.java
+++ b/guava/src/com/google/common/hash/Hasher.java
@@ -83,16 +83,6 @@
@Override Hasher putUnencodedChars(CharSequence charSequence);
/**
- * Equivalent to processing each {@code char} value in the {@code CharSequence}, in order.
- * The input must not be updated while this method is in progress.
- *
- * @deprecated Use {@link Hasher#putUnencodedChars} instead. This method is scheduled for
- * removal in Guava 16.0.
- */
- @Deprecated
- @Override Hasher putString(CharSequence charSequence);
-
- /**
* Equivalent to {@code putBytes(charSequence.toString().getBytes(charset))}.
*/
@Override Hasher putString(CharSequence charSequence, Charset charset);
diff --git a/guava/src/com/google/common/hash/Hashing.java b/guava/src/com/google/common/hash/Hashing.java
index 9f926d2..f8faf69 100644
--- a/guava/src/com/google/common/hash/Hashing.java
+++ b/guava/src/com/google/common/hash/Hashing.java
@@ -290,19 +290,6 @@
}
/**
- * If {@code hashCode} has enough bits, returns {@code hashCode.asLong()}, otherwise
- * returns a {@code long} value with {@code hashCode.asInt()} as the least-significant
- * four bytes and {@code 0x00} as each of the most-significant four bytes.
- *
- * @deprecated Use {@code HashCode.padToLong()} instead. This method is scheduled to be
- * removed in Guava 15.0.
- */
- @Deprecated
- public static long padToLong(HashCode hashCode) {
- return hashCode.padToLong();
- }
-
- /**
* Assigns to {@code hashCode} a "bucket" in the range {@code [0, buckets)}, in a uniform
* manner that minimizes the need for remapping as {@code buckets} grows. That is,
* {@code consistentHash(h, n)} equals:
diff --git a/guava/src/com/google/common/hash/Murmur3_32HashFunction.java b/guava/src/com/google/common/hash/Murmur3_32HashFunction.java
index 1c43d30..db6e673 100644
--- a/guava/src/com/google/common/hash/Murmur3_32HashFunction.java
+++ b/guava/src/com/google/common/hash/Murmur3_32HashFunction.java
@@ -102,7 +102,7 @@
}
// TODO(user): Maybe implement #hashBytes instead?
- @Override public HashCode hashString(CharSequence input) {
+ @Override public HashCode hashUnencodedChars(CharSequence input) {
int h1 = seed;
// step through the CharSequence 2 chars at a time
diff --git a/guava/src/com/google/common/hash/PrimitiveSink.java b/guava/src/com/google/common/hash/PrimitiveSink.java
index 43a9cc1..d0f7af1 100644
--- a/guava/src/com/google/common/hash/PrimitiveSink.java
+++ b/guava/src/com/google/common/hash/PrimitiveSink.java
@@ -20,7 +20,7 @@
/**
* An object which can receive a stream of primitive values.
- *
+ *
* @author Kevin Bourrillion
* @since 12.0 (in 11.0 as {@code Sink})
*/
@@ -41,15 +41,15 @@
* @return this instance
*/
PrimitiveSink putBytes(byte[] bytes);
-
+
/**
* Puts a chunk of an array of bytes into this sink. {@code bytes[off]} is the first byte written,
- * {@code bytes[off + len - 1]} is the last.
- *
+ * {@code bytes[off + len - 1]} is the last.
+ *
* @param bytes a byte array
* @param off the start offset in the array
* @param len the number of bytes to write
- * @return this instance
+ * @return this instance
* @throws IndexOutOfBoundsException if {@code off < 0} or {@code off + len > bytes.length} or
* {@code len < 0}
*/
@@ -91,15 +91,6 @@
PrimitiveSink putChar(char c);
/**
- * Puts a string into this sink.
- *
- * @deprecated Use {PrimitiveSink#putUnencodedChars} instead. This method is scheduled for
- * removal in Guava 16.0.
- */
- @Deprecated
- PrimitiveSink putString(CharSequence charSequence);
-
- /**
* Puts each 16-bit code unit from the {@link CharSequence} into this sink.
*
* @since 15.0 (since 11.0 as putString(CharSequence))
diff --git a/guava/src/com/google/common/io/BaseEncoding.java b/guava/src/com/google/common/io/BaseEncoding.java
index fdde18e..051ddf5 100644
--- a/guava/src/com/google/common/io/BaseEncoding.java
+++ b/guava/src/com/google/common/io/BaseEncoding.java
@@ -189,26 +189,6 @@
}
/**
- * Returns an {@code OutputSupplier} that supplies streams that encode bytes using this encoding
- * into writers from the specified {@code OutputSupplier}.
- *
- * @deprecated Use {@link #encodingSink(CharSink)} instead. This method is scheduled to be
- * removed in Guava 16.0.
- */
- @Deprecated
- @GwtIncompatible("Writer,OutputStream")
- public final OutputSupplier<OutputStream> encodingStream(
- final OutputSupplier<? extends Writer> writerSupplier) {
- checkNotNull(writerSupplier);
- return new OutputSupplier<OutputStream>() {
- @Override
- public OutputStream getOutput() throws IOException {
- return encodingStream(writerSupplier.getOutput());
- }
- };
- }
-
- /**
* Returns a {@code ByteSink} that writes base-encoded bytes to the specified {@code CharSink}.
*/
@GwtIncompatible("ByteSink,CharSink")
@@ -284,26 +264,6 @@
}
/**
- * Returns an {@code InputSupplier} that supplies input streams that decode base-encoded input
- * from readers from the specified supplier.
- *
- * @deprecated Use {@link #decodingSource(CharSource)} instead. This method is scheduled to be
- * removed in Guava 16.0.
- */
- @Deprecated
- @GwtIncompatible("Reader,InputStream")
- public final InputSupplier<InputStream> decodingStream(
- final InputSupplier<? extends Reader> readerSupplier) {
- checkNotNull(readerSupplier);
- return new InputSupplier<InputStream>() {
- @Override
- public InputStream getInput() throws IOException {
- return decodingStream(readerSupplier.getInput());
- }
- };
- }
-
- /**
* Returns a {@code ByteSource} that reads base-encoded bytes from the specified
* {@code CharSource}.
*/
diff --git a/guava/src/com/google/common/io/ByteStreams.java b/guava/src/com/google/common/io/ByteStreams.java
index 71c08fe..6d9bdfc 100644
--- a/guava/src/com/google/common/io/ByteStreams.java
+++ b/guava/src/com/google/common/io/ByteStreams.java
@@ -41,7 +41,6 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Arrays;
-import java.util.zip.Checksum;
/**
* Provides utility methods for working with byte arrays and I/O streams.
@@ -89,18 +88,6 @@
}
/**
- * Returns a new {@link ByteSource} that reads bytes from the given byte array.
- *
- * @since 14.0
- * @deprecated Use {@link ByteSource#wrap(byte[])} instead. This method is
- * scheduled to be removed in Guava 16.0.
- */
- @Deprecated
- public static ByteSource asByteSource(byte[] b) {
- return ByteSource.wrap(b);
- }
-
- /**
* Writes a byte array to an output stream from the given supplier.
*
* @param from the bytes to write
@@ -889,39 +876,6 @@
}
/**
- * Computes and returns the checksum value for a supplied input stream.
- * The checksum object is reset when this method returns successfully.
- *
- * @param supplier the input stream factory
- * @param checksum the checksum object
- * @return the result of {@link Checksum#getValue} after updating the
- * checksum object with all of the bytes in the stream
- * @throws IOException if an I/O error occurs
- * @deprecated Use {@code hash} with the {@code Hashing.crc32()} or
- * {@code Hashing.adler32()} hash functions instead. This method is
- * scheduled to be removed in Guava 15.0.
- */
- @Deprecated
- public static long getChecksum(
- InputSupplier<? extends InputStream> supplier, final Checksum checksum)
- throws IOException {
- checkNotNull(checksum);
- return readBytes(supplier, new ByteProcessor<Long>() {
- @Override
- public boolean processBytes(byte[] buf, int off, int len) {
- checksum.update(buf, off, len);
- return true;
- }
- @Override
- public Long getResult() {
- long result = checksum.getValue();
- checksum.reset();
- return result;
- }
- });
- }
-
- /**
* Computes the hash code of the data supplied by {@code supplier} using {@code
* hashFunction}.
*
diff --git a/guava/src/com/google/common/io/CharStreams.java b/guava/src/com/google/common/io/CharStreams.java
index 98f620a..4eccc56 100644
--- a/guava/src/com/google/common/io/CharStreams.java
+++ b/guava/src/com/google/common/io/CharStreams.java
@@ -77,18 +77,6 @@
}
/**
- * Returns a {@link CharSource} that reads the given string value.
- *
- * @since 14.0
- * @deprecated Use {@link CharSource#wrap(CharSequence)} instead. This method
- * is scheduled to be removed in Guava 16.0.
- */
- @Deprecated
- public static CharSource asCharSource(String string) {
- return CharSource.wrap(string);
- }
-
- /**
* Returns a factory that will supply instances of {@link InputStreamReader},
* using the given {@link InputStream} factory and character set.
*
diff --git a/guava/src/com/google/common/io/Closeables.java b/guava/src/com/google/common/io/Closeables.java
index f22e08e..d6f618b 100644
--- a/guava/src/com/google/common/io/Closeables.java
+++ b/guava/src/com/google/common/io/Closeables.java
@@ -88,32 +88,6 @@
}
/**
- * Equivalent to calling {@code close(closeable, true)}, but with no IOException in the signature.
- *
- * @param closeable the {@code Closeable} object to be closed, or null, in which case this method
- * does nothing
- * @deprecated Where possible, use the
- * <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html">
- * try-with-resources</a> statement if using JDK7 or {@link Closer} on JDK6 to close one or
- * more {@code Closeable} objects. This method is deprecated because it is easy to misuse and
- * may swallow IO exceptions that really should be thrown and handled. See
- * <a href="https://code.google.com/p/guava-libraries/issues/detail?id=1118">Guava issue
- * 1118</a> for a more detailed explanation of the reasons for deprecation and see
- * <a href="https://code.google.com/p/guava-libraries/wiki/ClosingResourcesExplained">
- * Closing Resources</a> for more information on the problems with closing {@code Closeable}
- * objects and some of the preferred solutions for handling it correctly. This method is
- * scheduled to be removed after upgrading Android to Guava 17.0.
- */
- @Deprecated
- public static void closeQuietly(@Nullable Closeable closeable) {
- try {
- close(closeable, true);
- } catch (IOException e) {
- logger.log(Level.SEVERE, "IOException should not have been thrown.", e);
- }
- }
-
- /**
* Closes the given {@link InputStream}, logging any {@code IOException} that's thrown rather
* than propagating it.
*
diff --git a/guava/src/com/google/common/io/FileBackedOutputStream.java b/guava/src/com/google/common/io/FileBackedOutputStream.java
index 8a0de58..cc1f7b6 100644
--- a/guava/src/com/google/common/io/FileBackedOutputStream.java
+++ b/guava/src/com/google/common/io/FileBackedOutputStream.java
@@ -119,19 +119,6 @@
}
/**
- * Returns a supplier that may be used to retrieve the data buffered
- * by this stream. This method returns the same object as
- * {@link #asByteSource()}.
- *
- * @deprecated Use {@link #asByteSource()} instead. This method is scheduled
- * to be removed in Guava 16.0.
- */
- @Deprecated
- public InputSupplier<InputStream> getSupplier() {
- return asByteSource();
- }
-
- /**
* Returns a readable {@link ByteSource} view of the data that has been
* written to this stream.
*
diff --git a/guava/src/com/google/common/io/Files.java b/guava/src/com/google/common/io/Files.java
index 86feac2..86cfe9d 100644
--- a/guava/src/com/google/common/io/Files.java
+++ b/guava/src/com/google/common/io/Files.java
@@ -52,7 +52,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import java.util.zip.Checksum;
/**
* Provides utility methods for working with files.
@@ -759,25 +758,6 @@
}
/**
- * Computes and returns the checksum value for a file.
- * The checksum object is reset when this method returns successfully.
- *
- * @param file the file to read
- * @param checksum the checksum object
- * @return the result of {@link Checksum#getValue} after updating the
- * checksum object with all of the bytes in the file
- * @throws IOException if an I/O error occurs
- * @deprecated Use {@code hash} with the {@code Hashing.crc32()} or
- * {@code Hashing.adler32()} hash functions. This method is scheduled
- * to be removed in Guava 15.0.
- */
- @Deprecated
- public static long getChecksum(File file, Checksum checksum)
- throws IOException {
- return ByteStreams.getChecksum(newInputStreamSupplier(file), checksum);
- }
-
- /**
* Computes the hash code of the {@code file} using {@code hashFunction}.
*
* @param file the file to read
diff --git a/guava/src/com/google/common/primitives/UnsignedBytes.java b/guava/src/com/google/common/primitives/UnsignedBytes.java
index 6177043..cc16b0c 100644
--- a/guava/src/com/google/common/primitives/UnsignedBytes.java
+++ b/guava/src/com/google/common/primitives/UnsignedBytes.java
@@ -22,6 +22,9 @@
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
+import sun.misc.Unsafe;
+
+import java.nio.ByteOrder;
import java.util.Comparator;
/**
@@ -278,12 +281,130 @@
}
/**
- * Provides a pure Java lexicographical comparator implementation.
+ * Provides a lexicographical comparator implementation; either a Java
+ * implementation or a faster implementation based on {@link Unsafe}.
+ *
+ * <p>Uses reflection to gracefully fall back to the Java implementation if
+ * {@code Unsafe} isn't available.
*/
@VisibleForTesting
static class LexicographicalComparatorHolder {
+ static final String UNSAFE_COMPARATOR_NAME =
+ LexicographicalComparatorHolder.class.getName() + "$UnsafeComparator";
- static final Comparator<byte[]> BEST_COMPARATOR = lexicographicalComparatorJavaImpl();
+ static final Comparator<byte[]> BEST_COMPARATOR = getBestComparator();
+
+ @VisibleForTesting
+ enum UnsafeComparator implements Comparator<byte[]> {
+ INSTANCE;
+
+ static final boolean BIG_ENDIAN =
+ ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN);
+
+ /*
+ * The following static final fields exist for performance reasons.
+ *
+ * In UnsignedBytesBenchmark, accessing the following objects via static
+ * final fields is the fastest (more than twice as fast as the Java
+ * implementation, vs ~1.5x with non-final static fields, on x86_32)
+ * under the Hotspot server compiler. The reason is obviously that the
+ * non-final fields need to be reloaded inside the loop.
+ *
+ * And, no, defining (final or not) local variables out of the loop still
+ * isn't as good because the null check on the theUnsafe object remains
+ * inside the loop and BYTE_ARRAY_BASE_OFFSET doesn't get
+ * constant-folded.
+ *
+ * The compiler can treat static final fields as compile-time constants
+ * and can constant-fold them while (final or not) local variables are
+ * run time values.
+ */
+
+ static final Unsafe theUnsafe;
+
+ /** The offset to the first element in a byte array. */
+ static final int BYTE_ARRAY_BASE_OFFSET;
+
+ static {
+ theUnsafe = getUnsafe();
+
+ BYTE_ARRAY_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class);
+
+ // sanity check - this should never fail
+ if (theUnsafe.arrayIndexScale(byte[].class) != 1) {
+ throw new AssertionError();
+ }
+ }
+
+ /**
+ * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package.
+ * Replace with a simple call to Unsafe.getUnsafe when integrating
+ * into a jdk.
+ *
+ * @return a sun.misc.Unsafe
+ */
+ private static sun.misc.Unsafe getUnsafe() {
+ try {
+ return sun.misc.Unsafe.getUnsafe();
+ } catch (SecurityException tryReflectionInstead) {}
+ try {
+ return java.security.AccessController.doPrivileged
+ (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
+ public sun.misc.Unsafe run() throws Exception {
+ Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
+ for (java.lang.reflect.Field f : k.getDeclaredFields()) {
+ f.setAccessible(true);
+ Object x = f.get(null);
+ if (k.isInstance(x))
+ return k.cast(x);
+ }
+ throw new NoSuchFieldError("the Unsafe");
+ }});
+ } catch (java.security.PrivilegedActionException e) {
+ throw new RuntimeException("Could not initialize intrinsics",
+ e.getCause());
+ }
+ }
+
+ @Override public int compare(byte[] left, byte[] right) {
+ int minLength = Math.min(left.length, right.length);
+ int minWords = minLength / Longs.BYTES;
+
+ /*
+ * Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
+ * time is no slower than comparing 4 bytes at a time even on 32-bit.
+ * On the other hand, it is substantially faster on 64-bit.
+ */
+ for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) {
+ long lw = theUnsafe.getLong(left, BYTE_ARRAY_BASE_OFFSET + (long) i);
+ long rw = theUnsafe.getLong(right, BYTE_ARRAY_BASE_OFFSET + (long) i);
+ if (lw != rw) {
+ if (BIG_ENDIAN) {
+ return UnsignedLongs.compare(lw, rw);
+ }
+
+ /*
+ * We want to compare only the first index where left[index] != right[index].
+ * This corresponds to the least significant nonzero byte in lw ^ rw, since lw
+ * and rw are little-endian. Long.numberOfTrailingZeros(diff) tells us the least
+ * significant nonzero bit, and zeroing out the first three bits of L.nTZ gives us the
+ * shift to get that least significant nonzero byte.
+ */
+ int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7;
+ return (int) (((lw >>> n) & UNSIGNED_MASK) - ((rw >>> n) & UNSIGNED_MASK));
+ }
+ }
+
+ // The epilogue to cover the last (minLength % 8) elements.
+ for (int i = minWords * Longs.BYTES; i < minLength; i++) {
+ int result = UnsignedBytes.compare(left[i], right[i]);
+ if (result != 0) {
+ return result;
+ }
+ }
+ return left.length - right.length;
+ }
+ }
enum PureJavaComparator implements Comparator<byte[]> {
INSTANCE;
@@ -299,5 +420,23 @@
return left.length - right.length;
}
}
+
+ /**
+ * Returns the Unsafe-using Comparator, or falls back to the pure-Java
+ * implementation if unable to do so.
+ */
+ static Comparator<byte[]> getBestComparator() {
+ try {
+ Class<?> theClass = Class.forName(UNSAFE_COMPARATOR_NAME);
+
+ // yes, UnsafeComparator does implement Comparator<byte[]>
+ @SuppressWarnings("unchecked")
+ Comparator<byte[]> comparator =
+ (Comparator<byte[]>) theClass.getEnumConstants()[0];
+ return comparator;
+ } catch (Throwable t) { // ensure we really catch *everything*
+ return lexicographicalComparatorJavaImpl();
+ }
+ }
}
}
diff --git a/guava/src/com/google/common/util/concurrent/AbstractExecutionThreadService.java b/guava/src/com/google/common/util/concurrent/AbstractExecutionThreadService.java
index 69d31ce..aefe27f 100644
--- a/guava/src/com/google/common/util/concurrent/AbstractExecutionThreadService.java
+++ b/guava/src/com/google/common/util/concurrent/AbstractExecutionThreadService.java
@@ -152,20 +152,6 @@
return serviceName() + " [" + state() + "]";
}
- // We override instead of using ForwardingService so that these can be final.
-
- @Deprecated
- @Override
- public final ListenableFuture<State> start() {
- return delegate.start();
- }
-
- @Deprecated
- @Override
- public final State startAndWait() {
- return delegate.startAndWait();
- }
-
@Override public final boolean isRunning() {
return delegate.isRunning();
}
@@ -174,18 +160,6 @@
return delegate.state();
}
- @Deprecated
- @Override
- public final ListenableFuture<State> stop() {
- return delegate.stop();
- }
-
- @Deprecated
- @Override
- public final State stopAndWait() {
- return delegate.stopAndWait();
- }
-
/**
* @since 13.0
*/
diff --git a/guava/src/com/google/common/util/concurrent/AbstractIdleService.java b/guava/src/com/google/common/util/concurrent/AbstractIdleService.java
index de120e1..23a56e1 100644
--- a/guava/src/com/google/common/util/concurrent/AbstractIdleService.java
+++ b/guava/src/com/google/common/util/concurrent/AbstractIdleService.java
@@ -106,20 +106,6 @@
return serviceName() + " [" + state() + "]";
}
- // We override instead of using ForwardingService so that these can be final.
-
- @Deprecated
- @Override
- public final ListenableFuture<State> start() {
- return delegate.start();
- }
-
- @Deprecated
- @Override
- public final State startAndWait() {
- return delegate.startAndWait();
- }
-
@Override public final boolean isRunning() {
return delegate.isRunning();
}
@@ -128,18 +114,6 @@
return delegate.state();
}
- @Deprecated
- @Override
- public final ListenableFuture<State> stop() {
- return delegate.stop();
- }
-
- @Deprecated
- @Override
- public final State stopAndWait() {
- return delegate.stopAndWait();
- }
-
/**
* @since 13.0
*/
diff --git a/guava/src/com/google/common/util/concurrent/AbstractScheduledService.java b/guava/src/com/google/common/util/concurrent/AbstractScheduledService.java
index ce203bc..5c4eb67 100644
--- a/guava/src/com/google/common/util/concurrent/AbstractScheduledService.java
+++ b/guava/src/com/google/common/util/concurrent/AbstractScheduledService.java
@@ -317,20 +317,6 @@
return serviceName() + " [" + state() + "]";
}
- // We override instead of using ForwardingService so that these can be final.
-
- @Deprecated
- @Override
- public final ListenableFuture<State> start() {
- return delegate.start();
- }
-
- @Deprecated
- @Override
- public final State startAndWait() {
- return delegate.startAndWait();
- }
-
@Override public final boolean isRunning() {
return delegate.isRunning();
}
@@ -339,18 +325,6 @@
return delegate.state();
}
- @Deprecated
- @Override
- public final ListenableFuture<State> stop() {
- return delegate.stop();
- }
-
- @Deprecated
- @Override
- public final State stopAndWait() {
- return delegate.stopAndWait();
- }
-
/**
* @since 13.0
*/
diff --git a/guava/src/com/google/common/util/concurrent/AbstractService.java b/guava/src/com/google/common/util/concurrent/AbstractService.java
index 0330cf4..0e996ed 100644
--- a/guava/src/com/google/common/util/concurrent/AbstractService.java
+++ b/guava/src/com/google/common/util/concurrent/AbstractService.java
@@ -34,7 +34,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -97,9 +96,6 @@
private final Monitor monitor = new Monitor();
- private final Transition startup = new Transition();
- private final Transition shutdown = new Transition();
-
private final Guard isStartable = new Guard(monitor) {
@Override public boolean isSatisfied() {
return state() == NEW;
@@ -144,52 +140,7 @@
private volatile StateSnapshot snapshot = new StateSnapshot(NEW);
/** Constructor for use by subclasses. */
- protected AbstractService() {
-
- // Add a listener to update the futures. This needs to be added first so that it is executed
- // before the other listeners. This way the other listeners can access the completed futures.
- addListener(
- new Listener() {
- @Override public void running() {
- startup.set(RUNNING);
- }
-
- @Override public void stopping(State from) {
- if (from == STARTING) {
- startup.set(STOPPING);
- }
- }
-
- @Override public void terminated(State from) {
- if (from == NEW) {
- startup.set(TERMINATED);
- }
- shutdown.set(TERMINATED);
- }
-
- @Override public void failed(State from, Throwable failure) {
- switch (from) {
- case STARTING:
- startup.setException(failure);
- shutdown.setException(new Exception("Service failed to start.", failure));
- break;
- case RUNNING:
- shutdown.setException(new Exception("Service failed while running", failure));
- break;
- case STOPPING:
- shutdown.setException(failure);
- break;
- case TERMINATED: // fall-through
- case FAILED: // fall-through
- case NEW: // fall-through
- default:
- throw new AssertionError("Unexpected from state: " + from);
- }
- }
- },
- MoreExecutors.sameThreadExecutor());
-
- }
+ protected AbstractService() {}
/**
* This method is called by {@link #startAsync} to initiate service startup. The invocation of
@@ -234,24 +185,6 @@
return this;
}
- @Deprecated
- @Override
- public final ListenableFuture<State> start() {
- if (monitor.enterIf(isStartable)) {
- try {
- snapshot = new StateSnapshot(STARTING);
- starting();
- doStart();
- } catch (Throwable startupFailure) {
- notifyFailed(startupFailure);
- } finally {
- monitor.leave();
- executeListeners();
- }
- }
- return startup;
- }
-
@Override public final Service stopAsync() {
if (monitor.enterIf(isStoppable)) {
try {
@@ -290,24 +223,6 @@
return this;
}
- @Deprecated
- @Override
- public final ListenableFuture<State> stop() {
- return shutdown;
- }
-
- @Deprecated
- @Override
- public State startAndWait() {
- return Futures.getUnchecked(start());
- }
-
- @Deprecated
- @Override
- public State stopAndWait() {
- return Futures.getUnchecked(stop());
- }
-
@Override public final void awaitRunning() {
monitor.enterWhenUninterruptibly(hasReachedRunning);
try {
@@ -507,19 +422,6 @@
return getClass().getSimpleName() + " [" + state() + "]";
}
- // A change from one service state to another, plus the result of the change.
- private class Transition extends AbstractFuture<State> {
- @Override
- public State get(long timeout, TimeUnit unit)
- throws InterruptedException, TimeoutException, ExecutionException {
- try {
- return super.get(timeout, unit);
- } catch (TimeoutException e) {
- throw new TimeoutException(AbstractService.this.toString());
- }
- }
- }
-
/**
* Attempts to execute all the listeners in {@link #listeners} while not holding the
* {@link #monitor}.
diff --git a/guava/src/com/google/common/util/concurrent/Service.java b/guava/src/com/google/common/util/concurrent/Service.java
index 3b4ea87..82f7917 100644
--- a/guava/src/com/google/common/util/concurrent/Service.java
+++ b/guava/src/com/google/common/util/concurrent/Service.java
@@ -55,40 +55,6 @@
public interface Service {
/**
* If the service state is {@link State#NEW}, this initiates service startup and returns
- * immediately. If the service has already been started, this method returns immediately without
- * taking action. A stopped service may not be restarted.
- *
- * @deprecated Use {@link #startAsync()} instead of this method to start the {@link Service} or
- * use a {@link Listener} to asynchronously wait for service startup.
- *
- * @return a future for the startup result, regardless of whether this call initiated startup.
- * Calling {@link ListenableFuture#get} will block until the service has finished
- * starting, and returns one of {@link State#RUNNING}, {@link State#STOPPING} or
- * {@link State#TERMINATED}. If the service fails to start, {@link ListenableFuture#get}
- * will throw an {@link ExecutionException}, and the service's state will be
- * {@link State#FAILED}. If it has already finished starting, {@link ListenableFuture#get}
- * returns immediately. Cancelling this future has no effect on the service.
- */
-
- @Deprecated
- ListenableFuture<State> start();
-
- /**
- * Initiates service startup (if necessary), returning once the service has finished starting.
- * Unlike calling {@code start().get()}, this method throws no checked exceptions, and it cannot
- * be {@linkplain Thread#interrupt interrupted}.
- *
- * @deprecated Use {@link #startAsync()} and {@link #awaitRunning} instead of this method.
- *
- * @throws UncheckedExecutionException if startup failed
- * @return the state of the service when startup finished.
- */
-
- @Deprecated
- State startAndWait();
-
- /**
- * If the service state is {@link State#NEW}, this initiates service startup and returns
* immediately. A stopped service may not be restarted.
*
* @return this
@@ -115,42 +81,6 @@
* started nor stopped. If the service has already been stopped, this method returns immediately
* without taking action.
*
- * @deprecated Use {@link #stopAsync} instead of this method to initiate service shutdown or use a
- * service {@link Listener} to asynchronously wait for service shutdown.
- *
- * @return a future for the shutdown result, regardless of whether this call initiated shutdown.
- * Calling {@link ListenableFuture#get} will block until the service has finished shutting
- * down, and either returns {@link State#TERMINATED} or throws an
- * {@link ExecutionException}. If it has already finished stopping,
- * {@link ListenableFuture#get} returns immediately. Cancelling this future has no effect
- * on the service.
- */
-
- @Deprecated
- ListenableFuture<State> stop();
-
- /**
- * Initiates service shutdown (if necessary), returning once the service has finished stopping. If
- * this is {@link State#STARTING}, startup will be cancelled. If this is {@link State#NEW}, it is
- * {@link State#TERMINATED terminated} without having been started nor stopped. Unlike calling
- * {@code stop().get()}, this method throws no checked exceptions.
- *
- * @deprecated Use {@link #stopAsync} and {@link #awaitTerminated} instead of this method.
- *
- * @throws UncheckedExecutionException if the service has failed or fails during shutdown
- * @return the state of the service when shutdown finished.
- */
-
- @Deprecated
- State stopAndWait();
-
- /**
- * If the service is {@linkplain State#STARTING starting} or {@linkplain State#RUNNING running},
- * this initiates service shutdown and returns immediately. If the service is
- * {@linkplain State#NEW new}, it is {@linkplain State#TERMINATED terminated} without having been
- * started nor stopped. If the service has already been stopped, this method returns immediately
- * without taking action.
- *
* @return this
* @since 15.0
*/
diff --git a/guava/src/com/google/common/xml/XmlEscapers.java b/guava/src/com/google/common/xml/XmlEscapers.java
index 357c417..bd96849 100644
--- a/guava/src/com/google/common/xml/XmlEscapers.java
+++ b/guava/src/com/google/common/xml/XmlEscapers.java
@@ -55,6 +55,13 @@
// For each xxxEscaper() method, please add links to external reference pages
// that are considered authoritative for the behavior of that escaper.
+ // TODO(user): When this escaper strips \uFFFE & \uFFFF, add this doc.
+ // <p>This escaper also silently removes non-whitespace control characters and
+ // the character values {@code 0xFFFE} and {@code 0xFFFF} which are not
+ // permitted in XML. For more detail see section
+ // <a href="http://www.w3.org/TR/2008/REC-xml-20081126/#charsets">2.2</a> of
+ // the XML specification.
+
/**
* Returns an {@link Escaper} instance that escapes special characters in a
* string so it can safely be included in an XML document as element content.
@@ -67,12 +74,6 @@
* {@link #xmlContentEscaper} if the output can appear in element content or
* {@link #xmlAttributeEscaper} in attribute values.
*
- * <p>This escaper substitutes {@code 0xFFFD} for non-whitespace control
- * characters and the character values {@code 0xFFFE} and {@code 0xFFFF} which
- * are not permitted in XML. For more detail see section <a
- * href="http://www.w3.org/TR/2008/REC-xml-20081126/#charsets">2.2</a> of the
- * XML specification.
- *
* <p>This escaper does not escape non-ASCII characters to their numeric
* character references (NCR). Any non-ASCII characters appearing in the input
* will be preserved in the output. Specifically "\r" (carriage return) is
@@ -93,12 +94,6 @@
* <a href="http://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize">3.3.3</a>
* of the XML specification.
*
- * <p>This escaper substitutes {@code 0xFFFD} for non-whitespace control
- * characters and the character values {@code 0xFFFE} and {@code 0xFFFF} which
- * are not permitted in XML. For more detail see section <a
- * href="http://www.w3.org/TR/2008/REC-xml-20081126/#charsets">2.2</a> of the
- * XML specification.
- *
* <p>This escaper does not escape non-ASCII characters to their numeric
* character references (NCR). However, horizontal tab {@code '\t'}, line feed
* {@code '\n'} and carriage return {@code '\r'} are escaped to a
@@ -121,23 +116,19 @@
// The char values \uFFFE and \uFFFF are explicitly not allowed in XML
// (Unicode code points above \uFFFF are represented via surrogate pairs
// which means they are treated as pairs of safe characters).
- builder.setSafeRange(Character.MIN_VALUE, '\uFFFD');
- // Unsafe characters are replaced with the Unicode replacement character.
- builder.setUnsafeReplacement("\uFFFD");
+ // TODO(user): When refactoring done change the \uFFFF below to \uFFFD
+ builder.setSafeRange(Character.MIN_VALUE, '\uFFFF');
+ // Unsafe characters are removed.
+ builder.setUnsafeReplacement("");
- /*
- * Except for \n, \t, and \r, all ASCII control characters are replaced with
- * the Unicode replacement character.
- *
- * Implementation note: An alternative to the following would be to make a
- * map that simply replaces the allowed ASCII whitespace characters with
- * themselves and to set the minimum safe character to 0x20. However this
- * would slow down the escaping of simple strings that contain \t, \n, or
- * \r.
- */
+ // Except for '\n', '\t' and '\r' we remove all ASCII control characters.
+ // An alternative to this would be to make a map that simply replaces the
+ // allowed ASCII whitespace characters with themselves and set the minimum
+ // safe character to 0x20. However this would slow down the escaping of
+ // simple strings that contain '\t','\n' or '\r'.
for (char c = MIN_ASCII_CONTROL_CHAR; c <= MAX_ASCII_CONTROL_CHAR; c++) {
if (c != '\t' && c != '\n' && c != '\r') {
- builder.addEscape(c, "\uFFFD");
+ builder.addEscape(c, "");
}
}