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

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

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

import angry1980.audio.model.Track;

import java.util.*;
import java.util.stream.Collectors;

public class TrackDAOInMemoryImpl implements TrackDAO{

    private Map tracks;

    public TrackDAOInMemoryImpl(){
        this.tracks = new HashMap<>();
    }

    @Override
    public Track tryToGet(long id) {
        return tracks.get(id);
    }

    @Override
    public Collection findByCluster(long cluster) {
        if(cluster == 0){
            return tryToGetAll();
        }
        return tracks.values().stream()
                .filter(track -> track.getCluster() == cluster)
                .collect(Collectors.toList());
    }

    @Override
    public Collection tryToGetAll() {
        return tracks.values();
    }

    @Override
    public Track tryToCreate(Track track) {
        tracks.put(track.getId(), track);
        return track;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy