Guava

Caffeine versus Guava cache

倾然丶 夕夏残阳落幕 提交于 2020-01-22 09:24:25
问题 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 expiration Caffeine use a scheduled executor to perform appropriate maintenance operations in background? 回答1: The main difference is because Caffeine uses ring buffers to record & replay events, whereas Guava uses ConcurrentLinkedQueue . The intent

Safe publication of array/collection/map contents written once

我的梦境 提交于 2020-01-16 08:08:05
问题 Main question: What is the best way to perform safe publication of the contents of an array, collection, or map in Java? Here is what I've tried and some side questions I have: Side question #1 On thread 1, I'm writing to an HashMap: Map<K, V> map = new HashMap<>(); map.put(key, value); My current understanding is that: Collections.unmodifiableMap() does not constitute safe publication of the references stored in the map. By examining these particular implementations of Map.of(), the result

Sorting Guava table on values

不羁的心 提交于 2020-01-16 06:34:44
问题 Is there any possible way to do that? The expecting effect would be that rowMap and columnMap entry values would be sorted by value. The problem is that I cannot create a comparator without the underlying maps in Table. Table table = TreeBasedTable.create(?,?); Map<String, Map<String, String>> rowMap = table.rowMap(); Map<String, String> thisMapShouldBeSortedByValues = rowMap.get(smth); Map<String, Map<String, String>> columnMap = table.columnMap(); Map<String, String>

More efficient method of aggregating items into super list Java

放肆的年华 提交于 2020-01-15 10:19:06
问题 I am looking for a more efficient way of accomplishing the result of the following code pre java 8 (this is on an app hosted on Google App Engine which does not yet support Java 8) List<Order> orders = getOrders(); List<LineItem> lineItems = new ArrayList<>(); for (final Order order : orders) { for (final LineItem lineItem : order.getItems()) { lineItems.add(lineItem); } } Is there a more efficient means of accomplishing this without needing to use Java 8 functionality? Possibly using Guava

Including Guava GWT in GWT app

 ̄綄美尐妖づ 提交于 2020-01-15 09:06:44
问题 I'm trying to add guava to my GWT 2.6.1 application. I included guava-19.0.jar and guava-gwt-19.0.jar. I added <inherits name="com.google.common.collect.Collect" /> <inherits name="com.google.common.base.Base" /> to my "MyApp.gwt.xml" file. When I go to run the app via Super Dev mode, I get this error, and I'm not sure what to do. Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors. [ERROR] Errors in 'jar:file:/C:/Projects/my_proj/code/my_gwt_app/main_app/libs/guava

Getting rid of NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE?

我的未来我决定 提交于 2020-01-15 07:03:18
问题 I'm getting NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE in this snippet final Integer id = Ints.tryParse(idString); FailReason.NO_SUCH_THING.checkCondition(id!=null); something.setId(id.intValue()); Here, checkCondition works just like Preconditions.checkArgument except for it throws my own exception. Throwing NPE or IAE is not appropriate here, as it's checking an external input rather than a programming error. FindBugs complains that "The return value from a method is dereferenced without a null

What happened to Guava Constraints? [closed]

一笑奈何 提交于 2020-01-14 14:42:11
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I recently came across the use case to create a collection that does not accept null values. Guava Constraints seemed to fit the bill. Unfortunately it has been deprecated in Guava Release 15. The class is still available in Release 18, but the access modifier has been set to package private. There are no clues

Check in range precondition

你说的曾经没有我的故事 提交于 2020-01-13 05:22:06
问题 I like guava preconditions, but what I really need from it is one more method - check that the number is in range. Smt like this //probably there should be checkStateInRange also public static void checkArgumentInRange(double value, int min, int max) { if (value < min || value > max) { throw new IllegalArgumentException(String.format("%s must be in range [%s, %s]", value, min, max)); } } I believe I'm not alone and it's a pretty common case. But such method doesn't exist. Is there any reasons

Map in Map in Guava

▼魔方 西西 提交于 2020-01-12 13:48:08
问题 I have some code with Map<String, Map<String, String>> objects, which works (it is instantiated as a HashMap of HashMaps), but I wonder whether there is a better way to represent this data structure in Guava. I have considered Multimap , but while there is ListMultimap and SetMultimap in Guava, I have found no "MapMultimap". I have also checked Table, which seems to be more like it, but its name is making me uncomfortable: what I have is definitely not a table but a tree. (There is no overlap

Map in Map in Guava

不羁岁月 提交于 2020-01-12 13:46:30
问题 I have some code with Map<String, Map<String, String>> objects, which works (it is instantiated as a HashMap of HashMaps), but I wonder whether there is a better way to represent this data structure in Guava. I have considered Multimap , but while there is ListMultimap and SetMultimap in Guava, I have found no "MapMultimap". I have also checked Table, which seems to be more like it, but its name is making me uncomfortable: what I have is definitely not a table but a tree. (There is no overlap