Best approach to refactor this java snippet
<p>I was told it is not a good style to call potentially costly methods for boolean expressions (<code>getSupercategories()</code>). </p>

<pre><code>private final SuperCategoriesResolver&lt;ProductModel&gt; catResolver = new SuperCategoriesResolver&lt;ProductModel&gt;() {
    @Override
    public Set&lt;CategoryModel&gt; getSuperCategories(final CategoryModel item) {
        return item == null || item.getSupercategories() == null ? Collections.EMPTY_SET
                : new LinkedHashSet&lt;CategoryModel&gt;(
                        item.getSupercategories());
    }
};
</code></pre>

<p>As well that <code>getSupercategories()</code> is potentially dangerous since it's backed by a relation attribute which might not be coming from local data members (<code>item</code> is sent as a parameter to a public method in this class and after wards is sent to <code>getSuperCategories()</code> which is overriden in the same class when declaring <code>catResolver</code>).</p>

<p><strong>Is this a better approach to tackle the argument above?</strong></p>

<pre><code>private final SuperCategoriesResolver&lt;ProductModel&gt; catResolver = new SuperCategoriesResolver&lt;ProductModel&gt;() {
    @Override
    public Set&lt;CategoryModel&gt; getSuperCategories(final ProductModel item) {
        if (item != null) {
            Set&lt;CategoryModel&gt; superCategories = (Set&lt;CategoryModel&gt;) item
                    .getSupercategories();

            if (superCategories != null)
                return superCategories;
        }

        return Collections.EMPTY_SET;
    }
};
</code></pre>

<p>Where I first verify that <code>item</code> is not <code>null</code>. if it is, then a return <code>empy_set</code> if not then I called the costly method and get the collection and just if it is not <code>null</code> return the collection with elements.</p>

<p>Thank u very much for your advice.</p>
