Ignore:
Timestamp:
02/03/16 23:24:10 (8 years ago)
Author:
Oliver Schonefeld
Message:
  • update/add copyright
  • fix typo in class name
  • minor changes
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 */
    117package eu.clarin.sru.server.fcs;
    218
     
    1127
    1228
     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 */
    1333public class AdvancedDataViewWriter {
    1434    public enum Unit {
    15         ITEM,
    16         TIMESTAMP
     35        ITEM, TIMESTAMP
    1736    }
    1837    private static final long INITIAL_SEGMENT_ID = 1;
     
    2746
    2847
     48    /**
     49     * Constructor.
     50     *
     51     * @param unit
     52     *            the unit to be used for span offsets
     53     * @see Unit
     54     */
    2955    public AdvancedDataViewWriter(Unit unit) {
    3056        if (unit == null) {
     
    3561
    3662
     63    /**
     64     * Reset the writer for writing a new data view (instance).
     65     */
    3766    public void reset() {
    3867        nextSegmentId = INITIAL_SEGMENT_ID;
     
    4069
    4170
    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     */
    7785    public void addSpan(URI layerId, long start, long end, String value) {
    7886        addSpan(layerId, start, end, value, null, NO_HIGHLIGHT);
     
    8088
    8189
     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     */
    82106    public void addSpan(URI layerId, long start, long end, String value,
    83107            int highlight) {
     
    86110
    87111
     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     */
    88126    public void addSpan(URI layerId, long start, long end, String value,
    89127            String altValue) {
     
    92130
    93131
     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     */
    94151    public void addSpan(URI layerId, long start, long end, String value,
    95152            String altValue, int highlight) {
     
    131188            if (segment.equals(span.segment)) {
    132189                // FIXME: better exception!
    133                 throw new IllegalArgumentException("segment already exists in layer");
     190                throw new IllegalArgumentException(
     191                        "segment already exists in layer");
    134192            }
    135193        }
     
    138196
    139197
     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     */
    140206    public void writeAdvancedDataView(XMLStreamWriter writer)
    141207            throws XMLStreamException {
     
    204270    }
    205271
     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
    206307} // class AdvancedDataViewHelper
Note: See TracChangeset for help on using the changeset viewer.