lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: Field.java -> STORED, NOT_STORED, etc...
Date Sun, 11 Jul 2004 15:35:50 GMT
Kevin A. Burton wrote:
> So I added a few constants to my class:
> 
> new Field( "name", "value", NOT_STORED, INDEXED, NOT_TOKENIZED );
> 
> which IMO is a lot easier to maintain.
> 
> Why not add these constants to Field.java:
> 
>    public static final boolean STORED = true;
>    public static final boolean NOT_STORED = false;
> 
>    public static final boolean INDEXED = true;
>    public static final boolean NOT_INDEXED = false;
> 
>    public static final boolean TOKENIZED = true;
>    public static final boolean NOT_TOKENIZED = false;
> 
> Of course you still have to remember the order but this becomes a lot 
> easier to maintain.

It would be best to get the compiler to check the order.

If we change this, why not use type-safe enumerations:

http://www.javapractices.com/Topic1.cjp

The calls would look like:

new Field("name", "value", Stored.YES, Indexed.NO, Tokenized.YES);

Stored could be implemented as the nested class:

public final class Stored {
   private Stored() {}
   public static final Stored YES = new Stored();
   public static final Stored NO = new Stored();
}

and the compiler would check the order of arguments.

How's that?

Doug



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


Mime
View raw message