I agree, this makes sense. I'll commit it. Thanks Stefan!
Except, the last one you list (getBinaryValue) I think should still
return null if no field by that name exists?
Mike
Stefan Trcek wrote:
Hello
The 'Document.getFieldables(String name)' is documented to return
'null'
in some cases (and really does, see the code below). However this
makes
a penalty to the client, as code like this
Document doc = hits.doc(i);
for (Fieldable f: doc.getFieldables("somefield")) {
System.out.println(f.stringValue());
}
is wrong (no check on 'null'). For the client code it would be better,
if 'Document.getFieldables(String)' would return 'new Fieldable[0]'
instead (no NullPointerException).
If you needn't distinguish between null-ed arrays and arrays of zero
lenght (do you?), I suggest to never return 'null', but return an
array
of size zero. If you don't trust the just-in-time compiler (concerning
performance), you may even define
private final static Fieldable[] EMPTY = new Fieldable[0];
and return 'EMPTY' at the (*) line. Same with
public final Field[] getFields(String name) {
public final String[] getValues(String name) {
public final byte[][] getBinaryValues(String name) {
public final byte[] getBinaryValue(String name) {
and maybe others.
Stefan
--- org.apache.lucene.document.Document.java ---------------------
public Fieldable[] getFieldables(String name) {
List result = new ArrayList();
for (int i = 0; i < fields.size(); i++) {
Fieldable field = (Fieldable)fields.get(i);
if (field.name().equals(name)) {
result.add(field);
}
}
if (result.size() == 0)
(*) return null;
return (Fieldable[])result.toArray(new Fieldable[result.size()]);
}
------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]