ReductionContext.java

1
/*******************************************************************************
2
 * Copyright (C) 2026, Leo Galambos
3
 * All rights reserved.
4
 * 
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 * 
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 
11
 * 2. Redistributions in binary form must reproduce the above copyright notice,
12
 *    this list of conditions and the following disclaimer in the documentation
13
 *    and/or other materials provided with the distribution.
14
 * 
15
 * 3. Neither the name of the copyright holder nor the names of its contributors
16
 *    may be used to endorse or promote products derived from this software
17
 *    without specific prior written permission.
18
 * 
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
 * POSSIBILITY OF SUCH DAMAGE.
30
 ******************************************************************************/
31
package org.egothor.stemmer.trie;
32
33
import java.util.LinkedHashMap;
34
import java.util.Map;
35
36
import org.egothor.stemmer.ReductionSettings;
37
38
/**
39
 * Reduction context used while canonicalizing mutable nodes.
40
 *
41
 * @param <V> value type
42
 */
43
public final class ReductionContext<V> {
44
45
    /**
46
     * Reduction settings.
47
     */
48
    private final ReductionSettings settings;
49
50
    /**
51
     * Canonical nodes by signature.
52
     */
53
    private final Map<ReductionSignature<V>, ReducedNode<V>> canonicalNodes;
54
55
    /**
56
     * Creates a new context.
57
     *
58
     * @param settings settings
59
     */
60
    public ReductionContext(final ReductionSettings settings) {
61
        this.settings = settings;
62
        this.canonicalNodes = new LinkedHashMap<>();
63
    }
64
65
    /**
66
     * Looks up a canonical node.
67
     *
68
     * @param signature signature
69
     * @return canonical node, or {@code null} if absent
70
     */
71
    public ReducedNode<V> lookup(final ReductionSignature<V> signature) {
72 1 1. lookup : replaced return value with null for org/egothor/stemmer/trie/ReductionContext::lookup → KILLED
        return this.canonicalNodes.get(signature);
73
    }
74
75
    /**
76
     * Registers a canonical node.
77
     *
78
     * @param signature signature
79
     * @param node      node
80
     */
81
    public void register(final ReductionSignature<V> signature, final ReducedNode<V> node) {
82
        this.canonicalNodes.put(signature, node);
83
    }
84
85
    /**
86
     * Returns the settings.
87
     *
88
     * @return settings
89
     */
90
    public ReductionSettings settings() {
91 1 1. settings : replaced return value with null for org/egothor/stemmer/trie/ReductionContext::settings → KILLED
        return this.settings;
92
    }
93
94
    /**
95
     * Returns the number of canonical nodes.
96
     *
97
     * @return canonical node count
98
     */
99
    public int canonicalNodeCount() {
100 1 1. canonicalNodeCount : replaced int return with 0 for org/egothor/stemmer/trie/ReductionContext::canonicalNodeCount → KILLED
        return this.canonicalNodes.size();
101
    }
102
}

Mutations

72

1.1
Location : lookup
Killed by : org.egothor.stemmer.trie.ReductionContextTest.[engine:junit-jupiter]/[class:org.egothor.stemmer.trie.ReductionContextTest]/[method:shouldExposeSettingsAndManageCanonicalNodeRegistry()]
replaced return value with null for org/egothor/stemmer/trie/ReductionContext::lookup → KILLED

91

1.1
Location : settings
Killed by : org.egothor.stemmer.trie.ReductionContextTest.[engine:junit-jupiter]/[class:org.egothor.stemmer.trie.ReductionContextTest]/[method:shouldExposeSettingsAndManageCanonicalNodeRegistry()]
replaced return value with null for org/egothor/stemmer/trie/ReductionContext::settings → KILLED

100

1.1
Location : canonicalNodeCount
Killed by : org.egothor.stemmer.trie.ReductionContextTest.[engine:junit-jupiter]/[class:org.egothor.stemmer.trie.ReductionContextTest]/[method:shouldExposeSettingsAndManageCanonicalNodeRegistry()]
replaced int return with 0 for org/egothor/stemmer/trie/ReductionContext::canonicalNodeCount → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1