Cache field order per-class. @return (cached) ordered list of fields
()
| 1062 | * @return (cached) ordered list of fields |
| 1063 | */ |
| 1064 | private List<String> fieldOrder() { |
| 1065 | Class<?> clazz = getClass(); |
| 1066 | // Try to read the value under the read lock |
| 1067 | cacheStructureLock.readLock().lock(); |
| 1068 | try { |
| 1069 | List<String> order = fieldOrder.get(clazz); |
| 1070 | if (order != null) { |
| 1071 | return order; // Return the cached result if found |
| 1072 | } |
| 1073 | } finally { |
| 1074 | cacheStructureLock.readLock().unlock(); |
| 1075 | } |
| 1076 | |
| 1077 | // If not found, compute the value under the write lock |
| 1078 | cacheStructureLock.writeLock().lock(); |
| 1079 | try { |
| 1080 | // Double-check if another thread has computed the value before we do (see JavaDoc) |
| 1081 | return fieldOrder.computeIfAbsent(clazz, (c) -> getFieldOrder()); |
| 1082 | } finally { |
| 1083 | cacheStructureLock.writeLock().unlock(); |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | public static List<String> createFieldsOrder(List<String> baseFields, String ... extraFields) { |
| 1088 | return createFieldsOrder(baseFields, Arrays.asList(extraFields)); |
no test coverage detected