<commit_before>/**! -*- Mode: Java; c-basic-offset: 4 -*-
 *
 * Copyright (c) 1999 by <NAME> <<EMAIL>>
 *
 */
package nu.dll.lyskom;

import java.util.Hashtable;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;

/**

              Text-Mapping ::=
                    ( range-begin           :    Local-Text-No;
                      range-end             :    Local-Text-No;
                      later-texts-exists    :    BOOL;
                      block                 :    Local-To-Global-Block;
                    )

              Local-To-Global-Block ::= SELECTION
                    ( 0=sparse sparse-block :   ARRAY Text-Number-Pair;
                      1=dense  dense-block  :   Text-List;
                    )

              Text-Number-Pair ::=
                    ( local-number          :   Local-Text-No;
                      global-number         :   Text-No;
                    )
**/

/**
 * This class handles storage of global text numbers for one conference.
 */
public class TextMapping implements Enumeration {
    public final static int DEBUG = 4;
    Hashtable hash = new Hashtable();
    int enumc = 0;
    List list = new LinkedList();
    //int[] list;

    public int localToGlobal(int n) {
	Integer i = (Integer) hash.get((Object) new Integer(n));
	if (i == null)
	    return -1;
	return i.intValue();
    }

    public int globalToLocal(int n) {
	Debug.println("TextMapping.globalToLocal(" + n + ")");
	Enumeration e = hash.keys();
	while (e.hasMoreElements()) {
	    Integer localNo = (Integer) e.nextElement();
	    Integer globalNo = (Integer) hash.get(localNo);
	    if (localNo.equals(globalNo))
		return localNo.intValue();
	}
	Debug.println("TextMapping.globalToLocal(" + n + "): nothing found");
	return -1;
    }
    /**
     * Move the "cursor" to the beginning of the list of pairs
     * (similarly to java.sql.ResultSet.first()
     *
     * I thought that I needed this method, but on second thought, I
     * didn't. Maybe it'll come in handy later.
     */
    public void first() {
	enumc = 0;
    }
    public boolean hasMoreElements() {
	return list != null && enumc < list.size();
    }
    /**
     * Returns the next Global number
     */
    public Object nextElement() {
	if (enumc > list.size()) {
	    Debug.println("no such element, enum=" + enumc);
	    return null;
	}
	Debug.println("returning " + localToGlobal(((Integer) list.get(enumc)).intValue()) + "/" +
		      ((Integer) list.get(enumc)).intValue() + " - " + enumc);
	return list != null ? (Object) new Integer(localToGlobal(((Integer)
								  list.get(enumc++)).intValue())) : null;<commit_msg>fixed [ 594972 ] off-by-one i TextMapping<commit_after>/**! -*- Mode: Java; c-basic-offset: 4 -*-
 *
 * Copyright (c) 1999 by <NAME> <<EMAIL>>
 *
 */
package nu.dll.lyskom;

import java.util.Hashtable;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;

/**

              Text-Mapping ::=
                    ( range-begin           :    Local-Text-No;
                      range-end             :    Local-Text-No;
                      later-texts-exists    :    BOOL;
                      block                 :    Local-To-Global-Block;
                    )

              Local-To-Global-Block ::= SELECTION
                    ( 0=sparse sparse-block :   ARRAY Text-Number-Pair;
                      1=dense  dense-block  :   Text-List;
                    )

              Text-Number-Pair ::=
                    ( local-number          :   Local-Text-No;
                      global-number         :   Text-No;
                    )
**/

/**
 * This class handles storage of global text numbers for one conference.
 */
public class TextMapping implements Enumeration {
    public final static int DEBUG = 4;
    Hashtable hash = new Hashtable();
    int enumc = 0;
    List list = new LinkedList();
    //int[] list;

    public int localToGlobal(int n) {
	Integer i = (Integer) hash.get((Object) new Integer(n));
	if (i == null)
	    return -1;
	return i.intValue();
    }

    public int globalToLocal(int n) {
	Debug.println("TextMapping.globalToLocal(" + n + ")");
	Enumeration e = hash.keys();
	while (e.hasMoreElements()) {
	    Integer localNo = (Integer) e.nextElement();
	    Integer globalNo = (Integer) hash.get(localNo);
	    if (localNo.equals(globalNo))
		return localNo.intValue();
	}
	Debug.println("TextMapping.globalToLocal(" + n + "): nothing found");
	return -1;
    }
    /**
     * Move the "cursor" to the beginning of the list of pairs
     * (similarly to java.sql.ResultSet.first()
     *
     * I thought that I needed this method, but on second thought, I
     * didn't. Maybe it'll come in handy later.
     */
    public void first() {
	enumc = 0;
    }
    public boolean hasMoreElements() {
	return list != null && enumc < list.size();
    }
    /**
     * Returns the next Global number
     */
    public Object nextElement() {
	if (enumc >= list.size()) {
	    Debug.println("no such element, enum=" + enumc);
	    return null;
	}
	Debug.println("returning " + localToGlobal(((Integer) list.get(enumc)).intValue()) + "/" +
		      ((Integer) list.get(enumc)).intValue() + " - " + enumc);
	return list != null ? (Object) new Integer(localToGlobal(((Integer)
								  list.get(enumc++)).intValue())) : null;
{'fraction_non_alphanumeric': 0.13633813353282215, 'fraction_numerical': 0.005610622779128483, 'mean_word_length': 1.9240021869874249, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6250180', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1572, 'n_words': 409}