package com.google.step.YOUR_PROJECT_NAME_HERE.external;

import com.google.step.YOUR_PROJECT_NAME_HERE.data.Card;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public final class W3SchoolClient {
  private static final String TITLE_ID = "h1";
  private static final String DESC_ID = "p";
  private static final String SNIPPET_ID = "w3-example";
  private static final String CODE_ID = "w3-code";

  public Card search(String w3Link) throws IOException {

    Document doc = Jsoup.connect(w3Link).get();
    Elements titles = doc.getElementsByTag(TITLE_ID);
    Elements descriptions = doc.getElementsByTag(DESC_ID);
    Elements snippets = doc.getElementsByClass(SNIPPET_ID);

    String title = "";
    String description = "";
    String code = "";

    if (titles != null
        && !titles.isEmpty()
        && descriptions != null
        && !descriptions.isEmpty()
        && snippets != null
        && !snippets.isEmpty()) {
      title = titles.first().text();
      description = descriptions.first().text();
      code = snippets.first().getElementsByClass(CODE_ID).text();
    }

    if (!title.isEmpty() && !description.isEmpty() && !code.isEmpty()) {
      Card w3Card = new Card(title, code, w3Link, description);
      return w3Card;
    }
    return null;
  }
}

@@ -832,176 +832,89 @@
 if (
-titles != null%0A        && !titles.isEmpty()%0A        && descriptions != null%0A        && !descriptions.isEmpty()%0A        && snippets != null%0A        && !snippets.isEmpty(
+!isNullOrEmpty(titles) && !isNullOrEmpty(descriptions) && !isNullOrEmpty(snippets
 )) %7B
@@ -1257,11 +1257,119 @@
 ull;%0A  %7D
+%0A%0A  public boolean isNullOrEmpty(Elements elements) %7B%0A    return elements == null %7C%7C elements.isEmpty();%0A  %7D
 %0A%7D%0A

Add isNullOrEmpty helper function