• 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

97.14
today-context/src/main/java/infra/context/properties/source/DefaultPropertyMapper.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.context.properties.source;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.util.Collections;
23
import java.util.List;
24

25
import infra.util.ObjectUtils;
26

27
/**
28
 * Default {@link PropertyMapper} implementation. Names are mapped by removing invalid
29
 * characters and converting to lower case. For example "{@code my.server_name.PORT}" is
30
 * mapped to "{@code my.servername.port}".
31
 *
32
 * @author Phillip Webb
33
 * @author Madhura Bhave
34
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
35
 * @see PropertyMapper
36
 * @see DefaultConfigurationPropertySource
37
 * @since 4.0
38
 */
39
final class DefaultPropertyMapper implements PropertyMapper {
40

41
  public static final PropertyMapper INSTANCE = new DefaultPropertyMapper();
5✔
42

43
  @Nullable
44
  private LastMapping<ConfigurationPropertyName, List<String>> lastMappedConfigurationPropertyName;
45

46
  @Nullable
47
  private LastMapping<String, ConfigurationPropertyName> lastMappedPropertyName;
48

49
  private DefaultPropertyMapper() {
50
  }
51

52
  @Override
53
  public List<String> map(ConfigurationPropertyName configurationPropertyName) {
54
    // Use a local copy in case another thread changes things
55
    LastMapping<ConfigurationPropertyName, List<String>> last = this.lastMappedConfigurationPropertyName;
3✔
56
    if (last != null && last.isFrom(configurationPropertyName)) {
6✔
57
      return last.mapping;
4✔
58
    }
59
    String convertedName = configurationPropertyName.toString();
3✔
60
    List<String> mapping = Collections.singletonList(convertedName);
3✔
61
    this.lastMappedConfigurationPropertyName = new LastMapping<>(configurationPropertyName, mapping);
7✔
62
    return mapping;
2✔
63
  }
64

65
  @Override
66
  public ConfigurationPropertyName map(String propertySourceName) {
67
    // Use a local copy in case another thread changes things
68
    LastMapping<String, ConfigurationPropertyName> last = this.lastMappedPropertyName;
3✔
69
    if (last != null && last.isFrom(propertySourceName)) {
6✔
70
      return last.mapping;
4✔
71
    }
72
    ConfigurationPropertyName mapping = tryMap(propertySourceName);
4✔
73
    this.lastMappedPropertyName = new LastMapping<>(propertySourceName, mapping);
7✔
74
    return mapping;
2✔
75
  }
76

77
  private ConfigurationPropertyName tryMap(String propertySourceName) {
78
    try {
79
      ConfigurationPropertyName convertedName = ConfigurationPropertyName.adapt(propertySourceName, '.');
4✔
80
      if (!convertedName.isEmpty()) {
3✔
81
        return convertedName;
2✔
82
      }
83
    }
84
    catch (Exception ignored) {
×
85
    }
1✔
86
    return ConfigurationPropertyName.EMPTY;
2✔
87
  }
88

89
  private static class LastMapping<T, M> {
90

91
    public final T from;
92

93
    public final M mapping;
94

95
    LastMapping(T from, M mapping) {
2✔
96
      this.from = from;
3✔
97
      this.mapping = mapping;
3✔
98
    }
1✔
99

100
    boolean isFrom(T from) {
101
      return ObjectUtils.nullSafeEquals(from, this.from);
5✔
102
    }
103

104
  }
105

106
}
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