/** * Get the method as the annotated element. * * @return the underlying method instance. */ @Override default Method getAnnotatedElement() { return getMember(); }
/** * Create a new instance of {@code DefaultPropertiesReader} with the given properties. * * @param properties the underlying properties map * @return a new instance of {@code DefaultPropertiesReader} */ public static PropertiesReader of(Map<String, Object> properties) { return new DefaultPropertiesReader(properties); }
/** * Get the field as the annotated element. * * @return the underlying field instance. */ @Override default Field getAnnotatedElement() { return getMember(); }
/** * Determine if the member is annotated with {@link Fake}, {@link Virtual}, or {@link Real} * annotation. * * @return true if the member is injectable, false otherwise */ default Boolean isInjectable() { return getFake().isPresent() || getReal().isPresent() || getVirtual().isPresent(); }
/** * Determine if the type is a supertype of the given type. * * @param type the super type * @return true if type is a supertype of the given type, false otherwise */ default Boolean isSupertypeOf(Type type) { boolean result = TypeToken.of(getGenericType()).isSupertypeOf(type); return result ? result : TypeToken.of(getType()).isSupertypeOf(type); }
/** * <p> * Get a PropertiesReader instance for the given mapKey. Note that: * </p> * <ul> * <li>If the key is empty then the this PropertiesReader instance will be returned</li> * <li>If the key is not found then an empty map will be returned</li> * </ul> * @param key the key associated with the map * @return an instance that wraps the found map */ default PropertiesReader getPropertiesReader(String key) { if (key.isEmpty()) { return this; } return DefaultPropertiesReader.of(findMap(key)); }
/** * Determine if the member is annotated with {@link Fake} or {@link Virtual} annotation. * * @return true if the member is a mock, false otherwise */ default Boolean isMock() { return getFake().isPresent() || getVirtual().isPresent(); }
/** * Get the name of the class the member is declared in. * * @return the member declaring class name. */ default String getDeclaringClassName() { return getDeclaringClass().getSimpleName(); }
/** * Get the type's class loader. * * @return the type's class loader. */ default ClassLoader getClassLoader() { return getType().getClassLoader(); }
/** * Get the member name. * * @return the member name. */ default String getName() { return getMember().getName(); }
/** * Add the given key/value pair if it is absent. * * @param <T> the value type * @param key the key * @param value the value * @return this object */ default <T> PropertiesWriter addProperty(String key, T value) { Map<String, T> properties = getProperties(); properties.computeIfAbsent(key, p -> value); return this; }
/** * Determine if the map returned by {@link #getProperties() } * contains key-value mappings. * * @return true if properties contains no key-value mapping, false otherwise */ default Boolean isEmpty() { return getProperties().isEmpty(); }
/** * Get the value the value associated with the given key. * * @param <T> the value type * @param key the key * @return the value to which the specified key is mapped, null otherwise */ default <T> T getProperty(String key) { return (T) getProperties().get(key); }
/** * Method return type. * * @return the method return type */ default Class<?> getReturnType() { return getAnnotatedElement().getReturnType(); }
/** * Get {@link Virtual} annotation. * * @return optional with virtual annotation, empty optional otherwise */ default Optional<Virtual> getVirtual() { return ofNullable(getMember().getDeclaredAnnotation(Virtual.class)); }
/** * Determine if the type is a subtype of the given type. * * @param type the subtype * @return true if type is a subtype of the given type, false otherwise */ default Boolean isSubtypeOf(Type type) { boolean result = TypeToken.of(getGenericType()).isSubtypeOf(type); return result ? result : TypeToken.of(getType()).isSubtypeOf(type); }
/** * Get the member's declaring class' classloader. * * @return the declaring class' classloader. */ default ClassLoader getDeclaringClassLoader() { return getDeclaringClass().getClassLoader(); }
/** * Get human readable type name. * * @return the type name. */ default String getTypeName() { return getType().getSimpleName(); }
/** * Get the class the member is declared in. * * @return the member declaring class. */ default Class<?> getDeclaringClass() { return getMember().getDeclaringClass(); }
/** * If the specified key is not already associated with a value (or is mapped to null), * attempts to compute its value using the given mapping function and enters it into this * map unless null. * * @param <T> the value type * @param key the key with which the specified value is to be associated * @param mappingFunction the function to compute a value * @return the current (existing or computed) value associated with the specified key */ default <T> T computeIfAbsent(String key, Function<String, T> mappingFunction) { Map<String, T> properties = getProperties(); return properties.computeIfAbsent(key, mappingFunction); }