lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "DM Smith (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LUCENE-1998) Use Java 5 enums
Date Wed, 21 Oct 2009 15:03:00 GMT

    [ https://issues.apache.org/jira/browse/LUCENE-1998?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12768270#action_12768270
] 

DM Smith commented on LUCENE-1998:
----------------------------------

I just noticed that enums are comparable. For the enum Version, we could take advantage for
this and not store a number for each value. It would be important to maintain order of versions
in the file from earliest to latest.

Should we do this?

Then the current patch's (comments removed for clarity):

public enum Version {
  LUCENE_CURRENT (0),
  LUCENE_20      (2000),
  LUCENE_21      (2100),
  LUCENE_22      (2200),
  LUCENE_23      (2300),
  LUCENE_24      (2400),
  LUCENE_29      (2900),
  LUCENE_30      (3000);
 
  private Version(int v) {
    this.v = v;
  }
 
  public boolean onOrAfter(Version other) {
    return v == 0 || v >= other.v;
  }

  private final int v;
}

Would become (the comment on strict ordering is necessary):

public enum Version {

  // These have to be ordered from the oldest to the newest version
  LUCENE_20,
  LUCENE_21,
  LUCENE_22,
  LUCENE_23,
  LUCENE_24,
  LUCENE_29,
  LUCENE_30,
  // This needs to be last
  LUCENE_CURRENT;
 
  /** A convienence method merely calling this.compareTo(other) >= 0 */
  public boolean onOrAfter(Version other) {
    return compareTo(other) >= 0;
  }

}


> Use Java 5 enums
> ----------------
>
>                 Key: LUCENE-1998
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1998
>             Project: Lucene - Java
>          Issue Type: Improvement
>    Affects Versions: 3.0
>            Reporter: DM Smith
>            Assignee: Uwe Schindler
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: LUCENE-1998_enum.patch, LUCENE-1998_enum.patch, LUCENE-1998_enum.patch,
LUCENE-1998_enum.patch
>
>
> Replace the use of o.a.l.util.Parameter with Java 5 enums, deprecating Parameter.
> Replace other custom enum patterns with Java 5 enums.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


Mime
View raw message