/**
 * Copyright (C) 2012 Ness Computing, Inc.
 *
 * Licensed 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 com.nesscomputing.sequencer;

import java.util.Arrays;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

@Immutable
@JsonDeserialize(as=ImmutableSequencerImpl.class)
public abstract class ImmutableSequencer<K> extends AbstractSequencer<K>
{
    private static final long serialVersionUID = 1L;

    @SafeVarargs
    public static <K> ImmutableSequencer<K> of(K... elements)
    {
        return of(Arrays.asList(elements));
    }

    @Nonnull
    public static <K> ImmutableSequencer<K> of(@Nonnull Iterable<K> iter)
    {
        return new ImmutableSequencerImpl<>(iter);
    }

    @Nonnull
    public static <K> ImmutableSequencer<K> copyOf(@Nonnull Sequencer<K> seq)
    {
        if (seq instanceof ImmutableSequencer) {
            return (ImmutableSequencer<K>) seq;
        }
        return new ImmutableSequencerImpl<>(seq);
    }

    @Override
    public final int sequenceOrAdd(@Nonnull K key)
    {
        throw new UnsupportedOperationException("Immutable sequencers may not be modified");
    }

    @Nonnull
    public ImmutableShadowingSequencerBuilder<K> extendImmutableSequence()
    {
        return new ImmutableShadowingSequencerBuilder<K>(this);
    }

    /**
     * @return the number of Sequencers backing this immutable instance.  Usually 1.
     */
    protected abstract int depth();
}

@@ -1610,32 +1610,108 @@
 ll K key)%0A    %7B%0A
+        int result = sequenceIfExists(key);%0A        if (result == -1) %7B%0A    
         throw ne
@@ -1783,18 +1783,72 @@
 modified
-%22)
+: tried to add %22 + key);%0A        %7D%0A        return result
 ;%0A    %7D%0A

Allow sequenceOrAdd to work on ImmutableSequencer if it's already present