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

Mutations

76

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

95

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

104

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