lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "DM Smith (JIRA)" <>
Subject [jira] Commented: (LUCENE-1998) Use Java 5 enums
Date Wed, 21 Oct 2009 16:08:59 GMT


DM Smith commented on LUCENE-1998:

bq. changing the order of enum constants is bad, you should always add them at the end
Is this true?

I did not know how Java serializes enums so I went looking:

Turns out it serializes the text representation of the enum constant and class info. This
is just like the Parameter class.

If I understand it correctly, with this, an enum is resilient to changes in order. New constants
can go in any place (for example, we can later add LUCENE_291 before LUCENE_30) and not break
serialization compatibility.

This is especially good for the future as it allows a path for deprecations. (E.g. deprecation
of o.a.l.d.Field.Index.COMPRESS)

So having LUCENE_CURRENT at the end is fine.

If we wanted it first (or anywhere else) we could have onOrAfter to be:
public boolean onOrAfter(Version other) { return other == LUCENE_CURRENT || compareTo(other)
>= 0; }

If we wanted to expose version numbering info in the future, I'd suggest the following pattern
(names are unimportant):
   public int getMajor() { return 2; }
   public int getMinor() { return 9; }
   public int getFix()      { return 0; }
because it does not require storage and unlike "2900" does not have positional notation meaning
(PIC code), e.g. public int getMajor() { return int(2900/1000); }

> Use Java 5 enums
> ----------------
>                 Key: LUCENE-1998
>                 URL:
>             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,
> 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:
For additional commands, e-mail:

View raw message