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

angry1980.audio.dao.TrackHashDAOInMemoryImpl Maven / Gradle / Ivy

There is a newer version: 0.0.10
Show newest version
package angry1980.audio.dao;

import angry1980.audio.model.TrackHash;

import java.util.*;

public class TrackHashDAOInMemoryImpl implements TrackHashDAO {

    private long mask;
    private Map> index;

    public TrackHashDAOInMemoryImpl(){
        this(-1);
    }

    public TrackHashDAOInMemoryImpl(long mask){
        this.index = new HashMap<>();
        this.mask = mask;
    }

    @Override
    public Optional create(TrackHash hash) {
        if(hash != null){
            index.computeIfAbsent(hash.getHash() & mask, l -> new ArrayList()).add(hash);
        }
        return Optional.ofNullable(hash);
    }

    @Override
    public List findByHash(long hash) {
        return index.getOrDefault(hash & mask, Collections.emptyList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy