<commit_before>/*
 * Copyright (C) 2010-2014 The MPDroid Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.namelessdev.mpdroid.helpers;

import com.namelessdev.mpdroid.MPDApplication;
import com.namelessdev.mpdroid.R;
import com.namelessdev.mpdroid.tools.Tools;

import org.a0z.mpd.exception.MPDServerException;
import org.a0z.mpd.item.Music;

import android.util.Log;

import java.io.BufferedOutputStream;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class AlbumCache {

    static final boolean GZIP = false;

    private static final String TAG = "AlbumCache";

    protected static AlbumCache sInstance = null;

    protected Map<String, AlbumDetails> mAlbumDetails; // "artist///album" ->

    // list of albumname, artist, albumartist including ""
    protected Set<List<String>> mAlbumSet;

    protected boolean mEnabled = true;

    protected File mFilesDir;

    protected Date mLastUpdate = null;

    protected CachedMPD mMPD;

    protected int mPort;

    protected String mServer;

    // albums that have an albumartist get an empty artist:
    protected Set<List<String>> mUniqueAlbumSet;

    protected AlbumCache(final CachedMPD mpd) {
        super();
        Log.d(TAG, "Starting ...");
        setMPD(mpd);
    }
    // details

    public static String albumCode(final String artist, final String album,
            final boolean isAlbumArtist) {
        return (artist != null ? artist : "") + "//" +
                (isAlbumArtist ? "AA" : "A") +
                "//" + (album != null ? album : "");
    }

    public static AlbumCache getInstance(final CachedMPD mpd) {
        if (sInstance == null) {
            sInstance = new AlbumCache(mpd);
        } else {
            sInstance.setMPD(mpd);
        }
        return sInstance;
    }

    protected static Set<String> getKeysByValue(final Map<String, Set<String>> map,
            final String val) {
        final Set<String> result = new HashSet<>();
        final Set<String> keys = map.keySet();
        for (final String key : keys) {
            final Set<String> values = map.get(key);
            if (val != null && val.isEmpty() || values.contains(val)) {
                result.add(key);
            }
        }
        return result;
    }

    public String cacheInfo() {
        return "AlbumCache: " +
                mAlbumSet.size() + " album/artist combinations, " +
                mUniqueAlbumSet.size() + " unique album/artist combinations, " +
                "Date: " + mLastUpdate;
    }<commit_msg>AlbumCache: Iterator over map using the entry set.<commit_after>/*
 * Copyright (C) 2010-2014 The MPDroid Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.namelessdev.mpdroid.helpers;

import com.namelessdev.mpdroid.MPDApplication;
import com.namelessdev.mpdroid.R;
import com.namelessdev.mpdroid.tools.Tools;

import org.a0z.mpd.exception.MPDServerException;
import org.a0z.mpd.item.Music;

import android.util.Log;

import java.io.BufferedOutputStream;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class AlbumCache {

    static final boolean GZIP = false;

    private static final String TAG = "AlbumCache";

    protected static AlbumCache sInstance = null;

    protected Map<String, AlbumDetails> mAlbumDetails; // "artist///album" ->

    // list of albumname, artist, albumartist including ""
    protected Set<List<String>> mAlbumSet;

    protected boolean mEnabled = true;

    protected File mFilesDir;

    protected Date mLastUpdate = null;

    protected CachedMPD mMPD;

    protected int mPort;

    protected String mServer;

    // albums that have an albumartist get an empty artist:
    protected Set<List<String>> mUniqueAlbumSet;

    protected AlbumCache(final CachedMPD mpd) {
        super();
        Log.d(TAG, "Starting ...");
        setMPD(mpd);
    }
    // details

    public static String albumCode(final String artist, final String album,
            final boolean isAlbumArtist) {
        return (artist != null ? artist : "") + "//" +
                (isAlbumArtist ? "AA" : "A") +
                "//" + (album != null ? album : "");
    }

    public static AlbumCache getInstance(final CachedMPD mpd) {
        if (sInstance == null) {
            sInstance = new AlbumCache(mpd);
        } else {
            sInstance.setMPD(mpd);
        }
        return sInstance;
    }

    protected static Set<String> getKeysByValue(final Map<String, Set<String>> map,
            final String val) {
        final Set<String> result = new HashSet<>();

        for (final Map.Entry<String, Set<String>> stringSetEntry : map.entrySet()) {
            final Set<String> values = stringSetEntry.getValue();
            if (val != null && val.isEmpty() || values.contains(val)) {
                result.add(stringSetEntry.getKey());
            }
        }
        return result;
    }

    public String cacheInfo() {
        return "AlbumCache: " +
                mAlbumSet.size() + " album/artist combinations, " +
                mUniqueAlbumSet.size() + " unique album/artist combinations, " +
                "Date: " + mLastUpdate;
    }
{'fraction_non_alphanumeric': 0.10290309390759166, 'fraction_numerical': 0.003816273681341148, 'mean_word_length': 2.9156883671291354, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7321839', 'n_tokens_mistral': 2157, 'n_tokens_neox': 2076, 'n_words': 618}