Project

Profile

Help

Revision a8bc0cf0

Added by Michael Kay over 1 year ago

Commit some files that had somehow got lost...

View differences:

latest10/hej/net/sf/saxon/event/SinkOutputter.java
1
package net.sf.saxon.event;
2

  
3
import net.sf.saxon.om.NodeName;
4
import net.sf.saxon.s9api.Location;
5
import net.sf.saxon.trans.XPathException;
6
import net.sf.saxon.type.SchemaType;
7
import net.sf.saxon.type.SimpleType;
8

  
9
/**
10
 * An Outputter that swallows (discards) all input supplied to it
11
 */
12

  
13
public class SinkOutputter extends Outputter {
14

  
15
    @Override
16
    public void startDocument(int properties) throws XPathException {
17

  
18
    }
19

  
20
    @Override
21
    public void endDocument() throws XPathException {
22

  
23
    }
24

  
25
    @Override
26
    public void startElement(NodeName elemName, SchemaType typeCode, Location location, int properties) throws XPathException {
27

  
28
    }
29

  
30
    @Override
31
    public void namespace(String prefix, String namespaceUri, int properties) throws XPathException {
32

  
33
    }
34

  
35
    @Override
36
    public void attribute(NodeName attName, SimpleType typeCode, CharSequence value, Location location, int properties) throws XPathException {
37

  
38
    }
39

  
40
    @Override
41
    public void endElement() throws XPathException {
42

  
43
    }
44

  
45
    @Override
46
    public void characters(CharSequence chars, Location location, int properties) throws XPathException {
47

  
48
    }
49

  
50
    @Override
51
    public void processingInstruction(String name, CharSequence data, Location location, int properties) throws XPathException {
52

  
53
    }
54

  
55
    @Override
56
    public void comment(CharSequence content, Location location, int properties) throws XPathException {
57

  
58
    }
59
}
60

  
61
// Copyright (c) 2009-2020 Saxonica Limited
latest10/hej/net/sf/saxon/gizmo/package.html
1
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
2
<!-- Copyright (c) 2020 Saxonica Limited. -->
3
<!-- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -->
4
<!-- If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
5
<!-- This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. -->
6
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
7

  
8
<html>
9

  
10
<head>
11
    <title>Package overview for net.sf.saxon.gizmo</title>
12
</head>
13

  
14
<body>
15

  
16
<p>This package provides supporting code for the Gizmo utility, found at <code>net.sf.saxon.Gizmo</code>.</p>
17

  
18
<p>It is chiefly concerned with interfacing to the JLine2 library, which provides supporting services
19
to handle command line editing, content completion, and session history</p>
20

  
21

  
22

  
23
</body>
24
</html>
latest10/hej/net/sf/saxon/value/SequenceSlice.java
1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2018-2020 Saxonica Limited
3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7

  
8
package net.sf.saxon.value;
9

  
10
import net.sf.saxon.expr.StaticProperty;
11
import net.sf.saxon.om.GroundedValue;
12
import net.sf.saxon.om.Item;
13
import net.sf.saxon.om.SequenceTool;
14
import net.sf.saxon.trans.XPathException;
15
import net.sf.saxon.tree.iter.ListIterator;
16
import net.sf.saxon.tree.util.FastStringBuffer;
17

  
18
import java.util.Iterator;
19
import java.util.List;
20

  
21

  
22
/**
23
 * A sequence value implemented extensionally. That is, this class represents a sequence
24
 * by allocating memory to each item in the sequence.
25
 */
