/**
* Copyright (c) 2009--2014 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package com.redhat.rhn.domain.channel;
import com.redhat.rhn.domain.BaseDomainHelper;
import com.redhat.rhn.domain.common.ArchType;
import com.redhat.rhn.domain.rhnpackage.PackageArch;
import com.redhat.rhn.domain.server.ServerArch;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import java.util.Set;
/**
* ChannelArch
* @version $Rev$
*/
public class ChannelArch extends BaseDomainHelper {
private Long id;
private String label;
private String name;
private ArchType archType;
private Set compatibleServerArches;
private Set compatiblePackageArches;
/**
* @return Returns the archType.
*/
public ArchType getArchType() {
return archType;
}
/**
* @param a The archType to set.
*/
public void setArchType(ArchType a) {
this.archType = a;
}
/**
* @return Returns the id.
*/
public Long getId() {
return id;
}
/**
* @param i The id to set.
*/
public void setId(Long i) {
this.id = i;
}
/**
* @return Returns the label.
*/
public String getLabel() {
return label;
}
/**
* @param l The label to set.
*/
public void setLabel(String l) {
this.label = l;
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param n The name to set.
*/
public void setName(String n) {
this.name = n;
}
/**
* Returns the set of server architectures compatible with this channel
* architecture.
* @return the set of server architectures compatible with this channel
* architecture.
*/
public Set getCompatibleServerArches() {
return compatibleServerArches;
}
/**
* Returns the set of package architectures compatible with this channel
* architecture.
* @return the set of package architectures compatible with this channel
* architecture.
*/
public Set getCompatiblePackageArches() {
return compatiblePackageArches;
}
/**
* Returns true if the given server architecture is compatible with this
* channel architecture. False if the server architecture is null or not
* compatible.
* @param arch Server architecture to be verified.
* @return true if compatible; false if null or not compatible.
*/
public boolean isCompatible(ServerArch arch) {
Set compats = getCompatibleServerArches();
if (compats == null) {
return false;
}
return compats.contains(arch);
}
/**
* Returns true if the given package architecture is compatible with this
* channel architecture. False if the package architecture is null or not
* compatible.
* @param arch Package architecture to be verified.
* @return true if compatible; false if null or not compatible.
*/
public boolean isCompatible(PackageArch arch) {
Set compats = getCompatiblePackageArches();
if (compats == null) {
return false;
}
return compats.contains(arch);
}
/**
* {@inheritDoc}
*/
public boolean equals(final Object other) {
if (!(other instanceof ChannelArch)) {
return false;
}
ChannelArch castOther = (ChannelArch) other;
return new EqualsBuilder().append(this.getId(), castOther.getId()).isEquals();
}
/**
* {@inheritDoc}
*/
public int hashCode() {
return new HashCodeBuilder().append(this.getId()).toHashCode();
}
/**
* {@inheritDoc}
*/
public String toString() {
return new ToStringBuilder(this).append("id", this.getId()).append("label",
this.getLabel()).append("name", this.getName()).append("archType",
this.getArchType()).toString();
}
/**
* @param arches The compatible package arches to set.
*/
public void setCompatiblePackageArches(Set<PackageArch> arches) {
compatiblePackageArches = arches;
}
/**
* Get the equivalent cobbler arch string for this ChannelArch, or null.
* Valid values are i386,x86_64,ia64,ppc,s390
* @return the cobbler arch
*/
public String cobblerArch() {
// will be like ["channel", "ia32", and possibly "deb"]. The second one is what
// we care about, map it to a cobbler arch if possible.
String[] substrings = getLabel().split("-");
if (substrings[1].equals("x86_64") || substrings[1].equals("amd64")) {
return "x86_64";
}
if (substrings[1].equals("ia32") || substrings[1].equals("i386")) {
return "i386";
}
if (substrings[1].equals("s390") || substrings[1].equals("s390x")) {
return "s390";
}
if (substrings[1].equals("ia64")) {
return "ia64";
}
if (substrings[1].equals("ppc") || substrings[1].equals("powerpc") ||
substrings[1].equals("iSeries") || substrings[1].equals("pSeries")) {
return "ppc";
}
if (substrings[1].equals("aarch64")) {
return "aarch64";
}
if (substrings[1].equals("ppc64le")) {
return "ppc64le";
}
return "";
}
}