private static <T> Object register(ConcurrentMap<MeterIdPrefix, Object> map,
                                       RegistrationState registrationState,
                                       MeterRegistry registry, MeterIdPrefix idPrefix, Class<T> type,
                                       BiFunction<MeterRegistry, MeterIdPrefix, T> factory) {

        final Object object = map.computeIfAbsent(idPrefix, i -> {
            registrationState.isRegistering = true;
            try {
                return factory.apply(registry, i);
            } finally {
                registrationState.isRegistering = false;
            }
        });

        if (!type.isInstance(object)) {
            throw new IllegalStateException(
                    "An object of different type has been registered already for idPrefix: " + idPrefix +
                    " (expected: " + type.getName() +
                    ", actual: " + (object != null ? object.getClass().getName() : "null") + ')');
        }
        return object;
    }
Associates a newly-created object with the specified {@link MeterIdPrefix} or returns an existing one if
exists already.

@param idPrefix the {@link MeterIdPrefix} of the object
@param type the type of the object created by {@code factory}
@param factory a factory that creates an object of {@code type}, to be associated with {@code idPrefix}

@return the object of {@code type}, which may or may not be created by {@code factory}
@throws IllegalStateException if there is already an object of different class associated
                              for the same {@link MeterIdPrefix}
core/src/main/java/com/linecorp/armeria/internal/common/metric/MicrometerUtil.java