Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-2601

Make getAttribute(Class attClass) Generic

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.9.1, 2.9.2, 2.9.3
    • Fix Version/s: 3.0
    • Component/s: core/other
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      org.apache.lucene.util.AttributeSource

      current:
      public Attribute getAttribute(Class attClass) {
      final Attribute att = (Attribute) this.attributes.get(attClass);
      if (att == null)

      { throw new IllegalArgumentException("This AttributeSource does not have the attribute '" + attClass.getName() + "'."); }
      return att;
      }
      sample usage:
      TermAttribute termAtt = (TermAttribute)ts.getAttribute(TermAttribute.class)


      my improvment:
      @SuppressWarnings("unchecked")
      public <T> T getAttribute2(Class<? extends Attribute> attClass) {
      final T att = (T) this.attributes.get(attClass);
      if (att == null) { throw new IllegalArgumentException("This AttributeSource does not have the attribute '" + attClass.getName() + "'."); }

      return att;
      }
      sample usage:
      TermAttribute termAtt = ts.getAttribute(TermAttribute.class)

        Attachments

          Activity

            People

            • Assignee:
              uschindler Uwe Schindler
              Reporter:
              wenbin.zhu wenbin.zhu
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: