• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
today-context/src/main/java/infra/cache/interceptor/SimpleKey.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.cache.interceptor;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.io.IOException;
23
import java.io.ObjectInputStream;
24
import java.io.Serial;
25
import java.io.Serializable;
26
import java.util.Arrays;
27

28
import infra.lang.Assert;
29

30
/**
31
 * A simple key as returned from the {@link SimpleKeyGenerator}.
32
 *
33
 * @author Phillip Webb
34
 * @author Juergen Hoeller
35
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
36
 * @see SimpleKeyGenerator
37
 * @since 4.0
38
 */
39
@SuppressWarnings("serial")
40
public class SimpleKey implements Serializable {
41

42
  /**
43
   * An empty key.
44
   */
45
  public static final SimpleKey EMPTY = new SimpleKey();
7✔
46

47
  private final Object[] params;
48

49
  // Effectively final, just re-calculated on deserialization
50
  private transient int hashCode;
51

52
  /**
53
   * Create a new {@link SimpleKey} instance.
54
   *
55
   * @param elements the elements of the key
56
   */
57
  public SimpleKey(Object @Nullable ... elements) {
2✔
58
    Assert.notNull(elements, "Elements is required");
3✔
59
    this.params = elements.clone();
5✔
60
    // Pre-calculate hashCode field
61
    this.hashCode = calculateHash(this.params);
5✔
62
  }
1✔
63

64
  @Override
65
  public boolean equals(@Nullable Object other) {
66
    return (this == other || (other instanceof SimpleKey that
14✔
67
            && Arrays.deepEquals(this.params, that.params)));
5✔
68
  }
69

70
  @Override
71
  public final int hashCode() {
72
    // Expose pre-calculated hashCode field
73
    return this.hashCode;
3✔
74
  }
75

76
  @Override
77
  public String toString() {
78
    return getClass().getSimpleName() + " " + Arrays.deepToString(this.params);
×
79
  }
80

81
  @Serial
82
  private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
83
    ois.defaultReadObject();
2✔
84
    // Re-calculate hashCode field on deserialization
85
    this.hashCode = calculateHash(this.params);
5✔
86
  }
1✔
87

88
  /**
89
   * Calculate the hash of the key using its elements and
90
   * mix the result with the finalising function of MurmurHash3.
91
   */
92
  private static int calculateHash(@Nullable Object[] params) {
93
    int hash = Arrays.deepHashCode(params);
3✔
94
    hash = (hash ^ (hash >>> 16)) * 0x85ebca6b;
8✔
95
    hash = (hash ^ (hash >>> 13)) * 0xc2b2ae35;
8✔
96
    return hash ^ (hash >>> 16);
6✔
97
  }
98

99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc