Quick Refactoring using Apache, Google libraries

This article provides some methods from Apache & Google libraries which can help to quickly refactor code without much impact & makes code more readable & well formed.

Libraries – Guava, Apache Commons Lang

Below code snippets provide the code which can be found in any project & then provides Apache/Google library way to refactor it.

Multiple objects null checks (If not null AND if not null …)

Default value (If null then use default value)

Multiple String equality checks (If equals OR if equals …)



Create new List with some values (New list , add, add …)

Map of Constant values (New map, put, put …)

First non-null non-empty String (If not empty else if not empty …)



Enum validity check

 

 

 

 

 

Leave a Reply

Your email address will not be published.