Skip to content

Can we replace Guava with Java 8 features? If we keep it should be upgraded to a more recent version #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TheSnoozer opened this issue Dec 7, 2017 · 1 comment
Milestone

Comments

@TheSnoozer
Copy link
Collaborator

Just a thought....we use guava for some common utility stuff.
With Java 8 some of Guava's stuff can be replaced with native Java code.
If there would no additional benefit in using guava it should be a replaced with native Java code.
This is just an evaluation if we can replace all current features with native code.
If not we keep guava (but should upgrade it to a more recent version).

Only thing that we seem to use (and might be useful) is an immutable map where no such replacement seem to exist inside the native java 8 environment.

https://www.reddit.com/r/java/comments/217rnf/what_is_obsolete_in_guava_since_java_8/

FluentIterable
Stream

{Listenable,Settable}Future
CompletableFuture

Sets.newConcurrentHashSet()
ConcurrentHashMap.newKeySet()

Joiner.on(separator).join(...)
String.join(separator, ...)
...or new StringJoiner(separator).add(...)
...or stream.collect(Collectors.joining(separator))

com.google.common.base.{Predicate,Function,Supplier,Optional}
java.util.function.{Predicate,Function,Supplier}, java.util.Optional (and Optional{Int,Long,Double})

Ordering.natural()
Comparator.naturalOrder()

ordering.reverse()
comparator.reversed()

Ordering.compound(comparator1, comparator2)
comparator1.thenComparing(comparator2)

Ordering.from(comparator).onResultOf(function)
Comparator.comparing(function, comparator)

Ordering.from(comparator).nulls{First,Last}()
Comparator.nulls{First,Last}(comparator)

ComparisonChain
comparator.thenComparing(...)

Some uses of BaseEncoding
java.util.Base64

Lists.transform(list, function)
list.stream().map(function).collect(Collectors.toList())

  • More verbose, less efficient.

Maps.uniqueIndex(collection, function)
collection.stream().collect(Collectors.toMap(Function.identity(), function))

  • More verbose, not immutable.

Multimaps.index(collection, function)
collection.stream().collect(Collectors.groupingBy(function))

  • More verbose, not immutable, not a Multimap.

https://groups.google.com/forum/#!topic/guava-discuss/fEdrMyNa8tA

com.google.common.base.Function -> java.util.function.Function

com.google.common.base.Supplier -> java.util.function.Supplier

void com.google.common.util.concurrent.ListenableFuture addListener(Runnable listener, Executor executor) method -> CompletableFuture java.util.concurrent.CompletableFuture.thenRunAsync(Runnable action, Executor executor) (.... instead of returning a void, this returns a CompletableFuture ).

com.google.common.util.concurrent.ListenableFuture.addListener(someRunnable, MoreExecutors.sameThreadExecutor() ) -> java.util.concurrent.CompletableFuture.thenRun( someRunnable )

com.google.common.util.concurrent.Futures.addCallback(..) -> doesn't exist

com.google.common.util.concurrent.SettableFuture.set(T) -> java.util.concurrent.CompletableFuture.complete(T)

boolean com.google.common.base.Predicate.apply(T) -> boolean java.util.function.Predicate.test(T)

com.google.common.base.Predicates.and/or/not -> java.util.function.Predicate.and/or/negate

com.google.common.base.Optional -> java.util.Optional

com.google.common.base.Joiner -> java.util.StringJoiner (roughly)

@TheSnoozer TheSnoozer added this to the v3.0-modularized milestone Dec 13, 2017
TheSnoozer pushed a commit to TheSnoozer/git-commit-id-maven-plugin that referenced this issue Sep 1, 2018
TheSnoozer pushed a commit to TheSnoozer/git-commit-id-maven-plugin that referenced this issue Sep 1, 2018
- replace com.google.common.base.Optional with java.util.Optional
- replace com.google.common.base.Joiner with java.util.StringJoiner or String.join
- replace com.google.common.base.MoreObjects with java.util.Optional
- replace Preconditions.checkArgument(arg != null, ...) with java.util.Objects.requireNonNull(arg)
- replace various com.google.common.base.{Function, Predicate, Predicates} code snippets with lambda expressions
- replace com.google.common.io.Closeables with java's try-with-resources
TheSnoozer pushed a commit that referenced this issue Sep 13, 2018
#346 / #336 / #350: Drop Java 1.7 support / introduce a timeout for any native git command / replace almost every guava feature with Java 8 features
@TheSnoozer
Copy link
Collaborator Author

I removed almost every (unnecessary) call that could be replaced with java8.
There is only a few items left where we ask guava for certain thinks.
Not sure if it would be worth to replace this with our own custom logic.
All together I updated it to the latest version available and thus i feel I just can close the ticket for now and if there is a need to full remove the dependency i think we just can go ahead and do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant