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

A Queue that ensure uniqueness of the elements?

How about a LinkedHashSet? Its iterator preserves insertion order, but because it’s a Set, its elements are unique. As its documentation says, Note that insertion order is not affected if an element is re-inserted into the set. In order to efficiently remove elements from the head of this “queue”, go through its iterator: Iterator<?> i … Read more

Lists.newArrayList vs new ArrayList

The guava builder saves typing the type arguments multiple times. Compare: List<Foo<Bar, Baz>> list = Lists.newArrayList(); List<Foo<Bar, Baz>> list = new ArrayList<Foo<Bar, Baz>>(); In Java 7 it’s a bit obsolete though, because you have the diamond operator: List<Foo<Bar, Baz>> list = new ArrayList<>();

Cleanest way to create a Guava Multimap from a Java 8 stream

You can just use the Guava Multimaps factory: ImmutableMultimap<String, Foo> foosById = Multimaps.index(foos, Foo::getId); or wrap a call to Multimaps.index with a Collector<T, A, R> interface (shown below, in an unoptimized naive implementation). Multimap<String, Foo> collect = foos.stream() .collect(MultimapCollector.toMultimap(Foo::getId)); and the Collector: public class MultimapCollector<T, K, V> implements Collector<T, Multimap<K, V>, Multimap<K, V>> { private … Read more

How to shrink code – 65k method limit in dex

It looks like Google has finally implementing a workaround/fix for surpassing the 65K method limit of dex files. About the 65K Reference Limit Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)