Skip to content

Commit dfc585d

Browse files
committed
refactoring
1 parent f4f9b2b commit dfc585d

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

jbbp/src/main/java/com/igormaznitsa/jbbp/mapper/JBBPMapper.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@
3939
public final class JBBPMapper {
4040

4141
public static final String MAKE_CLASS_INSTANCE_METHOD_NAME = "newInstance";
42-
43-
private static final Map<Class<?>, List<MappedFieldRecord>> CACHED_FIELDS = new ConcurrentHashMap<>();
44-
4542
/**
4643
* Flag to not throw exception if structure doesn't have value for a field.
4744
*
4845
* @since 1.1
4946
*/
5047
public static final int FLAG_IGNORE_MISSING_VALUES = 1;
48+
private static final Map<Class<?>, List<MappedFieldRecord>> CACHED_FIELDS = new ConcurrentHashMap<>();
49+
5150
/**
5251
* Create a class instance, map binary data of a structure for its path to its
5352
* fields and return the instance.
@@ -282,6 +281,25 @@ public static <T> T map(final JBBPFieldStruct rootStructure, final T instance, f
282281
return instance;
283282
}
284283

284+
/**
285+
* Get current number of classes which fields are cached in internal field cache.
286+
*
287+
* @return number of classes
288+
* @since 2.0.0
289+
*/
290+
public static int getClassCacheSize() {
291+
return CACHED_FIELDS.size();
292+
}
293+
294+
/**
295+
* Clear internal class field cache.
296+
*
297+
* @since 2.0.0
298+
*/
299+
public static void clearClassCache() {
300+
CACHED_FIELDS.clear();
301+
}
302+
285303
private static List<MappedFieldRecord> makeListOfRecords(final Object instance) {
286304
final Class<?> mappingClass = instance.getClass();
287305

0 commit comments

Comments
 (0)