blob: c3aad8977c0dceff0bfcb94c16686504b96bebc3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.p2.update;
import java.util.ArrayList;
import java.util.List;
/*
* Represents the changes between 2 lists of sites.
*/
public class SiteDelta {
private static final String PLATFORM_BASE = "platform:/base/"; //$NON-NLS-1$
static class Change {
Site oldSite;
Site newSite;
Change(Site oldSite, Site newSite) {
this.oldSite = oldSite;
this.newSite = newSite;
}
}
private List added = new ArrayList();
private List removed = new ArrayList();
private List changed = new ArrayList();
/*
* Create and return a new delta object based on the two given lists of
* site objects.
*/
public static SiteDelta create(List oneList, List twoList) {
Site[] one = (Site[]) oneList.toArray(new Site[oneList.size()]);
Site[] two = (Site[]) twoList.toArray(new Site[twoList.size()]);
SiteDelta result = new SiteDelta();
for (int i = 0; one == null || i < one.length; i++) {
boolean found = false;
for (int j = 0; !found && j < two.length; j++) {
if (two[j] != null && one[i].getUrl().equals(two[j].getUrl())) {
found = true;
// TODO
if (!one[i].getUrl().equals(PLATFORM_BASE) && !one[i].equals(two[j]))
result.changed.add(new Change(one[i], two[j]));
one[i] = null;
two[j] = null;
}
}
// TODO
if (!found && !PLATFORM_BASE.equals(one[i].getUrl()))
result.removed.add(one[i]);
}
for (int j = 0; j < two.length; j++) {
// TODO
if (two[j] != null && !PLATFORM_BASE.equals(two[j].getUrl()))
result.added.add(two[j]);
}
return result;
}
/*
* Return a list of the sites that were added. May return an empty list
* but never returns null.
*/
public Site[] added() {
return (Site[]) added.toArray(new Site[added.size()]);
}
/*
* Return a list of the sites that were removed. May return an empty list
* but never returns null.
*/
public Site[] removed() {
return (Site[]) removed.toArray(new Site[removed.size()]);
}
/*
* Return a list of the site changes that were changed. May return an empty list
* but never returns null.
*/
public Change[] changed() {
return (Change[]) changed.toArray(new Change[changed.size()]);
}
/*
* Return a boolean value indicating whether or not there are any
* changes in this delta.
*/
public boolean isEmpty() {
return added.size() == 0 && removed.size() == 0 && changed.size() == 0;
}
}
|