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

com.mindsnacks.zinc.classes.data.ZincCatalog 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 com.mindsnacks.zinc.exceptions.ZincException;

import java.util.Map;

/**
 * User: NachoSoto
 * Date: 9/3/13
 */
public class ZincCatalog {
    @SerializedName("id")
    private final String mIdentifier;

    @SerializedName("bundles")
    private final Map mBundles;

    public ZincCatalog(final String identifier, final Map bundles) {
        mIdentifier = identifier;
        mBundles = bundles;
    }

    public String getIdentifier() {
        return mIdentifier;
    }

    public int getVersionForBundleName(final String bundleName, final String distribution) throws DistributionNotFoundException {
        try {
            return mBundles.get(bundleName).getVersionForDistribution(distribution);
        } catch (DistributionNotFoundException e) {
            throw new DistributionNotFoundException(distribution, bundleName);
        } catch (NullPointerException e) {
            throw new DistributionNotFoundException(distribution, bundleName);
        }
    }

    @Override
    public String toString() {
        return "ZincCatalog {" +
                " identifier = '" + mIdentifier + '\'' +
                ", bundles = " + mBundles +
                '}';
    }

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

        final ZincCatalog that = (ZincCatalog)o;

        return mBundles.equals(that.mBundles) && mIdentifier.equals(that.mIdentifier);

    }

    public static class Info {
        @SerializedName("distributions")
        private final Map mDistributions;

        public Info(final Map distributions) {
            mDistributions = distributions;
        }

        public int getVersionForDistribution(String distribution) throws DistributionNotFoundException {
            if (mDistributions.containsKey(distribution)) {
                return mDistributions.get(distribution);
            } else {
                throw new DistributionNotFoundException(distribution);
            }
        }

        @Override
        public String toString() {
            return "Info {" +
                    "distributions = " + mDistributions +
                    '}';
        }

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

            return mDistributions.equals(((Info)o).mDistributions);
        }
    }

    public static class DistributionNotFoundException extends ZincException {
        public DistributionNotFoundException(final String distribution) {
            super(String.format("Distribution '%s' not found", distribution));
        }

        public DistributionNotFoundException(final String distribution, final String bundleName) {
            super(String.format("Distribution '%s' not found in bundle '%s'", distribution, bundleName));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy