Index: lucene/src/java/org/apache/lucene/document/FieldTypeAttribute.java
===================================================================
--- lucene/src/java/org/apache/lucene/document/FieldTypeAttribute.java	Thu Mar 24 13:49:28 NZDT 2011
+++ lucene/src/java/org/apache/lucene/document/FieldTypeAttribute.java	Thu Mar 24 13:49:28 NZDT 2011
@@ -0,0 +1,20 @@
+package org.apache.lucene.document;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public interface FieldTypeAttribute {
+}
Index: lucene/src/test/org/apache/lucene/document/TestFieldTypeBuilder.java
===================================================================
--- lucene/src/test/org/apache/lucene/document/TestFieldTypeBuilder.java	Thu Mar 24 20:15:59 NZDT 2011
+++ lucene/src/test/org/apache/lucene/document/TestFieldTypeBuilder.java	Thu Mar 24 20:15:59 NZDT 2011
@@ -0,0 +1,30 @@
+package org.apache.lucene.document;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Test;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class TestFieldTypeBuilder extends LuceneTestCase {
+
+  @Test
+  public void testFieldTypeBuilder_simpleInteration() {
+    FieldType fieldType = new FieldTypeBuilder().indexed(true).stored(true).build();
+    assertTrue(fieldType.getAttribute(CoreFieldTypeAttribute.class).isIndexed());
+    assertTrue(fieldType.getAttribute(CoreFieldTypeAttribute.class).isStored());
+  }
+}
Index: lucene/src/java/org/apache/lucene/document/CoreFieldTypeAttribute.java
===================================================================
--- lucene/src/java/org/apache/lucene/document/CoreFieldTypeAttribute.java	Thu Mar 24 19:58:24 NZDT 2011
+++ lucene/src/java/org/apache/lucene/document/CoreFieldTypeAttribute.java	Thu Mar 24 19:58:24 NZDT 2011
@@ -0,0 +1,40 @@
+package org.apache.lucene.document;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public interface CoreFieldTypeAttribute extends FieldTypeAttribute {
+
+  boolean isIndexed();
+  
+  boolean isStored();
+
+  boolean isTokenized();
+
+  boolean isTermVectorsStored();
+
+  boolean isOffsetsStoredWithTermVectors();
+
+  boolean isPositionsStoredWithTermVectors();
+
+  boolean isNormsIndexed();
+
+  boolean isTermFreqsIndexed();
+
+  boolean isPositionsIndexed();
+
+  boolean isLazy();
+}
Index: lucene/src/java/org/apache/lucene/document/FieldTypeBuilder.java
===================================================================
--- lucene/src/java/org/apache/lucene/document/FieldTypeBuilder.java	Thu Mar 24 20:08:38 NZDT 2011
+++ lucene/src/java/org/apache/lucene/document/FieldTypeBuilder.java	Thu Mar 24 20:08:38 NZDT 2011
@@ -0,0 +1,96 @@
+package org.apache.lucene.document;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class FieldTypeBuilder {
+
+  private int flags;
+  private Map<Class<? extends FieldTypeAttribute>, FieldTypeAttribute> attributes;
+
+  public FieldTypeBuilder indexed(boolean indexed) {
+    addFlagsIfTrue(indexed, FieldType.INDEXED);
+    return this;
+  }
+
+  public FieldTypeBuilder stored(boolean stored) {
+    addFlagsIfTrue(stored, FieldType.STORED);
+    return this;
+  }
+
+  public FieldTypeBuilder tokenized(boolean tokenized) {
+    addFlagsIfTrue(tokenized, FieldType.TOKENIZED);
+    return this;
+  }
+
+  public FieldTypeBuilder storeTermVectors(boolean storeTermVectors) {
+    addFlagsIfTrue(storeTermVectors, FieldType.STORE_TERM_VECTORS);
+    return this;
+  }
+
+  public FieldTypeBuilder storeOffsetsWithTermVectors(boolean storeOffsets) {
+    addFlagsIfTrue(storeOffsets, FieldType.STORE_OFFSETS_WITH_TERM_VECTORS);
+    return this;
+  }
+
+  public FieldTypeBuilder storePositionsWithTermVectors(boolean storePositions) {
+    addFlagsIfTrue(storePositions, FieldType.STORE_POSITIONS_WITH_TERM_VECTORS);
+    return this;
+  }
+
+  public FieldTypeBuilder indexNorms(boolean indexNorms) {
+    addFlagsIfTrue(indexNorms, FieldType.INDEX_NORMS);
+    return this;
+  }
+
+  public FieldTypeBuilder indexTermFreqs(boolean indexTermFreqs) {
+    addFlagsIfTrue(indexTermFreqs, FieldType.INDEX_TERM_FREQS);
+    return this;
+  }
+
+  public FieldTypeBuilder indexPositions(boolean indexPositions) {
+    addFlagsIfTrue(indexPositions, FieldType.INDEX_POSTIONS);
+    return this;
+  }
+
+  public FieldTypeBuilder lazy(boolean lazy) {
+    addFlagsIfTrue(lazy, FieldType.LAZY);
+    return this;
+  }
+
+  public FieldTypeBuilder addAttribute(FieldTypeAttribute typeAttribute) {
+    if (attributes == null) {
+      attributes = new HashMap<Class<? extends FieldTypeAttribute>, FieldTypeAttribute>();
+    }
+    attributes.put(typeAttribute.getClass(), typeAttribute);
+    return this;
+  }
+
+  public FieldType build() {
+    return new FieldType(flags, attributes);
+  }
+
+  // ================================================= Helper Methods ================================================
+
+  private void addFlagsIfTrue(boolean value, int flag) {
+    if (value) {
+      flags |= flag;
+    }
+  }
+}
Index: lucene/src/java/org/apache/lucene/document/FieldType.java
===================================================================
--- lucene/src/java/org/apache/lucene/document/FieldType.java	Thu Mar 24 19:58:58 NZDT 2011
+++ lucene/src/java/org/apache/lucene/document/FieldType.java	Thu Mar 24 19:58:58 NZDT 2011
@@ -0,0 +1,106 @@
+package org.apache.lucene.document;
+
+import java.util.Map;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class FieldType implements CoreFieldTypeAttribute {
+
+  public static final int INDEXED = 1;
+  public static final int STORED = 2;
+  public static final int TOKENIZED = 3;
+  public static final int STORE_TERM_VECTORS = 4;
+  public static final int STORE_OFFSETS_WITH_TERM_VECTORS = 5;
+  public static final int STORE_POSITIONS_WITH_TERM_VECTORS = 6;
+  public static final int INDEX_NORMS = 7;
+  public static final int INDEX_TERM_FREQS = 8;
+  public static final int INDEX_POSTIONS = 9;
+  public static final int LAZY = 10;
+  
+  private final Map<Class<? extends FieldTypeAttribute>, FieldTypeAttribute> attributes;
+  private final int flags;
+
+  public FieldType(int flags) {
+    this(flags, null);
+  }
+
+  public FieldType(int flags, Map<Class<? extends FieldTypeAttribute>, FieldTypeAttribute> attributes) {
+    this.flags = flags;
+    this.attributes = attributes;
+
+    if (this.attributes != null) {
+      this.attributes.put(CoreFieldTypeAttribute.class, this);
+    }
+  }
+
+  public boolean isIndexed() {
+    return flagsContain(INDEXED);
+  }
+
+  public boolean isStored() {
+    return flagsContain(STORED);
+  }
+
+  public boolean isTokenized() {
+    return flagsContain(TOKENIZED);
+  }
+
+  public boolean isTermVectorsStored() {
+    return flagsContain(STORE_TERM_VECTORS);
+  }
+
+  public boolean isOffsetsStoredWithTermVectors() {
+    return flagsContain(STORE_OFFSETS_WITH_TERM_VECTORS);
+  }
+
+  public boolean isPositionsStoredWithTermVectors() {
+    return flagsContain(STORE_POSITIONS_WITH_TERM_VECTORS);
+  }
+
+  public boolean isNormsIndexed() {
+    return flagsContain(INDEX_NORMS);
+  }
+
+  public boolean isTermFreqsIndexed() {
+    return flagsContain(INDEX_TERM_FREQS);
+  }
+
+  public boolean isPositionsIndexed() {
+    return flagsContain(INDEX_POSTIONS);
+  }
+
+  public boolean isLazy() {
+    return flagsContain(LAZY);
+  }
+
+  public <A extends FieldTypeAttribute> A getAttribute(Class<A> attributeClass) {
+    if (attributes == null) {
+      if (CoreFieldTypeAttribute.class == attributeClass) {
+        return attributeClass.cast(this);
+      }
+      return null;
+    }
+    return attributeClass.cast(attributes.get(attributeClass));
+  }
+
+  // ================================================= Helper Methods ================================================
+
+  private boolean flagsContain(int flag) {
+    return (flags & flag) == flag;
+  }
+
+}
