Optimize this code of adapter's overriden method getItemCount() How can I optimize this code of adapter's overriden method getItemCount()  into simpler form?

@Override
    public int getItemCount() {
        return super.getItemCount() == 0 &amp;&amp; data != null ? 1 : super.getItemCount();
    }
Code Beautification is suggestive. This is how I would write your code. There is also a possible performance optimization by only calling super.getItemCount() once.


be consistent with parentheses (I'm using a different rule for methods and conditions, but feel free to use your own preference as long as you are consistent)
create one variable to store the item count
get the item count you would like to return from the base class
determine predicate from the perspective of either


(A) the edge case value of item count, when itemCount == 0; an inner condition is used to determine the new value
(B) the combined condition that yields a different result itemCount == 0 &amp;&amp; data != null



snippet A

@Override
    public int getItemCount() {
        int itemCount = super.getItemCount();
        if (itemCount == 0) 
        {
            itemCount = data != null ? 1 : 0;
        }
        return itemCount;
    }


snippet B  

@Override
    public int getItemCount() {
        int itemCount = super.getItemCount();
        if (itemCount == 0 &amp;&amp; data != null) 
        {
            itemCount = 1;
        }
        return itemCount;
    }