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

com.jogamp.gluegen.cgram.PreprocessorInfoChannel Maven / Gradle / Ivy

There is a newer version: 2.3.2
Show newest version
package com.jogamp.gluegen.cgram;

import java.util.*;

public class PreprocessorInfoChannel
{
    Hashtable> lineLists = new Hashtable>(); // indexed by Token number
    int firstValidTokenNumber = 0;
    int maxTokenNumber = 0;

    public void addLineForTokenNumber( final Object line, final Integer toknum )
    {
        if ( lineLists.containsKey( toknum ) ) {
            final Vector lines = lineLists.get( toknum );
            lines.addElement(line);
        }
        else {
            final Vector lines = new Vector();
            lines.addElement(line);
            lineLists.put(toknum, lines);
            if ( maxTokenNumber < toknum.intValue() ) {
                maxTokenNumber = toknum.intValue();
            }
        }
    }

    public int getMaxTokenNumber()
    {
        return maxTokenNumber;
    }

    public Vector extractLinesPrecedingTokenNumber( final Integer toknum )
    {
        final Vector lines = new Vector();
        if (toknum == null) return lines;
        for (int i = firstValidTokenNumber; i < toknum.intValue(); i++){
            final Integer inti = new Integer(i);
            if ( lineLists.containsKey( inti ) ) {
                final Vector tokenLineVector = lineLists.get( inti );
                if ( tokenLineVector != null) {
                    final Enumeration tokenLines = tokenLineVector.elements();
                    while ( tokenLines.hasMoreElements() ) {
                        lines.addElement( tokenLines.nextElement() );
                    }
                    lineLists.remove(inti);
                }
            }
        }
        firstValidTokenNumber = toknum.intValue();
        return lines;
    }

    @Override
    public String toString()
    {
        final StringBuilder sb = new StringBuilder("PreprocessorInfoChannel:\n");
        for (int i = 0; i <= maxTokenNumber + 1; i++){
            final Integer inti = new Integer(i);
            if ( lineLists.containsKey( inti ) ) {
                final Vector tokenLineVector = lineLists.get( inti );
                if ( tokenLineVector != null) {
                    final Enumeration tokenLines = tokenLineVector.elements();
                    while ( tokenLines.hasMoreElements() ) {
                        sb.append(inti + ":" + tokenLines.nextElement() + '\n');
                    }
                }
            }
        }
        return sb.toString();
    }
}