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

com.mindsnacks.zinc.classes.data.ZincManifest Maven / Gradle / Ivy

There is a newer version: 1.6.2
Show newest version
package com.mindsnacks.zinc.classes.data;

import com.google.gson.annotations.SerializedName;

import java.util.*;

/**
 * User: NachoSoto
 * Date: 9/10/13
 */
public class ZincManifest {
    @SerializedName("flavors")
    private final List mFlavors;

    @SerializedName("catalog")
    private final String mIdentifier;

    @SerializedName("version")
    private final int mVersion;

    @SerializedName("bundle")
    private final String mBundleName;

    @SerializedName("files")
    private final Map mFiles;

    public ZincManifest(final List flavors,
                        final String identifier,
                        final int version,
                        final String bundleName, final Map files) {
        mFlavors = flavors;
        mIdentifier = identifier;
        mVersion = version;
        mBundleName = bundleName;
        mFiles = files;
    }

    public List getFlavors() {
        return mFlavors;
    }

    public String getIdentifier() {
        return mIdentifier;
    }

    public int getVersion() {
        return mVersion;
    }

    public String getBundleName() {
        return mBundleName;
    }

    /**
     * @return Map (filename => FileInfo)
     */
    public Map getFilesWithFlavor(final String flavor) {
        final Map result = new HashMap();

        for (final Map.Entry entry : mFiles.entrySet()) {
            final String filename = entry.getKey();
            final FileInfo fileInfo = entry.getValue();

            if (fileInfo.getFlavors().contains(flavor)) {
                result.put(filename, fileInfo);
            }
        }

        return result;
    }

    public static class FileInfo {
        public static final String GZIPPED_FORMAT = "gz";

        @SerializedName("flavors")
        private final Set mFlavors;

        @SerializedName("sha")
        private final String mHash;

        @SerializedName("formats")
        private final Map> mFormats;

        public FileInfo() {
            mFlavors = null;
            mHash = null;
            mFormats = null;
        }

        public FileInfo(final Set flavors, final String hash, final Map> formats) {
            mFlavors = flavors;
            mHash = hash;
            mFormats = formats;
        }

        public Set getFlavors() {
            return mFlavors;
        }

        public String getHash() {
            return mHash;
        }

        public String getHashWithExtension() {
            if (isGzipped()) {
                return getHash() + "." + GZIPPED_FORMAT;
            } else {
                return getHash();
            }
        }

        public boolean isGzipped() {
            return mFormats.containsKey(GZIPPED_FORMAT);
        }

        @Override
        public boolean equals(final Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            return mHash.equals(((FileInfo) o).mHash);
        }

        @Override
        public int hashCode() {
            return mHash.hashCode();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy