Project

Profile

Help

Revision 4cd28f0b

Added by Michael Kay 11 months ago

Code changes for .NEU convertibility

View differences:

latest10/hej/net/sf/saxon/expr/BinaryExpression.java
17 17
import net.sf.saxon.value.Cardinality;
18 18

  
19 19
import java.util.ArrayList;
20
import java.util.Iterator;
20 21
import java.util.List;
21 22

  
22 23
/**
......
50 51

  
51 52
    @Override
52 53
    final public Iterable<Operand> operands() {
53
        return () -> new PairIterator<>(lhs, rhs);
54
        // For .NEU - don't use a lambda expression here
55
        return new Iterable<Operand>() {
56
            @Override
57
            public Iterator<Operand> iterator() {
58
                return new PairIterator<>(lhs, rhs);
59
            }
60
        };
54 61
    }
55 62

  
56 63

  
latest10/hej/net/sf/saxon/expr/UnaryExpression.java
15 15
import net.sf.saxon.trans.XPathException;
16 16
import net.sf.saxon.tree.jiter.MonoIterator;
17 17
import net.sf.saxon.type.ItemType;
18
import java.util.Iterator;
18 19

  
19 20
/**
20 21
 * Unary Expression: an expression taking a single operand expression
......
47 48

  
48 49
    @Override
49 50
    public Iterable<Operand> operands() {
50
        return () -> new MonoIterator<>(operand);
51
        // For .NEU - don't use a lambda expression here
52
        return new Iterable<Operand>() {
53
            @Override
54
            public Iterator<Operand> iterator() {
55
                return new MonoIterator<>(operand);
56
            }
57
        };
51 58
    }
52 59

  
53 60
    /**
latest10/hej/net/sf/saxon/ma/map/HashTrieMap.java
75 75

  
76 76
    /**
77 77
     * Create a singleton map with a single key and value
78
     * @param key the key value
78
     * @param key   the key value
79 79
     * @param value the associated value
80 80
     * @return a singleton map
81 81
     */
......
96 96

  
97 97
    /**
98 98
     * Create a map whose entries are copies of the entries in an existing MapItem
99
     *
100
     * @param map       the existing map to be copied
99
     * @param map the existing map to be copied
101 100
     * @return the new map
102 101
     */
103 102

  
104 103
    public static HashTrieMap copy(MapItem map) {
105
//        if (Instrumentation.ACTIVE) {
106
//            Instrumentation.count("copies");
107
//        }
108 104
        if (map instanceof HashTrieMap) {
109
            return (HashTrieMap)map;
105
            return (HashTrieMap) map;
110 106
        }
111 107
        HashTrieMap m2 = new HashTrieMap();
112 108
        for (KeyValuePair pair : map.keyValuePairs()) {
......
117 113

  
118 114
    /**
119 115
     * After adding an entry to the map, update the cached type information
120
     * @param key the new key
121
     * @param val the new associated value
116
     * @param key      the new key
117
     * @param val      the new associated value
122 118
     * @param wasEmpty true if the map was empty before adding these values
123 119
     */
124 120

  
125 121
    private void updateTypeInformation(AtomicValue key, Sequence val, boolean wasEmpty) {
126
//        if (Instrumentation.ACTIVE) {
127
//            Instrumentation.count("updateTypeInformation");
128
//        }
129 122
        if (wasEmpty) {
130 123
            keyUType = key.getUType();
131 124
            valueUType = SequenceTool.getUType(val);
......
156 149
        }
157 150
        int count = 0;
158 151
        //noinspection UnusedDeclaration
159
        for (KeyValuePair entry: keyValuePairs()) {
152
        for (KeyValuePair entry : keyValuePairs()) {
160 153
            count++;
161 154
        }
162 155
        return entries = count;
......
177 170
     *
178 171
     * @param requiredKeyType   the required keyType
179 172
     * @param requiredValueType the required valueType
180
     * @param th        the type hierarchy cache for the configuration
173
     * @param th                the type hierarchy cache for the configuration
181 174
     * @return true if the map conforms to the required type
182 175
     */
183 176
    @Override
......
264 257
                valueType = SequenceTool.getItemType(val, th);
265 258
                valueCard = SequenceTool.getCardinality(val);
266 259
            } else {
267
                keyType = (AtomicType)Type.getCommonSuperType(keyType, key.getItemType(), th);
260
                keyType = (AtomicType) Type.getCommonSuperType(keyType, key.getItemType(), th);
268 261
                valueType = Type.getCommonSuperType(valueType, SequenceTool.getItemType(val, th), th);
269 262
                valueCard = Cardinality.union(valueCard, SequenceTool.getCardinality(val));
270 263
            }
......
287 280
     * Get the lowest common item type of the keys in the map
288 281
     *
289 282
     * @return the most specific type to which all the keys belong. If the map is
290
     *         empty, return UType.VOID (the type with no instances)
283
     * empty, return UType.VOID (the type with no instances)
291 284
     */
292 285
    @Override
293 286
    public UType getKeyUType() {
......
299 292
     * without modifying the original. If there is already an entry with the specified key,
300 293
     * this entry is replaced by the new entry.
301 294
     *
302
     * @param key     the key of the new entry
303
     * @param value   the value associated with the new entry
295
     * @param key   the key of the new entry
296
     * @param value the value associated with the new entry
304 297
     * @return the new map containing the additional entry
305 298
     */
306 299

  
......
323 316
     * must only be called while initially populating the map, and must not be called if
324 317
     * anyone else might already be using the map.
325 318
     *
326
     * @param key     the key of the new entry. Any existing entry with this key is replaced.
327
     * @param value   the value associated with the new entry
319
     * @param key   the key of the new entry. Any existing entry with this key is replaced.
320
     * @param value the value associated with the new entry
328 321
     * @return true if an existing entry with the same key was replaced
329 322
     */
330 323

  
......
348 341
    /**
349 342
     * Remove an entry from the map
350 343
     *
351
     * @param key     the key of the entry to be removed
344
     * @param key the key of the entry to be removed
352 345
     * @return a new map in which the requested entry has been removed; or this map
353
     *         unchanged if the specified key was not present
346
     * unchanged if the specified key was not present
354 347
     */
355 348

  
356 349
    @Override
......
367 360
        result.keyUType = keyUType;
368 361
        result.valueUType = valueUType;
369 362
        result.valueCardinality = valueCardinality;
370
        result.entries = entries-1;
363
        result.entries = entries - 1;
371 364
        return result;
372 365
    }
373 366

  
374 367
    /**
375 368
     * Get an entry from the Map
376 369
     *
377
     * @param key     the value of the key
370
     * @param key the value of the key
378 371
     * @return the value associated with the given key, or null if the key is not present in the map
379 372
     */
380 373

  
381 374
    @Override
382
    public GroundedValue get(AtomicValue key)  {
375
    public GroundedValue get(AtomicValue key) {
383 376
        KeyValuePair o = imap.get(makeKey(key));
384
        return o==null ? null : o.value;
377
        return o == null ? null : o.value;
385 378
    }
386 379

  
387 380
    /**
388 381
     * Get an key/value pair from the Map
389 382
     *
390
     * @param key     the value of the key
383
     * @param key the value of the key
391 384
     * @return the key-value-pair associated with the given key, or null if the key is not present in the map
392 385
     */
393 386

  
......
397 390

  
398 391
    /**
399 392
     * Get the set of all key values in the map
393
     *
400 394
     * @return an iterator over the keys, in undefined order
401 395
     */
402 396

  
......
421 415
    /**
422 416
     * Get the set of all key-value pairs in the map
423 417
     *
424
     * @return an iterator over the key-value pairs
418
     * @return an iterable whose iterator delivers the key-value pairs
425 419
     */
426 420
    @Override
427 421
    public Iterable<KeyValuePair> keyValuePairs() {
428
//        if (Instrumentation.ACTIVE) {
429
//            Instrumentation.count("keyValuePairs");
430
//        }
431
        return () -> new Iterator<KeyValuePair>() {
432
            Iterator<Tuple2<AtomicMatchKey, KeyValuePair>> base = imap.iterator();
433

  
422
        // For .NEU - don't use a lambda expression here
423
        return new Iterable<KeyValuePair>() {
434 424
            @Override
435
            public boolean hasNext() {
436
                return base.hasNext();
437
            }
425
            public Iterator<KeyValuePair> iterator() {
426
                return new Iterator<KeyValuePair>() {
427
                    Iterator<Tuple2<AtomicMatchKey, KeyValuePair>> base = imap.iterator();
438 428

  
439
            @Override
440
            public KeyValuePair next() {
441
                return base.next()._2;
442
            }
443

  
444
            @Override
445
            public void remove() {
446
                base.remove();
447
            }
448
        };
429
                    @Override
430
                    public boolean hasNext() {
431
                        return base.hasNext();
432
                    }
449 433

  
434
                    @Override
435
                    public KeyValuePair next() {
436
                        return base.next()._2;
437
                    }
450 438

  
439
                    @Override
440
                    public void remove() {
441
                        base.remove();
442
                    }
443
                };
444
            };
445
        };
451 446
    }
452 447

  
453 448

  
latest10/hej/net/sf/saxon/ma/map/RangeKey.java
111 111
     */
112 112
    @Override
113 113
    public Iterable<KeyValuePair> keyValuePairs() {
114
        return () -> new Iterator<KeyValuePair>() {
115
            AtomicIterator keys = keys();
116
            AtomicValue next = keys.next();
114
        // For .NEU - don't use a lambda expression here
115
        return new Iterable<KeyValuePair>() {
116
            @NotNull
117 117
            @Override
118
            public boolean hasNext() {
119
                return next != null;
120
            }
118
            public Iterator<KeyValuePair> iterator() {
119
                return new Iterator<KeyValuePair>() {
120
                    AtomicIterator keys = keys();
121
                    AtomicValue next = keys.next();
121 122

  
122
            @Override
123
            public KeyValuePair next() {
124
                if (next == null) {
125
                    return null;
126
                } else {
127
                    KeyValuePair kvp = new KeyValuePair(next, get(next));
128
                    next = keys.next();
129
                    return kvp;
130
                }
123
                    @Override
124
                    public boolean hasNext() {
125
                        return next != null;
126
                    }
127

  
128
                    @Override
129
                    public KeyValuePair next() {
130
                        if (next == null) {
131
                            return null;
132
                        } else {
133
                            KeyValuePair kvp = new KeyValuePair(next, get(next));
134
                            next = keys.next();
135
                            return kvp;
136
                        }
137
                    }
138
                };
131 139
            }
132 140
        };
133 141
    }
latest10/hej/net/sf/saxon/ma/map/SingleEntryMap.java
20 20
import net.sf.saxon.value.AtomicValue;
21 21
import net.sf.saxon.value.SequenceType;
22 22

  
23
import java.util.Iterator;
24

  
23 25
/**
24 26
 * A key and a corresponding value to be held in a Map. A key-value pair also acts as a singleton
25 27
 * map in its own right.
......
82 84
     */
83 85
    @Override
84 86
    public Iterable<KeyValuePair> keyValuePairs() {
85
        return () -> new MonoIterator<>(new KeyValuePair(key, value));
87
        // For .NEU - don't use a lambda expression here
88
        return new Iterable<KeyValuePair>() {
89
            @Override
90
            public Iterator<KeyValuePair> iterator() {
91
                return new MonoIterator<>(new KeyValuePair(key, value));
92
            }
93
        };
86 94
    }
87 95

  
88 96
    /**
latest10/hej/net/sf/saxon/om/GroundedValue.java
146 146
    }
147 147

  
148 148
    default Iterable<? extends Item> asIterable() {
149
        return () -> {
150
            final UnfailingIterator base = iterate();
151
            return new Iterator<Item>() {
152

  
153
                Item pending = null;
154

  
155
                @Override
156
                public boolean hasNext() {
157
                    pending = base.next();
158
                    return pending != null;
159
                }
160

  
161
                @Override
162
                public Item next() {
163
                    return pending;
164
                }
165
            };
149
        // For .NEU - don't use a lambda expression here
150
        return new Iterable<Item>() {
151
            @Override
152
            public Iterator<Item> iterator() {
153
                final UnfailingIterator base = iterate();
154
                return new Iterator<Item>() {
155

  
156
                    Item pending = null;
157

  
158
                    @Override
159
                    public boolean hasNext() {
160
                        pending = base.next();
161
                        return pending != null;
162
                    }
163

  
164
                    @Override
165
                    public Item next() {
166
                        return pending;
167
                    }
168
                };
169
            }
166 170
        };
167 171
    }
168 172

  

Also available in: Unified diff