Java tutorial
/******************************************************************************* * Copyright (c) 2011, 2012 AGETO Service GmbH and others. * All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html. * * Contributors: * Gunnar Wagenknecht - initial API and implementation *******************************************************************************/ package org.eclipse.gyrex.p2.internal.packages; import org.eclipse.equinox.p2.metadata.Version; import org.eclipse.gyrex.common.identifiers.IdHelper; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; /** * An installable unit. */ public final class InstallableUnitReference { private String id; private Version version; @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final InstallableUnitReference other = (InstallableUnitReference) obj; if (id == null) { if (other.id != null) { return false; } } else if (!id.equals(other.id)) { return false; } if (version == null) { if (other.version != null) { return false; } } else if (!version.equals(other.version)) { return false; } return true; } /** * The unit id. * * @return */ public String getId() { return id; } /** * Returns the version. * * @return the version */ public Version getVersion() { return version; } @Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + ((id == null) ? 0 : id.hashCode()); result = (prime * result) + ((version == null) ? 0 : version.hashCode()); return result; } /** * Sets the id. * * @param id * the id to set */ public void setId(final String id) { if (!IdHelper.isValidId(id)) { throw new IllegalArgumentException("invalid id"); } this.id = id; } /** * Sets the version. * * @param version * the version to set */ public void setVersion(final Version version) { this.version = version; } @Override public String toString() { final ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); builder.append("id", id); builder.append("version", version); return builder.toString(); } }