Debian Codegraph @

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/RequirementChange.java

raw
1 /*******************************************************************************
2 * Copyright (c) 2007, 2017 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.equinox.internal.p2.metadata;
15
16 import org.eclipse.equinox.p2.metadata.IRequirementChange;
17
18 public class RequirementChange implements IRequirementChange {
19 private IRequiredCapability applyOn;
20 private IRequiredCapability newValue;
21
22 public RequirementChange(IRequiredCapability applyOn2, IRequiredCapability newValue2) {
23 if (applyOn2 == null && newValue2 == null)
24 throw new IllegalArgumentException();
25 this.applyOn = applyOn2;
26 this.newValue = newValue2;
27 }
28
29 @Override
30 public IRequiredCapability applyOn() {
31 return applyOn;
32 }
33
34 @Override
35 public IRequiredCapability newValue() {
36 return newValue;
37 }
38
39 @Override
40 public boolean matches(IRequiredCapability toMatch) {
41 if (!toMatch.getNamespace().equals(applyOn.getNamespace()))
42 return false;
43 if (!toMatch.getName().equals(applyOn.getName()))
44 return false;
45 if (toMatch.getRange().equals(applyOn.getRange()))
46 return true;
47
48 return toMatch.getRange().intersect(applyOn.getRange()) != null;
49 }
50
51 @Override
52 public int hashCode() {
53 final int prime = 31;
54 int result = 1;
55 result = prime * result + ((applyOn == null) ? 0 : applyOn.hashCode());
56 result = prime * result + ((newValue == null) ? 0 : newValue.hashCode());
57 return result;
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (this == obj)
63 return true;
64 if (obj == null)
65 return false;
66 if (!(obj instanceof IRequirementChange))
67 return false;
68 final IRequirementChange other = (IRequirementChange) obj;
69 if (applyOn == null) {
70 if (other.applyOn() != null)
71 return false;
72 } else if (!applyOn.equals(other.applyOn()))
73 return false;
74 if (newValue == null) {
75 if (other.newValue() != null)
76 return false;
77 } else if (!newValue.equals(other.newValue()))
78 return false;
79 return true;
80 }
81
82 @Override
83 public String toString() {
84 return applyOn + " --> " + newValue; //$NON-NLS-1$
85 }
86 }