LUCENE-4055: nuke more mutability

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4055@1340108 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-05-18 14:31:35 +00:00
parent a6207d9c04
commit be52287d6e
5 changed files with 11 additions and 15 deletions

View File

@ -38,12 +38,10 @@ import org.apache.lucene.util.IOUtils;
public class SepDocValuesConsumer extends DocValuesWriterBase { public class SepDocValuesConsumer extends DocValuesWriterBase {
private final Directory directory; private final Directory directory;
private final FieldInfos fieldInfos;
public SepDocValuesConsumer(PerDocWriteState state) throws IOException { public SepDocValuesConsumer(PerDocWriteState state) throws IOException {
super(state); super(state);
this.directory = state.directory; this.directory = state.directory;
fieldInfos = state.fieldInfos;
} }
@Override @Override

View File

@ -560,7 +560,7 @@ class DocumentsWriterPerThread {
PerDocWriteState newPerDocWriteState(String segmentSuffix) { PerDocWriteState newPerDocWriteState(String segmentSuffix) {
assert segment != null; assert segment != null;
return new PerDocWriteState(infoStream, directory, segment, fieldInfos, bytesUsed, segmentSuffix, IOContext.DEFAULT); return new PerDocWriteState(infoStream, directory, segment, bytesUsed, segmentSuffix, IOContext.DEFAULT);
} }
@Override @Override

View File

@ -33,18 +33,16 @@ public class PerDocWriteState {
public final InfoStream infoStream; public final InfoStream infoStream;
public final Directory directory; public final Directory directory;
public final String segmentName; public final String segmentName;
public final FieldInfos fieldInfos;
public final Counter bytesUsed; public final Counter bytesUsed;
public final String segmentSuffix; public final String segmentSuffix;
public final IOContext context; public final IOContext context;
public PerDocWriteState(InfoStream infoStream, Directory directory, public PerDocWriteState(InfoStream infoStream, Directory directory,
String segmentName, FieldInfos fieldInfos, Counter bytesUsed, String segmentName, Counter bytesUsed,
String segmentSuffix, IOContext context) { String segmentSuffix, IOContext context) {
this.infoStream = infoStream; this.infoStream = infoStream;
this.directory = directory; this.directory = directory;
this.segmentName = segmentName; this.segmentName = segmentName;
this.fieldInfos = fieldInfos;
this.segmentSuffix = segmentSuffix; this.segmentSuffix = segmentSuffix;
this.bytesUsed = bytesUsed; this.bytesUsed = bytesUsed;
this.context = context; this.context = context;
@ -54,7 +52,6 @@ public class PerDocWriteState {
infoStream = state.infoStream; infoStream = state.infoStream;
directory = state.directory; directory = state.directory;
segmentName = state.segmentName; segmentName = state.segmentName;
fieldInfos = state.fieldInfos;
segmentSuffix = state.segmentSuffix; segmentSuffix = state.segmentSuffix;
bytesUsed = Counter.newCounter(); bytesUsed = Counter.newCounter();
context = state.context; context = state.context;
@ -64,7 +61,6 @@ public class PerDocWriteState {
this.infoStream = state.infoStream; this.infoStream = state.infoStream;
this.directory = state.directory; this.directory = state.directory;
this.segmentName = state.segmentName; this.segmentName = state.segmentName;
this.fieldInfos = state.fieldInfos;
this.segmentSuffix = segmentSuffix; this.segmentSuffix = segmentSuffix;
this.bytesUsed = state.bytesUsed; this.bytesUsed = state.bytesUsed;
this.context = state.context; this.context = state.context;

View File

@ -248,11 +248,11 @@ public class TestCodecs extends LuceneTestCase {
terms[i] = new TermData(text, docs, null); terms[i] = new TermData(text, docs, null);
} }
final MutableFieldInfos fieldInfos = new MutableFieldInfos(new MutableFieldInfos.FieldNumberBiMap()); final MutableFieldInfos builder = new MutableFieldInfos(new MutableFieldInfos.FieldNumberBiMap());
final FieldData field = new FieldData("field", fieldInfos, terms, true, false); final FieldData field = new FieldData("field", builder, terms, true, false);
final FieldData[] fields = new FieldData[] {field}; final FieldData[] fields = new FieldData[] {field};
final FieldInfos fieldInfos = builder.finish();
final Directory dir = newDirectory(); final Directory dir = newDirectory();
this.write(fieldInfos, dir, fields, true); this.write(fieldInfos, dir, fields, true);
Codec codec = Codec.getDefault(); Codec codec = Codec.getDefault();
@ -294,16 +294,17 @@ public class TestCodecs extends LuceneTestCase {
} }
public void testRandomPostings() throws Throwable { public void testRandomPostings() throws Throwable {
final MutableFieldInfos fieldInfos = new MutableFieldInfos(new MutableFieldInfos.FieldNumberBiMap()); final MutableFieldInfos builder = new MutableFieldInfos(new MutableFieldInfos.FieldNumberBiMap());
final FieldData[] fields = new FieldData[NUM_FIELDS]; final FieldData[] fields = new FieldData[NUM_FIELDS];
for(int i=0;i<NUM_FIELDS;i++) { for(int i=0;i<NUM_FIELDS;i++) {
final boolean omitTF = 0==(i%3); final boolean omitTF = 0==(i%3);
final boolean storePayloads = 1==(i%3); final boolean storePayloads = 1==(i%3);
fields[i] = new FieldData(fieldNames[i], fieldInfos, this.makeRandomTerms(omitTF, storePayloads), omitTF, storePayloads); fields[i] = new FieldData(fieldNames[i], builder, this.makeRandomTerms(omitTF, storePayloads), omitTF, storePayloads);
} }
final Directory dir = newDirectory(); final Directory dir = newDirectory();
final FieldInfos fieldInfos = builder.finish();
if (VERBOSE) { if (VERBOSE) {
System.out.println("TEST: now write postings"); System.out.println("TEST: now write postings");

View File

@ -46,10 +46,11 @@ public class TestFieldInfos extends LuceneTestCase {
public FieldInfos createAndWriteFieldInfos(Directory dir, String filename) throws IOException{ public FieldInfos createAndWriteFieldInfos(Directory dir, String filename) throws IOException{
//Positive test of FieldInfos //Positive test of FieldInfos
assertTrue(testDoc != null); assertTrue(testDoc != null);
MutableFieldInfos fieldInfos = new MutableFieldInfos(new MutableFieldInfos.FieldNumberBiMap()); MutableFieldInfos builder = new MutableFieldInfos(new MutableFieldInfos.FieldNumberBiMap());
for (IndexableField field : testDoc) { for (IndexableField field : testDoc) {
fieldInfos.addOrUpdate(field.name(), field.fieldType()); builder.addOrUpdate(field.name(), field.fieldType());
} }
FieldInfos fieldInfos = builder.finish();
//Since the complement is stored as well in the fields map //Since the complement is stored as well in the fields map
assertTrue(fieldInfos.size() == DocHelper.all.size()); //this is all b/c we are using the no-arg constructor assertTrue(fieldInfos.size() == DocHelper.all.size()); //this is all b/c we are using the no-arg constructor