From dfcb1cd1bce993a50ef211bc12f81993b215303b Mon Sep 17 00:00:00 2001 From: Adam Gent Date: Thu, 8 Feb 2024 16:42:05 -0500 Subject: [PATCH] Remove PropertyValue and friends --- .../io/jstach/rainbowgum/LogProperties.java | 204 ------------------ 1 file changed, 204 deletions(-) diff --git a/core/src/main/java/io/jstach/rainbowgum/LogProperties.java b/core/src/main/java/io/jstach/rainbowgum/LogProperties.java index c14b9075..9f88711f 100644 --- a/core/src/main/java/io/jstach/rainbowgum/LogProperties.java +++ b/core/src/main/java/io/jstach/rainbowgum/LogProperties.java @@ -814,56 +814,6 @@ private static void validateKeyParameters(String key, Set parameters) { } } - /** - * A lazily retrieved value. - * - * @param value type. - */ - sealed interface Value { - - /** - * Maps a property value to a new property value. - * @param new value type. - * @param mapper function. - * @return new property value. - */ - public Value map(PropertyFunction mapper); - - /** - * Gets the value. - * @return value or null. - */ - public @Nullable T valueOrNull(); - - /** - * Gets a value if there is if not uses the fallback. - * @param fallback maybe null. - * @return value. - */ - default @Nullable T valueOrNull(@Nullable T fallback) { - var v = valueOrNull(); - if (v != null) { - return v; - } - return fallback; - } - - /** - * Gets the value and will fail with {@link NoSuchElementException} if there is no - * value. - * @return value. - * @throws NoSuchElementException if there is no value. - */ - public T value() throws NoSuchElementException; - - /** - * Append description of value. - * @param sb appended to. - */ - public void describe(StringBuilder sb); - - } - /** * The result of a property fetched from properties. * @@ -1046,160 +996,6 @@ sealed interface RequiredResult extends Result { } - /** - * Multiple properties tried in order. - * - * @param property type. - * @param propertyValues property values - */ - record PropertiesValue(List> propertyValues) implements Value { - - @Override - public Value map(PropertyFunction mapper) { - - List> values = new ArrayList<>(); - for (var v : propertyValues) { - values.add(v.map(mapper)); - } - return new PropertiesValue<>(values); - } - - @Override - public @Nullable T valueOrNull() { - for (var pv : propertyValues) { - var v = pv.valueOrNull(); - if (v != null) { - return v; - } - } - return null; - } - - @Override - public T value() throws NoSuchElementException { - var t = valueOrNull(); - if (t != null) { - return t; - } - StringBuilder error = new StringBuilder(); - error.append("Property not found for: "); - describe(error); - throw new NoSuchElementException(error.toString()); - } - - @Override - public void describe(StringBuilder sb) { - for (var v : propertyValues) { - v.describe(sb); - sb.append(", "); - } - } - - } - - /** - * A property value is a property and its lazily retrieved value. - * - * @param value type. - * @param property backing property. - * @param properties the log properties instance. - */ - record PropertyValue(Property property, LogProperties properties) implements Value { - /** - * Maps a property value to a new property value. - * @param new value type. - * @param mapper function. - * @return new property value. - */ - public PropertyValue map(PropertyFunction mapper) { - return new PropertyValue<>(property.map(mapper), properties); - } - - /** - * Gets the value. - * @return value or null. - */ - public @Nullable T valueOrNull() { - return result().valueOrNull(); - } - - private Result result() { - return property.get(properties); - } - - /** - * Gets a value if there if not uses the fallback. - * @param fallback maybe null. - * @return value. - */ - public @Nullable T valueOrNull(@Nullable T fallback) { - var v = valueOrNull(); - if (v != null) { - return v; - } - return fallback; - } - - /** - * Convenience that turns a value into an optional. - * @return optional. - */ - public Optional optional() { - return Optional.ofNullable(valueOrNull()); - } - - /** - * Gets the value and will fail with {@link NoSuchElementException} if there is no - * value. - * @return value. - * @throws NoSuchElementException if there is no value. - */ - public T value() throws NoSuchElementException { - return result().value(); - } - - /** - * Gets a value if there if not uses the fallback if not null otherwise throws an - * exception. - * @param fallback maybe null. - * @return value. - * @throws NoSuchElementException if no property and fallback is - * null. - */ - public T value(@Nullable T fallback) throws NoSuchElementException { - return result().value(fallback); - } - - /** - * Gets a value if there if not uses the fallback if not null otherwise throws an - * exception. - * @param fallback maybe null. - * @return value. - * @throws NoSuchElementException if no property and fallback is - * null. - */ - public T value(@SuppressWarnings("exports") Supplier fallback) - throws NoSuchElementException { - return result().value(fallback); - } - - /** - * Set a property if its not null. - * @param consumer first parameter is first key and second parameter is non null - * value. - */ - public void set(BiConsumer consumer) { - T value = valueOrNull(); - if (value != null) { - consumer.accept(property.key(), value); - } - } - - public void describe(StringBuilder b) { - b.append(property); - } - } - /** * A property description. *