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

org.cthul.strings.format.IntMatchResults Maven / Gradle / Ivy

Go to download

Functions for converting strings from and to various formats, such as roman numbers, alpha indices, Java identifiers, and format strings.

The newest version!
package org.cthul.strings.format;

import java.util.*;

/**
 * A {@link MatchResults} where all values are identified by index.
 * @author Arian Treffer
 */
public class IntMatchResults extends MatchResultsBase {
    
    protected final ArrayList intResults = new ArrayList<>();

    @Override
    public void put(int i, Object o) {
        insert(intResults, i, o);
    }
    
    protected final void insert(ArrayList list, int i, Object o) {
        list.ensureCapacity(i+1);
        for (int j = list.size(); j <= i; j++) list.add(null);
        list.set(i, o);
    }

    @Override
    public void put(char c, Object o) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void put(String s, Object o) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Object get(int i) {
        if (i >= intResults.size()) return null;
        return intResults.get(i);
    }

    @Override
    public Object get(char c) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Object get(String s) {
        throw new UnsupportedOperationException();
    }
    
    public List getIntResultList() {
        return complete(intResults);
    }
    
    public Map getIntResultMap() {
        final Map result = new HashMap<>();
        for (int i = 0; i < intResults.size(); i++) {
            result.put(i, complete(intResults.get(i)));
        }
        return result;
    }
    
}