001/*
002 * #%L
003 * Netarchivesuite - harvester
004 * %%
005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library,
006 *             the National Library of France and the Austrian National Library.
007 * %%
008 * This program is free software: you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation, either version 2.1 of the
011 * License, or (at your option) any later version.
012 * 
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Lesser Public License for more details.
017 * 
018 * You should have received a copy of the GNU General Lesser Public
019 * License along with this program.  If not, see
020 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
021 * #L%
022 */
023package dk.netarkivet.harvester.datamodel;
024
025import dk.netarkivet.common.exceptions.ArgumentNotValid;
026
027/**
028 * Sparse version for DomainConfiguration class. To be used for GUI purposes only. Immutable.
029 *
030 * @see dk.netarkivet.harvester.datamodel.DomainConfiguration
031 */
032public class SparseDomainConfiguration {
033    /** Name of domain this is a configuration for. */
034    private final String domainName;
035    /** Name of this configuration. */
036    private final String configurationName;
037
038    /**
039     * Create a sparse configuration.
040     *
041     * @param domainName Name of domain this is a configuration for.
042     * @param configurationName Name of configuration.
043     * @throws ArgumentNotValid if either argument is null or empty.
044     */
045    public SparseDomainConfiguration(String domainName, String configurationName) {
046        ArgumentNotValid.checkNotNullOrEmpty(domainName, "domainName");
047        ArgumentNotValid.checkNotNullOrEmpty(configurationName, "configurationName");
048        this.domainName = domainName;
049        this.configurationName = configurationName;
050    }
051
052    /**
053     * Alternate constructor taking a DomainConfiguration as input.
054     *
055     * @param dc a DomainConfiguration
056     */
057    public SparseDomainConfiguration(DomainConfiguration dc) {
058        ArgumentNotValid.checkNotNull(dc, "DomainConfiguration dc");
059        this.domainName = dc.getDomainName();
060        this.configurationName = dc.getName();
061    }
062
063    /**
064     * Get domain name.
065     *
066     * @return The domain name.
067     */
068    public String getDomainName() {
069        return this.domainName;
070    }
071
072    /**
073     * Get configuration name.
074     *
075     * @return The configuration name.
076     */
077    public String getConfigurationName() {
078        return this.configurationName;
079    }
080
081    public boolean equals(Object o) {
082        if (this == o) {
083            return true;
084        }
085        if (!(o instanceof SparseDomainConfiguration)) {
086            return false;
087        }
088
089        final SparseDomainConfiguration configKey = (SparseDomainConfiguration) o;
090
091        if (!configurationName.equals(configKey.getConfigurationName())) {
092            return false;
093        }
094        if (!domainName.equals(configKey.getDomainName())) {
095            return false;
096        }
097
098        return true;
099    }
100
101    public int hashCode() {
102        int result;
103        result = domainName.hashCode();
104        result = 29 * result + configurationName.hashCode();
105        return result;
106    }
107
108}