Source Code Cross Referenced for MapVirtualDocumentCollection.java in  » Search-Engine » mg4j » test » it » unimi » dsi » mg4j » document » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » mg4j » test.it.unimi.dsi.mg4j.document 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package test.it.unimi.dsi.mg4j.document;
002:
003:        import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
004:        import it.unimi.dsi.fastutil.objects.ObjectArrayList;
005:        import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
006:        import it.unimi.dsi.fastutil.objects.Reference2ObjectMaps;
007:        import it.unimi.dsi.io.FastBufferedReader;
008:        import it.unimi.dsi.io.WordReader;
009:        import it.unimi.dsi.lang.MutableString;
010:        import it.unimi.dsi.mg4j.document.AbstractDocumentCollection;
011:        import it.unimi.dsi.mg4j.document.AbstractDocumentFactory;
012:        import it.unimi.dsi.mg4j.document.Document;
013:        import it.unimi.dsi.mg4j.document.DocumentCollection;
014:        import it.unimi.dsi.mg4j.document.DocumentFactory;
015:        import it.unimi.dsi.mg4j.tool.VirtualDocumentResolver;
016:        import it.unimi.dsi.mg4j.util.parser.callback.AnchorExtractor.Anchor;
017:
018:        import java.io.IOException;
019:        import java.io.InputStream;
020:        import java.util.Map;
021:
022:        /** A virtual document collection explicitly defined by an array of maps and a trivial resolver (mainly useful for testing).
023:         * 
024:         * <p>Every map in the provided sequence is considered a virtual document, and the only
025:         * field virtual. The factory is built-in.
026:         * 
027:         * <p>For simple testing, it is suggested that the provided document specifiers are just integers (as strings),
028:         * and that an instance of {@link MapVirtualDocumentCollection.TrivialVirtualDocumentResolver} is used to resolve them.
029:         */
030:
031:        public class MapVirtualDocumentCollection extends
032:                AbstractDocumentCollection {
033:            /** A trivial resolver that just parses document specifier as integers. */
034:            public final static class TrivialVirtualDocumentResolver implements 
035:                    VirtualDocumentResolver {
036:                private static final long serialVersionUID = 1L;
037:                private int numberOfDocuments;
038:
039:                public int numberOfDocuments() {
040:                    return numberOfDocuments;
041:                }
042:
043:                public void context(Document document) {
044:                }
045:
046:                public int resolve(CharSequence virtualDocumentSpec) {
047:                    final int d = Integer.parseInt(virtualDocumentSpec
048:                            .toString());
049:                    return d < 0 || d >= numberOfDocuments ? -1 : d;
050:                }
051:
052:                public TrivialVirtualDocumentResolver(
053:                        final int numberOfDocuments) {
054:                    this .numberOfDocuments = numberOfDocuments;
055:                }
056:            };
057:
058:            public final static class MapVirtualDocumentFactory extends
059:                    AbstractDocumentFactory {
060:                private static final long serialVersionUID = 1L;
061:
062:                public DocumentFactory copy() {
063:                    return this ;
064:                }
065:
066:                public int fieldIndex(String fieldName) {
067:                    if ("virtual".equals(fieldName))
068:                        return 0;
069:                    return -1;
070:                }
071:
072:                public String fieldName(int field) {
073:                    ensureFieldIndex(field);
074:                    return "virtual";
075:                }
076:
077:                public FieldType fieldType(int field) {
078:                    ensureFieldIndex(field);
079:                    return FieldType.VIRTUAL;
080:                }
081:
082:                public Document getDocument(InputStream rawContent,
083:                        Reference2ObjectMap<Enum<?>, Object> metadata)
084:                        throws IOException {
085:                    throw new UnsupportedOperationException();
086:                }
087:
088:                public int numberOfFields() {
089:                    return 1;
090:                }
091:            }
092:
093:            final public Int2ObjectMap<? extends CharSequence>[] virtual;
094:            final DocumentFactory factory;
095:
096:            public MapVirtualDocumentCollection(
097:                    final Int2ObjectMap<? extends CharSequence>... virtual) {
098:                factory = new MapVirtualDocumentFactory();
099:                this .virtual = virtual;
100:            }
101:
102:            public int size() {
103:                return virtual.length;
104:            }
105:
106:            public Document document(final int index) {
107:                return new Document() {
108:                    public void close() {
109:                    }
110:
111:                    public Object content(int field) throws IOException {
112:                        ensureDocumentIndex(index);
113:                        ObjectArrayList<Anchor> result = new ObjectArrayList<Anchor>();
114:                        for (Map.Entry<Integer, ? extends CharSequence> entry : virtual[index]
115:                                .entrySet())
116:                            result.add(new Anchor(new MutableString(entry
117:                                    .getKey().toString()), new MutableString(
118:                                    entry.getValue())));
119:                        return result;
120:                    }
121:
122:                    public CharSequence title() {
123:                        return null;
124:                    }
125:
126:                    public CharSequence uri() {
127:                        return null;
128:                    }
129:
130:                    public WordReader wordReader(int field) {
131:                        return new FastBufferedReader();
132:                    }
133:                };
134:            }
135:
136:            public InputStream stream(final int index) throws IOException {
137:                throw new UnsupportedOperationException();
138:            }
139:
140:            @SuppressWarnings("unchecked")
141:            public Reference2ObjectMap<Enum<?>, Object> metadata(int index)
142:                    throws IOException {
143:                return Reference2ObjectMaps.EMPTY_MAP;
144:            }
145:
146:            public DocumentCollection copy() {
147:                return this ;
148:            }
149:
150:            public DocumentFactory factory() {
151:                return factory;
152:            };
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.