Skip to content

Commit

Permalink
Update OverrideConfiguration
Browse files Browse the repository at this point in the history
- Introduced fields for values that were retrieved from the parent configuration whenever they were called.
- Eagerly filling the new fields in the OverrideConfiguration's constructor.
  • Loading branch information
marcus-talbot42 committed Apr 4, 2024
1 parent 14073b6 commit 173e59e
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Issue [#196](https://github.com/42BV/beanmapper/issues/196) **Calls to the logger should not contain a call to String.formatted(Object...)**; Fixed by removing any formatting from performance logging. Trace-logging should keep the level of detail provided by the formatting.
- Issue [#197](https://github.com/42BV/beanmapper/issues/197) **Implement caching for Unproxy results.**; Created UnproxyResultStore, allowing for thread-safe caching and retrieval of unproxied classes.
- Issue [#199](https://github.com/42BV/beanmapper/issues/199) **Use of OverrideField causes excessive resource consumption.**; Use of OverrideField was phased out. OverrideField itself is now deprecated for removal.
- Issue [#201](https://github.com/42BV/beanmapper/issues/201) **Calls from OverrideConfiguration to parentConfiguration cause unnecessary overhead.**; Introduced fields in the OverrideConfiguration, to limit the overhead of calls to the parent configuration.

## [4.1.3] - 2024-03-27

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/beanmapper/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ public interface Configuration {
*/
List<BeanPair> getBeanPairs();

/**
* Retrieves the CollectionHandlerStore from the CoreConfiguration.
*
* @return The CollectionHandlerStore retrieved from the CoreConfiguration.
*/
CollectionHandlerStore getCollectionHandlerStore();

boolean isConverterChoosable();

void setConverterChoosable(boolean converterChoosable);
Expand Down Expand Up @@ -448,4 +455,11 @@ public interface Configuration {
* @param <V> The type of the associated value.
*/
<T, V> V getDefaultValueForClass(Class<T> targetClass);

/**
* Retrieved the Map containing the custom values for classes registered to the current mapping.
*
* @return Map containing custom values per type.
*/
Map<Class<?>, Object> getCustomDefaultValuesMap();
}
21 changes: 18 additions & 3 deletions src/main/java/io/beanmapper/config/CoreConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,8 @@ public void setFlushAfterClear(Trinary flushAfterClear) {
*/
@Override
public <T, V> V getDefaultValueForClass(Class<T> targetClass) {
return this.customDefaultValueMap.containsKey(targetClass)
? (V) this.customDefaultValueMap.get(targetClass)
: DefaultValues.defaultValueFor(targetClass);
Object defaultValue = customDefaultValueMap.get(targetClass);
return defaultValue != null ? (V) defaultValue : DefaultValues.defaultValueFor(targetClass);
}

/**
Expand All @@ -442,4 +441,20 @@ public <T, V> V getDefaultValueForClass(Class<T> targetClass) {
public <T, V> void addCustomDefaultValueForClass(Class<T> targetClass, V value) {
this.customDefaultValueMap.put(targetClass, value);
}

/**
* {@inheritDoc}
*/
@Override
public CollectionHandlerStore getCollectionHandlerStore() {
return this.collectionHandlerStore;
}

/**
* {@inheritDoc}
*/
@Override
public Map<Class<?>, Object> getCustomDefaultValuesMap() {
return customDefaultValueMap;
}
}
Loading

0 comments on commit 173e59e

Please sign in to comment.