Wednesday, September 13, 2017

Java syntax question.

Hi there,

I don't know what the Java syntax below would mean (<?>). I hope someone can help. It looks so similar to Java generic method, but I can't find any tutorial for it.

Thank you.

public <T> NodeInfo<?> getNodeInfo(T value) {
    if (value == null) {
      // Return top level categories.
      return new DefaultNodeInfo<Category>(categoryDataProvider, new CategoryCell(images.contactsGroup()));
    } else if (value instanceof Category) {
      // Return the first letters of each first name.
      Category category = (Category) value;
      List<ContactInfo> contacts = ContactDatabase.get().queryContactsByCategory(category);
      Map<Character, LetterCount> counts = new TreeMap<Character, LetterCount>();
      for (ContactInfo contact : contacts) {
        Character first = contact.getFirstName().charAt(0);
        LetterCount count = counts.get(first);
        if (count == null) {
          count = new LetterCount(category, first);
          counts.put(first, count);
        } else {
            count.increment();
          }
      }
      List<LetterCount> orderedCounts = new ArrayList<LetterCount>(counts.values());
      return new DefaultNodeInfo<LetterCount>(new ListDataProvider<LetterCount>(orderedCounts), new LetterCountCell());
   
    } else if (value instanceof LetterCount) {
      // Return the contacts with the specified character and first name.
      LetterCount count = (LetterCount) value;
      List<ContactInfo> contacts = ContactDatabase.get().queryContactsByCategoryAndFirstName(count.category, count.firstLetter + "");
      ListDataProvider<ContactInfo> dataProvider = new ListDataProvider<ContactInfo>(contacts, ContactInfo.KEY_PROVIDER);
      return new DefaultNodeInfo<ContactInfo>(dataProvider, contactCell, selectionModel, selectionManager, null);
    }

    // Unhandled type.
    String type = value.getClass().getName();
    throw new IllegalArgumentException("Unsupported object type: " + type);
  }

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment