001/** 002 * The MIT License (MIT) 003 * 004 * Copyright (c) 2019 nobark (tools4j), Marco Terzer, Anton Anufriev 005 * 006 * Permission is hereby granted, free of charge, to any person obtaining a copy 007 * of this software and associated documentation files (the "Software"), to deal 008 * in the Software without restriction, including without limitation the rights 009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 010 * copies of the Software, and to permit persons to whom the Software is 011 * furnished to do so, subject to the following conditions: 012 * 013 * The above copyright notice and this permission notice shall be included in all 014 * copies or substantial portions of the Software. 015 * 016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 022 * SOFTWARE. 023 */ 024package org.tools4j.nobark.queue; 025 026/** 027 * Merger strategy passed to some conflation queues upon construction to support merging of values when conflation 028 * occurs. 029 * 030 * @param <K> the type of the conflation key 031 * @param <V> the type of values in the queue 032 */ 033@FunctionalInterface 034public interface Merger<K,V> { 035 /** 036 * Method called to merge two values; the merged value is returned. 037 * 038 * @param conflationKey the conflation key 039 * @param olderValue the older value that was already present in the queue 040 * @param newValue the newer value that is currently being added to the queue 041 * @return the merged value; can be {@code newValue} itself but should not be {@code olderValue} as this instance 042 * is returned by the enqueue method and may be reused by the producer 043 */ 044 V merge(K conflationKey, V olderValue, V newValue); 045}