/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.component.reactive.streams;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;

/**
 * A list of possible backpressure strategy to use when the emission of upstream items cannot respect backpressure.
 */
public enum ReactiveStreamsBackpressureStrategy {

    /**
     * Buffers <em>all</em> onNext values until the downstream consumes it.
     */
    BUFFER {
        @Override
        public <T> Collection<T> update(Deque<T> buffer, T element) {
            buffer.addLast(element);
            return Collections.emptySet();
        }
    },

    /**
     * Drops the most recent onNext value if the downstream can't keep up.
     */
    DROP {
        @Override
        public <T> Collection<T> update(Deque<T> buffer, T element) {
            if (buffer.size() > 0) {
                return Arrays.asList(element);
            } else {
                buffer.addLast(element);
                return Collections.emptySet();
            }
        }
    },

    /**
     * Keeps only the latest onNext value, overwriting any previous value if the
     * downstream can't keep up.
     */
    LATEST {
        @Override
        public <T> Collection<T> update(Deque<T> buffer, T element) {
            Collection<T> discarded = Collections.emptySet();
            if (buffer.size() > 0) {
                discarded = Arrays.asList(buffer.removeFirst());
            }

            buffer.addLast(element);
            return discarded;
        }
    };


    /**
     * Updates the buffer and returns a list of discarded elements (if any).
     *
     * @param buffer the buffer to update
     * @param element the elment that should possibly be inserted
     * @param <T> the generic type of the element
     * @return the list of discarded elements
     */
    public abstract <T> Collection<T> update(Deque<T> buffer, T element);

}

@@ -855,33 +855,8 @@
 s;%0A%0A
-import java.util.Arrays;%0A
 impo
@@ -880,16 +880,16 @@
 ection;%0A
+
 import j
@@ -1651,25 +1651,37 @@
  return 
-Arrays.as
+Collections.singleton
 List(ele
@@ -2190,17 +2190,535 @@
 d = 
-Arrays.as
+Collections.singletonList(buffer.removeLast());%0A            %7D%0A%0A            buffer.addLast(element);%0A            return discarded;%0A        %7D%0A    %7D,%0A%0A    /**%0A     * Keeps only the oldest onNext value, overwriting any previous value if the%0A     * downstream can't keep up.%0A     */%0A    OLDEST %7B%0A        @Override%0A        public %3CT%3E Collection%3CT%3E update(Deque%3CT%3E buffer, T element) %7B%0A            Collection%3CT%3E discarded = Collections.emptySet();%0A            if (buffer.size() %3E 0) %7B%0A                discarded = Collections.singleton
 List
@@ -2841,17 +2841,16 @@
     %7D;%0A%0A
-%0A
     /**%0A

Fix latest strategy which was mistakenly acting as oldest.