• 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

88.0
today-context/src/main/java/infra/context/properties/source/MapConfigurationPropertySource.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.Iterator;
24
import java.util.LinkedHashMap;
25
import java.util.Map;
26
import java.util.stream.Stream;
27

28
import infra.core.env.MapPropertySource;
29
import infra.lang.Assert;
30

31
/**
32
 * A {@link ConfigurationPropertySource} backed by a {@link Map} and using standard name
33
 * mapping rules.
34
 *
35
 * @author Phillip Webb
36
 * @author Madhura Bhave
37
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
38
 * @since 4.0
39
 */
40
public class MapConfigurationPropertySource implements IterableConfigurationPropertySource {
41

42
  private static final PropertyMapper[] DEFAULT_MAPPERS = { DefaultPropertyMapper.INSTANCE };
8✔
43

44
  private final Map<String, Object> source;
45

46
  private final IterableConfigurationPropertySource delegate;
47

48
  /**
49
   * Create a new empty {@link MapConfigurationPropertySource} instance.
50
   */
51
  public MapConfigurationPropertySource() {
52
    this(Collections.emptyMap());
3✔
53
  }
1✔
54

55
  /**
56
   * Create a new {@link MapConfigurationPropertySource} instance with entries copies
57
   * from the specified map.
58
   *
59
   * @param map the source map
60
   */
61
  public MapConfigurationPropertySource(Map<?, ?> map) {
2✔
62
    this.source = new LinkedHashMap<>();
5✔
63
    MapPropertySource mapPropertySource = new MapPropertySource("source", this.source);
7✔
64
    this.delegate = new DefaultIterableConfigurationPropertySource(mapPropertySource, false, DEFAULT_MAPPERS);
8✔
65
    putAll(map);
3✔
66
  }
1✔
67

68
  /**
69
   * Add all entries from the specified map.
70
   *
71
   * @param map the source map
72
   */
73
  public void putAll(Map<?, ?> map) {
74
    Assert.notNull(map, "Map is required");
3✔
75
    assertNotReadOnlySystemAttributesMap(map);
3✔
76
    map.forEach(this::put);
4✔
77
  }
1✔
78

79
  /**
80
   * Add an individual entry.
81
   *
82
   * @param name the name
83
   * @param value the value
84
   */
85
  public void put(Object name, Object value) {
86
    Assert.notNull(name, "'name' is required");
3✔
87
    this.source.put(name.toString(), value);
7✔
88
  }
1✔
89

90
  @Override
91
  public Object getUnderlyingSource() {
92
    return this.source;
×
93
  }
94

95
  @Nullable
96
  @Override
97
  public ConfigurationProperty getConfigurationProperty(ConfigurationPropertyName name) {
98
    return this.delegate.getConfigurationProperty(name);
5✔
99
  }
100

101
  @Override
102
  public Iterator<ConfigurationPropertyName> iterator() {
103
    return this.delegate.iterator();
4✔
104
  }
105

106
  @Override
107
  public Stream<ConfigurationPropertyName> stream() {
108
    return this.delegate.stream();
4✔
109
  }
110

111
  private void assertNotReadOnlySystemAttributesMap(Map<?, ?> map) {
112
    try {
113
      map.size();
3✔
114
    }
115
    catch (UnsupportedOperationException ex) {
×
116
      throw new IllegalArgumentException("Security restricted maps are not supported", ex);
×
117
    }
1✔
118
  }
1✔
119

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