[guava-libraries] 01/04: Restored the Enums.valueOfFunction() method (removed in Guava 18)
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Fri Jul 3 17:54:52 UTC 2015
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to branch master
in repository guava-libraries.
commit 93262237273cc961fa278826eddc0be403fe68f7
Author: Emmanuel Bourg <ebourg at apache.org>
Date: Fri Jul 3 09:18:33 2015 +0200
Restored the Enums.valueOfFunction() method (removed in Guava 18)
---
debian/changelog | 7 +++
debian/patches/08-preserve-enums-methods.patch | 68 ++++++++++++++++++++++++++
debian/patches/series | 1 +
3 files changed, 76 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index 5ebda2f..8a9f5c1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+guava-libraries (18.0-3) UNRELEASED; urgency=medium
+
+ * Improved the backward compatibility:
+ - Restored the Enums.valueOfFunction() method (removed in Guava 18)
+
+ -- Emmanuel Bourg <ebourg at apache.org> Fri, 03 Jul 2015 09:17:02 +0200
+
guava-libraries (18.0-2) unstable; urgency=medium
* Improved the backward compatibility:
diff --git a/debian/patches/08-preserve-enums-methods.patch b/debian/patches/08-preserve-enums-methods.patch
new file mode 100644
index 0000000..1c896ba
--- /dev/null
+++ b/debian/patches/08-preserve-enums-methods.patch
@@ -0,0 +1,68 @@
+Description: Preserves the Enums.valueOfFunction() method that was removed in Guava 18.
+Author: Emmanuel Bourg <ebourg at apache.org>
+Forwarded: not-needed
+--- a/guava/src/com/google/common/base/Enums.java
++++ b/guava/src/com/google/common/base/Enums.java
+@@ -62,6 +62,62 @@
+ }
+ }
+
++
++ /**
++ * Returns a {@link Function} that maps an {@link Enum} name to the associated {@code Enum}
++ * constant. The {@code Function} will return {@code null} if the {@code Enum} constant
++ * does not exist.
++ *
++ * @param enumClass the {@link Class} of the {@code Enum} declaring the constant values
++ * @deprecated Use {@link Enums#stringConverter} instead. Note that the string converter has
++ * slightly different behavior: it throws {@link IllegalArgumentException} if the enum
++ * constant does not exist rather than returning {@code null}. It also converts {@code null}
++ * to {@code null} rather than throwing {@link NullPointerException}. This method is
++ * scheduled for removal in Guava 18.0.
++ */
++ @Deprecated
++ public static <T extends Enum<T>> Function<String, T> valueOfFunction(
++ Class<T> enumClass) {
++ return new ValueOfFunction<T>(enumClass);
++ }
++
++ /**
++ * A {@link Function} that maps an {@link Enum} name to the associated constant, or {@code null}
++ * if the constant does not exist.
++ */
++ private static final class ValueOfFunction<T extends Enum<T>>
++ implements Function<String, T>, Serializable {
++
++ private final Class<T> enumClass;
++
++ private ValueOfFunction(Class<T> enumClass) {
++ this.enumClass = checkNotNull(enumClass);
++ }
++
++ @Override
++ public T apply(String value) {
++ try {
++ return Enum.valueOf(enumClass, value);
++ } catch (IllegalArgumentException e) {
++ return null;
++ }
++ }
++
++ @Override public boolean equals(@Nullable Object obj) {
++ return obj instanceof ValueOfFunction && enumClass.equals(((ValueOfFunction) obj).enumClass);
++ }
++
++ @Override public int hashCode() {
++ return enumClass.hashCode();
++ }
++
++ @Override public String toString() {
++ return "Enums.valueOf(" + enumClass + ")";
++ }
++
++ private static final long serialVersionUID = 0;
++ }
++
+ /**
+ * Returns an optional enum constant for the given type, using {@link Enum#valueOf}. If the
+ * constant does not exist, {@link Optional#absent} is returned. A common use case is for parsing
diff --git a/debian/patches/series b/debian/patches/series
index 194bef1..faf4a05 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -5,3 +5,4 @@
05-preserve-mapmaker-makecomputingmap.patch
06-preserve-pre-guava18-methods.patch
07-java8-compatibility.patch
+08-preserve-enums-methods.patch
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/guava-libraries.git
More information about the pkg-java-commits
mailing list