team-supercharge / rxsnappy

RxSnappy is a thread safe rxjava wrapper for the great SnappyDB fast key-value database for Android.
Apache License 2.0
49 stars 9 forks source link

Improve key generation helper #3

Open pakoito opened 8 years ago

pakoito commented 8 years ago

Object... is not an explicit contract. There is no indication that the operation could take long due to serialization + Base64, and it doesn't recommend caching or anything of the sorts. Serialization may cause unintended crashes for non-serializable objects.

As small tweaks, you should move the nullcheck atop the method to avoid allocating the StringBuilder or copying the reference prematurely.

https://github.com/team-supercharge/rxsnappy/blob/master/rxsnappy/src/main/java/io/supercharge/rxsnappy/RxSnappyUtils.java#L39

richardradics commented 8 years ago

I need some inspiration how to generate a unique key, I dont want to depend to the gson library

pakoito commented 8 years ago

Java has hashCode() for these cases, but it requires the user to read the documentation and override the method properly. In this case I would rename the method to generateKeyFromHashes() to be more explicit about it. The price you pay is some primitive autoboxing.

Another uglier one is taking Comparables instead of Objects.