Changeset 6935 for FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/AdvancedDataViewWriter.java
- Timestamp:
- 02/03/16 23:24:10 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/AdvancedDataViewWriter.java
r6884 r6935 1 /** 2 * This software is copyright (c) 2013-2016 by 3 * - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) 4 * This is free software. You can redistribute it 5 * and/or modify it under the terms described in 6 * the GNU General Public License v3 of which you 7 * should have received a copy. Otherwise you can download 8 * it from 9 * 10 * http://www.gnu.org/licenses/gpl-3.0.txt 11 * 12 * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) 13 * 14 * @license http://www.gnu.org/licenses/gpl-3.0.txt 15 * GNU General Public License v3 16 */ 1 17 package eu.clarin.sru.server.fcs; 2 18 … … 11 27 12 28 29 /** 30 * Helper class for serializing Advanced data views. It can be used for writing 31 * more than one, but it is <em>not thread-save</em>. 32 */ 13 33 public class AdvancedDataViewWriter { 14 34 public enum Unit { 15 ITEM, 16 TIMESTAMP 35 ITEM, TIMESTAMP 17 36 } 18 37 private static final long INITIAL_SEGMENT_ID = 1; … … 27 46 28 47 48 /** 49 * Constructor. 50 * 51 * @param unit 52 * the unit to be used for span offsets 53 * @see Unit 54 */ 29 55 public AdvancedDataViewWriter(Unit unit) { 30 56 if (unit == null) { … … 35 61 36 62 63 /** 64 * Reset the writer for writing a new data view (instance). 65 */ 37 66 public void reset() { 38 67 nextSegmentId = INITIAL_SEGMENT_ID; … … 40 69 41 70 42 private static final class Segment { 43 private final String id; 44 private final long start; 45 private final long end; 46 private final URI ref; 47 48 private Segment(long id, long start, long end) { 49 this.id = "s" + Long.toHexString(id); 50 this.start = start; 51 this.end = end; 52 this.ref = null; 53 } 54 } 55 56 private static final class Span { 57 private final Segment segment; 58 private final String value; 59 private final String altValue; 60 private final String highlight; 61 62 63 private Span(Segment segment, String value, String altValue, 64 int highlight) { 65 this.segment = segment; 66 this.value = value; 67 this.altValue = altValue; 68 if (highlight != NO_HIGHLIGHT) { 69 this.highlight = "h" + Integer.toHexString(highlight); 70 } else { 71 this.highlight = null; 72 } 73 } 74 } 75 76 71 /** 72 * Add a span. 73 * 74 * @param layerId 75 * the span's layer id 76 * @param start 77 * the span's start offset 78 * @param end 79 * the span's end offset 80 * @param value 81 * the span's content value or <code>null</code> if none 82 * @throws IllegalArgumentException 83 * if any argument is invalid 84 */ 77 85 public void addSpan(URI layerId, long start, long end, String value) { 78 86 addSpan(layerId, start, end, value, null, NO_HIGHLIGHT); … … 80 88 81 89 90 /** 91 * Add a span. 92 * 93 * @param layerId 94 * the span's layer id 95 * @param start 96 * the span's start offset 97 * @param end 98 * the span's end offset 99 * @param value 100 * the span's content value or <code>null</code> if none 101 * @param highlight 102 * the highlight group 103 * @throws IllegalArgumentException 104 * if any argument is invalid 105 */ 82 106 public void addSpan(URI layerId, long start, long end, String value, 83 107 int highlight) { … … 86 110 87 111 112 /** 113 * Add a span. 114 * 115 * @param layerId 116 * the span's layer id 117 * @param start 118 * the span's start offset 119 * @param end 120 * the span's end offset 121 * @param value 122 * the span's content value or <code>null</code> if none 123 * @param altValue 124 * the span's alternate value or <code>null</code> if none 125 */ 88 126 public void addSpan(URI layerId, long start, long end, String value, 89 127 String altValue) { … … 92 130 93 131 132 /** 133 * Add a span. 134 * 135 * @param layerId 136 * the span's layer id 137 * @param start 138 * the span's start offset 139 * @param end 140 * the span's end offset 141 * @param value 142 * the span's content value or <code>null</code> if none 143 * @param altValue 144 * @param highlight 145 * the span's alternate value or <code>null</code> if none 146 * @param highlight 147 * the highlight group 148 * @throws IllegalArgumentException 149 * if any argument is invalid 150 */ 94 151 public void addSpan(URI layerId, long start, long end, String value, 95 152 String altValue, int highlight) { … … 131 188 if (segment.equals(span.segment)) { 132 189 // FIXME: better exception! 133 throw new IllegalArgumentException("segment already exists in layer"); 190 throw new IllegalArgumentException( 191 "segment already exists in layer"); 134 192 } 135 193 } … … 138 196 139 197 198 /** 199 * Write the Advanced data view to the output stream. 200 * 201 * @param writer 202 * the writer to write to 203 * @throws XMLStreamException 204 * if an error occurs 205 */ 140 206 public void writeAdvancedDataView(XMLStreamWriter writer) 141 207 throws XMLStreamException { … … 204 270 } 205 271 272 private static final class Segment { 273 private final String id; 274 private final long start; 275 private final long end; 276 private final URI ref; 277 278 279 private Segment(long id, long start, long end) { 280 this.id = "s" + Long.toHexString(id); 281 this.start = start; 282 this.end = end; 283 this.ref = null; 284 } 285 } 286 287 private static final class Span { 288 private final Segment segment; 289 private final String value; 290 private final String altValue; 291 private final String highlight; 292 293 294 private Span(Segment segment, String value, String altValue, 295 int highlight) { 296 this.segment = segment; 297 this.value = value; 298 this.altValue = altValue; 299 if (highlight != NO_HIGHLIGHT) { 300 this.highlight = "h" + Integer.toHexString(highlight); 301 } else { 302 this.highlight = null; 303 } 304 } 305 } 306 206 307 } // class AdvancedDataViewHelper
Note: See TracChangeset
for help on using the changeset viewer.