| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
| 11 | package org.eclipse.pde.api.tools.internal.descriptors; |
| 12 | |
| 13 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IComponentDescriptor; |
| 14 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; |
| 15 | |
| 16 | /** |
| 17 | * Base implementation of {@link IComponentDescriptor} |
| 18 | * |
| 19 | * @since 1.0.1 |
| 20 | * |
| 21 | * @noextend This class is not intended to be subclassed by clients. |
| 22 | * @noinstantiate This class is not intended to be instantiated by clients. |
| 23 | */ |
| 24 | public class ComponentDescriptorImpl extends NamedElementDescriptorImpl implements IComponentDescriptor { |
| 25 | |
| 26 | private String componentid = null; |
| 27 | private String version = null; |
| 28 | |
| 29 | /** |
| 30 | * Constructor |
| 31 | * @param componentid |
| 32 | */ |
| 33 | public ComponentDescriptorImpl(String componentid, String version) { |
| 34 | super(componentid); |
| 35 | this.componentid = componentid; |
| 36 | this.version = version; |
| 37 | |
| 38 | } |
| 39 | |
| 40 | /* (non-Javadoc) |
| 41 | * @see org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor#getElementType() |
| 42 | */ |
| 43 | public int getElementType() { |
| 44 | return COMPONENT; |
| 45 | } |
| 46 | |
| 47 | /* (non-Javadoc) |
| 48 | * @see java.lang.Object#hashCode() |
| 49 | */ |
| 50 | public int hashCode() { |
| 51 | int hc = 0; |
| 52 | if (version != null) { |
| 53 | hc = version.hashCode(); |
| 54 | } |
| 55 | return this.componentid.hashCode() + hc; |
| 56 | } |
| 57 | |
| 58 | /* (non-Javadoc) |
| 59 | * @see java.lang.Object#equals(java.lang.Object) |
| 60 | */ |
| 61 | public boolean equals(Object obj) { |
| 62 | if(obj instanceof IComponentDescriptor) { |
| 63 | if (this.componentid.equals(((IComponentDescriptor)obj).getId())) { |
| 64 | if (this.version == null) { |
| 65 | return ((IComponentDescriptor)obj).getVersion() == null; |
| 66 | } else { |
| 67 | return this.version.equals(((IComponentDescriptor)obj).getVersion()); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | /* (non-Javadoc) |
| 75 | * @see org.eclipse.pde.api.tools.internal.provisional.descriptors.IComponentDescriptor#getId() |
| 76 | */ |
| 77 | public String getId() { |
| 78 | return this.componentid; |
| 79 | } |
| 80 | |
| 81 | /* (non-Javadoc) |
| 82 | * @see org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor#getPath() |
| 83 | */ |
| 84 | public IElementDescriptor[] getPath() { |
| 85 | return null; |
| 86 | } |
| 87 | |
| 88 | /* (non-Javadoc) |
| 89 | * @see java.lang.Object#toString() |
| 90 | */ |
| 91 | public String toString() { |
| 92 | return this.componentid; |
| 93 | } |
| 94 | |
| 95 | /* (non-Javadoc) |
| 96 | * @see org.eclipse.pde.api.tools.internal.provisional.descriptors.IComponentDescriptor#getVersion() |
| 97 | */ |
| 98 | public String getVersion() { |
| 99 | return version; |
| 100 | } |
| 101 | |
| 102 | } |