All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zalando.nakadiproducer.eventlog.CompactionKeyExtractors Maven / Gradle / Ivy

There is a newer version: 30.0.0-RC1
Show newest version
package org.zalando.nakadiproducer.eventlog;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;
import java.util.function.Function;

/**
 * This class contains implementations of {@link CompactionKeyExtractor} used by the factory methods in that interface.
 */
final class CompactionKeyExtractors {

    @AllArgsConstructor(access = AccessLevel.PACKAGE)
    static class SimpleCompactionKeyExtractor implements CompactionKeyExtractor {
        @Getter
        private final String eventType;
        private final Function> extractorFunction;

        @Override
        public Optional tryGetKeyFor(Object o) {
            return extractorFunction.apply(o);
        }
    }

    @AllArgsConstructor(access = AccessLevel.PACKAGE)
    static class TypedCompactionKeyExtractor implements CompactionKeyExtractor {
        @Getter
        private final String eventType;
        private final Class type;
        private final Function extractorFunction;

        @Override
        public Optional tryGetKeyFor(Object o) {
            if(type.isInstance(o)) {
                return Optional.of(extractorFunction.apply(type.cast(o)));
            } else {
                return Optional.empty();
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy