Search in sources :

Example 1 with Playlist

use of hr.fer.oop.homework_09.t05.Playlist in project Lectures by FER-OOP.

the class Main method main.

public static void main(String[] args) {
    Playlist p1 = PlaylistDataLoader.createPlaylist();
    Playlist p2 = PlaylistDataLoader.createPlaylist();
    Set<String> words = PlaylistUtil.words(p1, p2);
    System.out.println("Words in songs");
    for (String s : words) {
        System.out.println(s);
    }
    Map<String, Integer> wordsCounts = PlaylistUtil.wordsOccurance(p1);
    System.out.println("Words in songs (occurances):");
    for (var entry : wordsCounts.entrySet()) {
        System.out.println(entry.getKey() + " (" + entry.getValue() + ")");
    }
    Map<Integer, Map<String, Integer>> perLength = PlaylistUtil.perLength(p1);
    System.out.println("Words in songs by words length:");
    for (var lengthEntry : perLength.entrySet()) {
        System.out.print(lengthEntry.getKey() + ": ");
        for (var entry : lengthEntry.getValue().entrySet()) {
            System.out.print(entry.getKey() + " (" + entry.getValue() + ") ");
        }
        System.out.println();
    }
}
Also used : Playlist(hr.fer.oop.homework_09.t05.Playlist)

Example 2 with Playlist

use of hr.fer.oop.homework_09.t05.Playlist in project Lectures by FER-OOP.

the class PlaylistUtil method perLength.

public static Map<Integer, Map<String, Integer>> perLength(Playlist... playlists) {
    Map<Integer, Map<String, Integer>> map = new TreeMap<>();
    for (Playlist playlist : playlists) {
        for (int i = 1, n = playlist.count(); i <= n; i++) {
            String name = playlist.trackAt(i).getName();
            for (String s : name.split(" ")) {
                Map<String, Integer> words = map.get(s.length());
                if (words == null) {
                    words = new HashMap<>();
                    map.put(s.length(), words);
                }
                Integer count = words.getOrDefault(s, 0);
                words.put(s, count + 1);
            }
        }
    }
    return map;
}
Also used : Playlist(hr.fer.oop.homework_09.t05.Playlist)

Example 3 with Playlist

use of hr.fer.oop.homework_09.t05.Playlist in project Lectures by FER-OOP.

the class Main method main.

public static void main(String[] args) {
    Playlist p = PlaylistDataLoader.createPlaylist();
    printPlaylist(p);
    SortedPlaylist sp = new SortedPlaylist("Sorted " + p.getName());
    for (int i = 1, len = p.count(); i <= len; i++) {
        sp.add(p.trackAt(i));
    }
    sp.add(new Track("Seven Drunken Nights", "The Dubliners", 213));
    printPlaylist(sp);
    sp.invert();
    sp.add(new Track("If I Should Fall from Grace with God", "The Pogues", 140));
    printPlaylist(sp);
}
Also used : Playlist(hr.fer.oop.homework_09.t05.Playlist) Track(hr.fer.oop.homework_09.t05.Track)

Example 4 with Playlist

use of hr.fer.oop.homework_09.t05.Playlist in project Lectures by FER-OOP.

the class PlaylistUtil method wordsOccurance.

public static Map<String, Integer> wordsOccurance(Playlist... playlists) {
    Map<String, Integer> map = new TreeMap<>();
    for (Playlist playlist : playlists) {
        for (int i = 1, n = playlist.count(); i <= n; i++) {
            String name = playlist.trackAt(i).getName();
            for (String s : name.split(" ")) {
                Integer count = map.get(s);
                map.put(s, count == null ? 1 : count + 1);
            }
        }
    }
    return map;
}
Also used : Playlist(hr.fer.oop.homework_09.t05.Playlist)

Aggregations

Playlist (hr.fer.oop.homework_09.t05.Playlist)4 Track (hr.fer.oop.homework_09.t05.Track)1