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

io.virtdata.basicsmappers.from_long.to_int.HashedLineToInt Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package io.virtdata.basicsmappers.from_long.to_int;

import io.virtdata.annotations.ThreadSafeMapper;
import io.virtdata.util.ResourceFinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.function.LongToIntFunction;

@ThreadSafeMapper
public class HashedLineToInt implements LongToIntFunction {
    private final static Logger logger = LoggerFactory.getLogger(HashedLineToInt.class);

    private final List lines;
    private final String filename;
    private final Hash intHash;

    public HashedLineToInt(String filename) {
        this.filename = filename;
        this.lines = ResourceFinder.readDataFileLines(filename);
        this.intHash = new Hash();
    }

    public String toString() {
        return getClass().getSimpleName() + ":" + filename;
    }

    @Override
    public int applyAsInt(long value) {
        int itemIdx = intHash.applyAsInt(value) % lines.size();
        String item = lines.get(itemIdx);
        return Integer.valueOf(item);
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy