001: package test.it.unimi.dsi.mg4j.document;
002:
003: /*
004: * MG4J: Managing Gigabytes for Java
005: *
006: * Copyright (C) 2006-2007 Sebastiano Vigna
007: *
008: * This library is free software; you can redistribute it and/or modify it
009: * under the terms of the GNU Lesser General Public License as published by the Free
010: * Software Foundation; either version 2.1 of the License, or (at your option)
011: * any later version.
012: *
013: * This library is distributed in the hope that it will be useful, but
014: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
015: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
016: * for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: */
023:
024: import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
025: import it.unimi.dsi.io.FastBufferedReader;
026: import it.unimi.dsi.io.NullReader;
027: import it.unimi.dsi.io.WordReader;
028: import it.unimi.dsi.mg4j.document.AbstractDocument;
029: import it.unimi.dsi.mg4j.document.Document;
030: import it.unimi.dsi.mg4j.document.PropertyBasedDocumentFactory;
031: import it.unimi.dsi.util.Properties;
032:
033: import java.io.InputStream;
034:
035: /** A factory (with a single text field named <samp>text</samp>) that does not read at all from input streams and always
036: * return an empty reader.
037: */
038:
039: @SuppressWarnings("unused")
040: public class NullDocumentFactory extends PropertyBasedDocumentFactory {
041: private static final long serialVersionUID = 1L;
042:
043: public NullDocumentFactory() {
044: }
045:
046: public NullDocumentFactory(
047: final Reference2ObjectMap<Enum<?>, Object> defaultMetadata) {
048: }
049:
050: public NullDocumentFactory(final Properties properties) {
051: }
052:
053: public NullDocumentFactory(final String[] property) {
054: }
055:
056: public NullDocumentFactory copy() {
057: return this ;
058: }
059:
060: public int numberOfFields() {
061: return 1;
062: }
063:
064: public String fieldName(final int field) {
065: if (field != 0)
066: throw new IndexOutOfBoundsException();
067: return "text";
068: }
069:
070: public int fieldIndex(final String fieldName) {
071: return fieldName.equals("text") ? 0 : -1;
072: }
073:
074: public FieldType fieldType(final int field) {
075: return FieldType.TEXT;
076: }
077:
078: public Document getDocument(final InputStream rawContent,
079: final Reference2ObjectMap<Enum<?>, Object> metadata) {
080: return new AbstractDocument() {
081:
082: public CharSequence title() {
083: return "dummy title";
084: }
085:
086: public String toString() {
087: return title().toString();
088: }
089:
090: public CharSequence uri() {
091: return "dummy://";
092: }
093:
094: public Object content(final int field) {
095: if (field != 0)
096: throw new IndexOutOfBoundsException();
097: return NullReader.getInstance();
098: }
099:
100: public WordReader wordReader(final int field) {
101: return new FastBufferedReader();
102: }
103: };
104: }
105: }
|