26

  
27
public class SequenceSlice implements GroundedValue {
28
    private List<? extends Item> value;
29
    private int offset;
30
    private int length;
31

  
32
    /**
33
     * Construct an sequence from a slice of a list of items. Note, the list of items is used as is,
34
     * which means the caller must not subsequently change its contents.
35
     *
36
     * @param value the list of items
37
     * @param offset the zero-based position of the first item to be included in the sequence
38
     * @param length the number of items to be included in the sequence; if this exceeds the number
39
     *               of items available for inclusion, include all items up to the end of the sequence
40
     * @throws IndexOutOfBoundsException if offset < 0 or length < 0 or offset + length < value.size()
41
     */
42

  
43
    public SequenceSlice(List<? extends Item> value, int offset, int length) {
44
        this.value = value;
45
        this.offset = offset;
46
        if (offset < 0 || length < 0) {
47
            throw new IndexOutOfBoundsException();
48
        }
49
        if (length > value.size() || offset + length > value.size()) { // carefully written to handle length=Integer.MAX_VALUE
50
            this.length = value.size() - offset;
51
        } else {
52
            this.length = length;
53
        }
54
    }
55

  
56
    public String getStringValue() throws XPathException {
57
        return SequenceTool.getStringValue(this);
58
    }
59

  
60
    public CharSequence getStringValueCS() throws XPathException {
61
        return SequenceTool.getStringValue(this);
62
    }
63

  
64
    /**
65
     * Get the first item in the sequence.
66
     *
67
     * @return the first item in the sequence if there is one, or null if the sequence
68
     *         is empty
69
     */
70
    public Item head() {
71
        return itemAt(0);
72
    }
73

  
74
    /**
75
     * Get the number of items in the sequence
76
     *
77
     * @return the number of items in the sequence
78
     */
79

  
80
    public int getLength() {
81
        return length;
82
    }
83

  
84
    /**
85
     * Determine the cardinality
86
     *
87
     * @return the cardinality of the sequence, using the constants defined in
88
     *         net.sf.saxon.value.Cardinality
89
     * @see Cardinality
90
     */
91

  
92
    public int getCardinality() {
93
        switch (getLength()) {
94
            case 0:
95
                return StaticProperty.EMPTY;
96
            case 1:
97
                return StaticProperty.EXACTLY_ONE;
98
            default:
99
                return StaticProperty.ALLOWS_ONE_OR_MORE;
100
        }
101
    }
102

  
103
    /**
104
     * Get the n'th item in the sequence (starting with 0 as the first item)
105
     *
106
     * @param n the position of the required item
107
     * @return the n'th item in the sequence, or null if the position is out of range
108
     */
109

  
110
    /*@Nullable*/
111
    public Item itemAt(int n) {
112
        if (n < 0 || n >= getLength()) {
113
            return null;
114
        } else {
115
            return value.get(n + offset);
116
        }
117
    }
118

  
119
    /**
120
     * Return an iterator over this sequence.
121
     *
122
     * @return the required SequenceIterator, positioned at the start of the
123
     *         sequence
124
     */
125

  
126
    /*@NotNull*/
127
    public ListIterator<? extends Item> iterate() {
128
        return new ListIterator<>(value.subList(offset, offset+length));
129
    }
130
    
131
    /**
132
     * Get a subsequence of the value
133
     *
134
     * @param start  the index of the first item to be included in the result, counting from zero.
135
     *               A negative value is taken as zero. If the value is beyond the end of the sequence, an empty
136
     *               sequence is returned
137
     * @param length the number of items to be included in the result. Specify Integer.MAX_VALUE to
138
     *               get the subsequence up to the end of the base sequence. If the value is negative, an empty sequence
139
     *               is returned. If the value goes off the end of the sequence, the result returns items up to the end
140
     *               of the sequence
141
     * @return the required subsequence. If min is
142
     */
143

  
144
    /*@NotNull*/
145
    public GroundedValue subsequence(int start, int length) {
146
        if (start < 0) {
147
            start = 0;
148
        }
149
        int newStart = start+offset;
150
        if (newStart > value.size()) {
151
            return EmptySequence.getInstance();
152
        }
153
        if (length < 0) {
154
            return EmptySequence.getInstance();
155
        }
156
        int newLength = Integer.min(length, this.length);
157
        if (newStart + newLength > value.size()) {
158
            newLength = value.size() - newStart;
159
        }
160
        switch (newLength) {
161
            case 0:
162
                return EmptySequence.getInstance();
163
            case 1:
164
                return value.get(newStart);
165
            default:
166
                return new SequenceSlice(value, newStart, newLength);
167
        }
168
    }
169

  
170
    /*@NotNull*/
171
    public String toString() {
172
        FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.C64);
173
        for (int i = 0; i < getLength(); i++) {
174
            fsb.append(i == 0 ? "(" : ", ");
175
            fsb.append(itemAt(i).toString());
176
        }
177
        fsb.cat(')');
178
        return fsb.toString();
179
    }
180

  
181
    /**
182
     * Reduce the sequence to its simplest form. If the value is an empty sequence, the result will be
183
     * EmptySequence.getInstance(). If the value is a single atomic value, the result will be an instance
184
     * of AtomicValue. If the value is a single item of any other kind, the result will be an instance
185
     * of One. Otherwise, the result will typically be unchanged.
186
     *
187
     * @return the simplified sequence
188
     */
189
    public GroundedValue reduce() {
190
        int len = getLength();
191
        if (len == 0) {
192
            return EmptySequence.getInstance();
193
        } else if (len == 1) {
194
            return itemAt(0);
195
        } else {
196
            return this;
197
        }
198
    }
199

  
200
    /**
201
     * Get the contents of this value in the form of a Java {@link Iterable},
202
     * so that it can be used in a for-each expression
203
     * @return an Iterable containing the same sequence of items
204
     */
205

  
206
    public Iterable<? extends Item> asIterable() {
207
        return value.subList(offset, offset+length);
208
    }
209

  
210
    /**
211
     * Get an iterator (a Java {@link Iterator}) over the items in this sequence.
212
     * @return an iterator over the items in this sequence.
213
     */
214

  
215
    public Iterator<? extends Item> iterator() {
216
        return value.subList(offset, offset + length).iterator();
217
    }
218
}
219

  

Also available in: Unified diff