lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bmes...@apache.org
Subject cvs commit: jakarta-lucene/src/java/org/apache/lucene/index FieldInfos.java
Date Sun, 19 Dec 2004 14:55:48 GMT
bmesser     2004/12/19 06:55:48

  Modified:    src/java/org/apache/lucene/index FieldInfos.java
  Log:
  do not longer return an extra blank field in Reader getFieldNames
  PR:19085
  Obtained from: Mark Harwood
  Submitted by: Bernhard
  
  Revision  Changes    Path
  1.14      +33 -9     jakarta-lucene/src/java/org/apache/lucene/index/FieldInfos.java
  
  Index: FieldInfos.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/index/FieldInfos.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- FieldInfos.java	5 Oct 2004 17:30:47 -0000	1.13
  +++ FieldInfos.java	19 Dec 2004 14:55:48 -0000	1.14
  @@ -42,9 +42,7 @@
     private ArrayList byNumber = new ArrayList();
     private HashMap byName = new HashMap();
   
  -  FieldInfos() {
  -    add("", false);
  -  }
  +  FieldInfos() { }
   
     /**
      * Construct a FieldInfos object using the directory and the name of the file
  @@ -168,23 +166,49 @@
     }
   
     public int fieldNumber(String fieldName) {
  -    FieldInfo fi = fieldInfo(fieldName);
  -    if (fi != null)
  -      return fi.number;
  -    else
  +    try {
  +      FieldInfo fi = fieldInfo(fieldName);
  +      if (fi != null)
  +        return fi.number;
  +    }
  +    catch (IndexOutOfBoundsException ioobe) {
         return -1;
  +    }
  +    return -1;
     }
   
     public FieldInfo fieldInfo(String fieldName) {
       return (FieldInfo) byName.get(fieldName);
     }
   
  +  /**
  +   * Return the fieldName identified by it's number.
  +   * @param fieldNumber
  +   * @return the fieldName or an empty string when the field
  +   * with the given number doesn't exist.
  +   */  
     public String fieldName(int fieldNumber) {
  -    return fieldInfo(fieldNumber).name;
  +    try {
  +      return fieldInfo(fieldNumber).name;
  +    }
  +    catch (NullPointerException npe) {
  +      return "";
  +    }
     }
   
  +  /**
  +   * Return the fieldinfo object referenced by the fieldNumber.
  +   * @param fieldNumber
  +   * @return the FieldInfo object or null when the given fieldNumber
  +   * doesn't exist.
  +   */  
     public FieldInfo fieldInfo(int fieldNumber) {
  -    return (FieldInfo) byNumber.get(fieldNumber);
  +    try {
  +      return (FieldInfo) byNumber.get(fieldNumber);
  +    }
  +    catch (IndexOutOfBoundsException ioobe) {
  +      return null;
  +    }
     }
   
     public int size() {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message