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
2
votes
1 answer

Elements order provided by ConcurrenLinkedtHashmap iterator depends on key size?

I found strange behaviour of (iterator?) ConcurrentLinkedHashMap. Elements obtained by iterating entrySet/keySet are in strange/unexpected order if key is long. Everything is ok if key is short. Following code: public static void main(String[]…
littleAlien
  • 721
  • 2
  • 8
  • 20
2
votes
3 answers

Create Multimap from Map> with key as V[0] and value as K using Java 8

I have a Map>(say inputMap) and I want to convert this to another Map> where each (k,v) in the new map is (v.get(0),k) of inputMap. Ex. X -> B,C,D Y -> B,D,E Z -> B,G,H P -> A,B,D Q -> A,D,F R ->…
Hav3n
  • 251
  • 5
  • 21
2
votes
3 answers

google guava checking for item in cache

I'm trying to use google guava cache on a program but am not quite getting how it works. I'm loading up the cache and then at a later stage i'm trying to check if an item exists in the cache, my code below doesnt quite work The getIfPresent returns…
blu10
  • 534
  • 2
  • 6
  • 28
2
votes
2 answers

Neo4j and Java: fast and random sample of Iterable

I've coded a traversal in Java which returns an Iterable. The worst case is an Iterable size of 850784 relationships. Objective: I want to sample (without replacement) only 20 relationships and I want to do it fast. Solution 1 : performing a…
guzu92
  • 737
  • 1
  • 12
  • 28
2
votes
2 answers

Is there a with() method inside ImmutableMap?

I am watching the video (https://www.youtube.com/watch?v=ZeO_J2OcHYM) and find that we can initialize the ImmutableMap using the with() method. See below: public static final ImmutableMap ENGLISH_TO_INT = ImmutableMap …
injoy
  • 3,993
  • 10
  • 40
  • 69
2
votes
2 answers

How to throw away the original collection once the Immutable version is created using Google Guava?

I have a map as below and once I get the immutable version of the original map, I don't need the original one anymore. Is there a way to have the GC recycle it? Map map = new TreeMap<>(); map.put("1", "one"); map.put("2",…
injoy
  • 3,993
  • 10
  • 40
  • 69
2
votes
4 answers

Best way to return null from a method?

I need to get the hostname of the machine where the code is running. I have a method like this: private static final String getHostName() { try { return InetAddress.getLocalHost().getCanonicalHostName().toLowerCase(); } catch…
user1950349
  • 4,738
  • 19
  • 67
  • 119
2
votes
0 answers

Guava event bus unregister all the event listeners

Are there any provision to unregister all the event bus listeners ? Like, when the application is about exit, and it has to do some clean up. I have some context where i'm unable to unregister with event bus.
alkber
  • 1,426
  • 2
  • 20
  • 26
2
votes
1 answer

Difference between Iterables.tryFind and FluentIterable.firstMatch in Guava

Is there any difference between? MyObject myWantedObj = Iterables.tryFind(myListOfObjects, new Predicate() { public boolean apply(MyObject myObj) { return myObj.getSomeAttribute().equals(someFinalVariable); …
Omar Hrynkiewicz
  • 502
  • 1
  • 8
  • 21
2
votes
2 answers

Ordered table datastructure

I have data structured in a table form +------+------+------+------+ | | Col1 | Col2 | Col3 | +------+------+------+------+ | Row1 | 1 | 2 | 3 | | Row2 | 5 | 5 | 6 | | Row3 | 9 | 2 | 7…
Chris
  • 390
  • 2
  • 6
2
votes
1 answer

Google Guava Hashing

I have some problem with guava funnel , I read this article https://code.google.com/p/guava-libraries/wiki/HashingExplained and others , but I don't know how I can use funnel when my class contains not only primitive types. Funnel
Dominic
  • 47
  • 1
  • 5
2
votes
1 answer

What exception should be thrown when Guava CacheLoader is unable to load the data?

I am implementing simple guava CacheLoader as it is stated here CacheLoader loader = new CacheLoader() { public Graph load(Key key) throws AnyException { return createExpensiveGraph(key); } }; …
lopushen
  • 1,117
  • 2
  • 11
  • 32
2
votes
1 answer

google guava cachebuilder use greater of the time between exipreAfterAccess and expireActerWrite

Firstly I apolozige if I didnt adhere to any of the rules and regulations of stackoverflow as I am posting a question for the first time. I am in a situation where I need to use expirable map where elements from the map can be deleted automatically…
Ricky M
  • 45
  • 4
2
votes
1 answer

Use Guava Range with custom object

I'm wondering if it's possible to use Guava Range to iterate on a list of custom objects. I have this example, which should get an interval of 5 items in a list: Range range = Range.closed(customObjectList.get(Auxiliar.index),…
Alex DG
  • 1,859
  • 2
  • 22
  • 34
2
votes
1 answer

Where can I find PrimitiveArrays in Guava?

I was using com.google.common.collect.PrimitiveArrays from Google Collections, however I cannot find it in Guava, was it renamed? Where can I find it?
Gabriel Ščerbák
  • 18,240
  • 8
  • 37
  • 52
1 2 3
99
100