/* This file is part of SableCC ( http://sablecc.org ).
 * 
 * See the NOTICE file distributed with this work for copyright information.
 *
 * 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 org.sablecc.sablecc.alphabet;

import java.util.SortedMap;
import java.util.SortedSet;

import org.sablecc.sablecc.exception.InternalException;

public class AlphabetMergeResult<T extends Comparable<? super T>> {

    private final Alphabet<T> newAlphabet;

    private final Alphabet<T> oldAlphabet1;

    private final SortedMap<Symbol<T>, SortedSet<Symbol<T>>> oldAlphabet1SymbolMap;

    private final Alphabet<T> oldAlphabet2;

    private final SortedMap<Symbol<T>, SortedSet<Symbol<T>>> oldAlphabet2SymbolMap;

    AlphabetMergeResult(
            Alphabet<T> newAlphabet,
            Alphabet<T> oldAlphabet1,
            SortedMap<Symbol<T>, SortedSet<Symbol<T>>> oldAlphabet1SymbolMap,
            Alphabet<T> oldAlphabet2,
            SortedMap<Symbol<T>, SortedSet<Symbol<T>>> oldAlphabet2SymbolMap) {

        this.newAlphabet = newAlphabet;

        this.oldAlphabet1 = oldAlphabet1;
        this.oldAlphabet1SymbolMap = oldAlphabet1SymbolMap;

        this.oldAlphabet2 = oldAlphabet2;
        this.oldAlphabet2SymbolMap = oldAlphabet2SymbolMap;
    }

    public Alphabet<T> getNewAlphabet() {

        return this.newAlphabet;
    }

    public SortedMap<Symbol<T>, SortedSet<Symbol<T>>> getSymbolMap(
            Alphabet<T> alphabet) {

        if (alphabet == this.oldAlphabet1) {
            return this.oldAlphabet1SymbolMap;
        }

        if (alphabet == this.oldAlphabet2) {
            return this.oldAlphabet2SymbolMap;
        }

        throw new InternalException("invalid alphabet");
    }
}

@@ -1865,27 +1865,27 @@
 ublic Sorted
-Map
+Set
 %3CSymbol%3CT%3E, 
@@ -1886,81 +1886,508 @@
 l%3CT%3E
-, SortedSet%3CSymbol%3CT%3E%3E%3E getSymbolMap(%0A            Alphabet%3CT%3E alphabet) %7B
+%3E getNewSymbols(%0A            Symbol%3CT%3E oldSymbol,%0A            Alphabet%3CT%3E oldAlphabet) %7B%0A%0A        if (oldSymbol == null) %7B%0A            throw new InternalException(%22oldSymbol may not be null%22);%0A        %7D%0A%0A        if (oldAlphabet == null) %7B%0A            throw new InternalException(%22oldAlphabet may not be null%22);%0A        %7D%0A%0A        if (!oldAlphabet.getSymbols().contains(oldSymbol)) %7B%0A            throw new InternalException(%0A                    %22oldSymbol is not an element of oldAlphabet%22);%0A        %7D
 %0A%0A  
@@ -2388,33 +2388,36 @@
  %7D%0A%0A        if (
-a
+oldA
 lphabet == this.
@@ -2469,32 +2469,47 @@
 phabet1SymbolMap
+.get(oldSymbol)
 ;%0A        %7D%0A%0A   
@@ -2517,17 +2517,20 @@
     if (
-a
+oldA
 lphabet 
@@ -2594,24 +2594,39 @@
 et2SymbolMap
+.get(oldSymbol)
 ;%0A        %7D%0A

Improve the AlphabetMergeResult class.