Questions tagged [guava]

Google's Core Java Library for Java and Android development.

Guava

Guava is an open-source Java library that aims to make working in the Java language more pleasant and more productive.

It contains several core libraries that Google relies on in their Java-based projects: collections, caching, primitives support, concurrency libraries, common annotations, basic string processing, I/O, mathematics, etc.

Resources

3540 questions
40
votes
8 answers

How to remove control characters from java string?

I have a string coming from UI that may contains control characters, and I want to remove all control characters except carriage returns, line feeds, and tabs. Right now I can find two way to remove all control characters: 1- using guava: return…
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
39
votes
3 answers

Does Java 8 have cached support for suppliers?

The guava library has it's own Supplier which does not extend Java 8 Supplier. Also guava provides a cache for suppliers - Suppliers#memoize. Is there something similar, but for Java 8 Suppliers?
Cherry
  • 31,309
  • 66
  • 224
  • 364
39
votes
2 answers

Guava ImmutableMap has noticeably slower access than HashMap

While working on a memory benchmark of some high-throughput data structures, I realized I could use an ImmutableMap with only a little refactoring. Thinking this would be an improvement, I threw it into the mix and was surprised to discover that…
dimo414
  • 47,227
  • 18
  • 148
  • 244
38
votes
10 answers

ProGuard configuration for Guava with obfuscation and optimization

Looking for a ProGuard configuration for Guava that will obfuscate and optimize, as the default one that is provided on the website does not. Not only that I cannot get it to export my apk, I keep getting: Warning:…
user1159819
  • 1,549
  • 4
  • 16
  • 29
38
votes
4 answers

Grouping elements of a list into sublists (maybe by using guava)

I want to group elements of a list. I'm currently doing it this way: public static List> group(final List list, final GroupFunction groupFunction) { List> result = Lists.newArrayList(); for (final E element :…
Fabian Zeindl
  • 5,860
  • 8
  • 54
  • 78
38
votes
1 answer

Caffeine versus Guava cache

According to these micro benchmarks it turns out that Caffeine is a way faster than Guava cache in both read and write operations. What is the secret of Caffeine implementation? How it differs from the Guava Cache? Am I right that in case of timed…
Developer87
  • 2,448
  • 4
  • 23
  • 43
38
votes
3 answers

How to get max() element from List in Guava

Let's say we have a Collection of Items: class Item { public String title; public int price; } List list = getListOfItems(); I would like to get an Item with a maximum price out of that list with Guava library (with Ordering, I…
Mike Minicki
  • 8,216
  • 11
  • 39
  • 43
37
votes
6 answers

Google-guava checkNotNull and IntelliJ IDEA's "may produce java.lang.NullPointerException"

Is there any way to suppress this warning: MyClass object = null; /*Some code that 'might' set this object but I know it will*/ Preconditions.checkNotNull(object); //when "assert object != null" is used here no warning is…
Sebastian
  • 663
  • 1
  • 7
  • 20
37
votes
6 answers

Google Guava Supplier Example

Please explain the use of the interface Supplier(in Guava) with a suitable example .
Emil
  • 13,577
  • 18
  • 69
  • 108
37
votes
6 answers

Maven for Eclipse 1.5.0 plugin cannot be installed under Kepler

I downloaded Eclipse Kepler and tried to install M2Eclipse from its update site. After selecting Maven Integration for Eclipse, I clicked Next and got the following error: Missing requirement: Maven Integration for Eclipse 1.5.0.20140606-0033…
Howy
  • 825
  • 2
  • 10
  • 20
36
votes
1 answer

Java: suppress warning "X is marked unstable"

I am using the com.google.common.net.MediaType class from the Google Guava library and it is marked as @Beta. I'd like to suppress warnings that this is marked as unstable. What's the @SuppressWarnings key do I need to use?
Kousha
  • 32,871
  • 51
  • 172
  • 296
36
votes
9 answers

Idiomatic way to use for-each loop given an iterator?

When the enhanced for loop (foreach loop) was added to Java, it was made to work with a target of either an array or Iterable. for ( T item : /*T[] or Iterable*/ ) { //use item } That works great for Collection classes that only…
Mark Peters
  • 80,126
  • 17
  • 159
  • 190
36
votes
9 answers

Get minvalue of a Map(Key,Double)

Is there a method (maybe with Google Collections) to obtain the min value of a Map(Key, Double)? In the traditional way, I would have to sort the map according to the values, and take the first/last one.
user326667
  • 509
  • 1
  • 7
  • 11
36
votes
3 answers

@Nullable input in Google Guava Function interface triggers FindBugs warning

The com.google.common.base.Function interface (from Google Guava) defines apply as: @Nullable T apply(@Nullable F input); The method has the following javadoc note: @throws NullPointerException if {@code input} is null and this function does not…
vitaly
  • 2,755
  • 4
  • 23
  • 35
35
votes
6 answers

Most efficient way to find the collection of all ids in a collection of entities

I have an entity: public class Entity { private long id; private String data; public long getId() { return id; } public String getData() { return data; } } and a collection of…
rapt
  • 11,810
  • 35
  • 103
  • 145