001: package org.apache.lucene.document;
002:
003: import java.io.Serializable;
004:
005: /**
006: * Copyright 2004 The Apache Software Foundation
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: */
020:
021: /**
022: * Provides information about what should be done with this Field
023: *
024: **/
025: //Replace with an enumerated type in 1.5
026: public final class FieldSelectorResult implements Serializable {
027:
028: /**
029: * Load this {@link Field} every time the {@link Document} is loaded, reading in the data as it is encounterd.
030: * {@link Document#getField(String)} and {@link Document#getFieldable(String)} should not return null.
031: *<p/>
032: * {@link Document#add(Fieldable)} should be called by the Reader.
033: */
034: public transient static final FieldSelectorResult LOAD = new FieldSelectorResult(
035: 0);
036: /**
037: * Lazily load this {@link Field}. This means the {@link Field} is valid, but it may not actually contain its data until
038: * invoked. {@link Document#getField(String)} SHOULD NOT BE USED. {@link Document#getFieldable(String)} is safe to use and should
039: * return a valid instance of a {@link Fieldable}.
040: *<p/>
041: * {@link Document#add(Fieldable)} should be called by the Reader.
042: */
043: public transient static final FieldSelectorResult LAZY_LOAD = new FieldSelectorResult(
044: 1);
045: /**
046: * Do not load the {@link Field}. {@link Document#getField(String)} and {@link Document#getFieldable(String)} should return null.
047: * {@link Document#add(Fieldable)} is not called.
048: * <p/>
049: * {@link Document#add(Fieldable)} should not be called by the Reader.
050: */
051: public transient static final FieldSelectorResult NO_LOAD = new FieldSelectorResult(
052: 2);
053: /**
054: * Load this field as in the {@link #LOAD} case, but immediately return from {@link Field} loading for the {@link Document}. Thus, the
055: * Document may not have its complete set of Fields. {@link Document#getField(String)} and {@link Document#getFieldable(String)} should
056: * both be valid for this {@link Field}
057: * <p/>
058: * {@link Document#add(Fieldable)} should be called by the Reader.
059: */
060: public transient static final FieldSelectorResult LOAD_AND_BREAK = new FieldSelectorResult(
061: 3);
062: /**
063: * Behaves much like {@link #LOAD} but does not uncompress any compressed data. This is used for internal purposes.
064: * {@link Document#getField(String)} and {@link Document#getFieldable(String)} should not return null.
065: * <p/>
066: * {@link Document#add(Fieldable)} should be called by the Reader.
067: */
068: public transient static final FieldSelectorResult LOAD_FOR_MERGE = new FieldSelectorResult(
069: 4);
070:
071: /** Expert: Load the size of this {@link Field} rather than its value.
072: * Size is measured as number of bytes required to store the field == bytes for a binary or any compressed value, and 2*chars for a String value.
073: * The size is stored as a binary value, represented as an int in a byte[], with the higher order byte first in [0]
074: */
075: public transient static final FieldSelectorResult SIZE = new FieldSelectorResult(
076: 5);
077:
078: /** Expert: Like {@link #SIZE} but immediately break from the field loading loop, i.e., stop loading further fields, after the size is loaded */
079: public transient static final FieldSelectorResult SIZE_AND_BREAK = new FieldSelectorResult(
080: 6);
081:
082: private int id;
083:
084: private FieldSelectorResult(int id) {
085: this .id = id;
086: }
087:
088: public boolean equals(Object o) {
089: if (this == o)
090: return true;
091: if (o == null || getClass() != o.getClass())
092: return false;
093:
094: final FieldSelectorResult that = (FieldSelectorResult) o;
095:
096: if (id != that.id)
097: return false;
098:
099: return true;
100: }
101:
102: public int hashCode() {
103: return id;
104: }
105: }
|