Managing highly repetitive code and documentation in Java

For people that absolutely need performance, boxing and unboxing and generified collections and whatnot are big no-no’s. The same problem happens in performance computing where you need the same complex to work both for float and double (say some of the method shown in Goldberd’s “What every computer scientist should know about floating-point numbers“ paper). … Read more

Google Guava isNullOrEmpty for collections

No, this method does not exist in Guava and is in fact in our “idea graveyard.” We don’t believe that “is null or empty” is a question you ever really want to be asking about a collection. If a collection might be null, and null should be treated the same as empty, then get all … Read more

java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap error using GeckoDriver Firefox through Selenium in Java

This error message… Exception in thread “main” java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap at org.openqa.selenium.firefox.FirefoxDriver …implies that the file com/google/common/collect/ImmutableMap might be corrupted or there is some incompatibility between the version of the binaries you are using specifically with the guava version / dependency (maven). You need to take care of a couple of things as follows: In the … Read more

org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList; with Selenium 3.5.3 Chrome 76

This error message… java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList; …implies that there is some incompatibility between the version of the binaries you are using specifically with the guava dependency. You are using chrome= 76.0 You are using the following: <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-chrome-driver</artifactId> <version>3.5.3</version> <scope>test</scope> </dependency> Your Selenium Client version is 3.5.3 which is more then 2 years older. Your … Read more

Map that could be iterated in the order of values

I would do this with Guava as follows: Ordering<Map.Entry<Key, Value>> entryOrdering = Ordering.from(valueComparator) .onResultOf(new Function<Entry<Key, Value>, Value>() { public Value apply(Entry<Key, Value> entry) { return entry.getValue(); } }).reverse(); // Desired entries in desired order. Put them in an ImmutableMap in this order. ImmutableMap.Builder<Key, Value> builder = ImmutableMap.builder(); for (Entry<Key, Value> entry : entryOrdering.sortedCopy(map.entrySet())) { builder.put(entry.getKey(), … Read more

Google Guava vs. Apache Commons [closed]

In my opinion the better choice is Guava (formerly known as Google collections): it’s more modern (has generics) it absolutely follows the Collections API requirements it’s actively maintained CacheBuilder and it’s predecessor MapMaker are just plain awesome Apache Commons Collections is a good library as well, but it has long failed to provide a generics-enabled … Read more