To use it, call the `localPoW` method of the IotaAPI.Builder and pass
your desired PoW implementation.
The included implementation uses @Come-from-Beyond's PearlDiver (which
according to a statement of him on Slack may be used "for whatever you
wish" despite missing a license in the repo) to performs PoW by CPU.
Other implementations are possible (even outside this lib) by
implementing the IotaLocalPoW interface.
The PearlDiver class has been taken from
iotaledger/PearlDiver@212c332d60, the only
modification was to make it Java 7 compatible by replacing the lambda
with a Runnable anonymous class and fixing the nested `this` references
to point to the outer class.
As Java's Lists use boxed Integers, we try to avoid the memory
consumption, GC pressure and time overhead caused by copying an int[]
into a List<Integer> and back again.
In fact, most arraycopy and copyOfRange calls in the class are unneeded,
since Kerl can also directly operate on array slices. Care has been
taken not to introduce new side effects, therefore one copyOfRange call
in `digests` needs to stay. Existing side effects are kept, although
probably undesirable (`signatureFragment` clobbers the `keyFragment`
input parameter).
The code copies 243 single adjacent element in an array using arraycopy in a loop. For copying single elements, direct array access is more performant (as it avoids the penalty of calling into native code and the JIT may detect patterns and optimize them). However, in this case, as the copied elements are adjacent, replace the whole loop with a single arraycopy call.
The trits() method that takes a `String` first checks if the String contains a number, and if yes tries to convert that number into trytes. A String consisting only of digits "9" is ambiguous and has been converted as a number instead of a String (making one unit test fail). Since there is only one caller of that method that intentionally passes a number containing a String (and it is even in the same class), refactor it to have overloads taking a String vs. a long value and fix the only caller to use the long overload instead.
Found by Eclipse's static null value analyzer.
It makes no sense to set the value to 0 if it is not null. That way, null remains null (and will create a NPE in line 123), and all other values get overwritten by 0. Therefore, overwrite null by zero, fixing both warnings.