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
101
102
103
104
105
106
107
108
109
110
111
|
/*******************************************************************************
* Copyright (c) 2013, 2014 Tasktop Technologies and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.gerrit.core.client;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.mylyn.internal.gerrit.core.client.compat.PatchScriptX;
import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.reviewdb.Patch;
import com.google.gerrit.reviewdb.PatchSet;
/**
* Defines a single patch set, that is a state comparison between an (optional) base and target. The content can then be
* populated by calling
* {@link GerritClient#loadPatchSetContent(GerritPatchSetContent, org.eclipse.core.runtime.IProgressMonitor)}.
*
* @author Steffen Pingel
* @author Miles Parker
*/
public class PatchSetContent {
private final PatchSet base;
private PatchSet target;
private PatchSetDetail targetDetail;
Map<Patch.Key, PatchScriptX> patchScriptByPatchKey;
/**
* Creates empty patch set content using detailed target.
*
* @param base
* may be null, in which case the target will be compared to an empty baseline
* @param targetDetail
*/
public PatchSetContent(PatchSet base, PatchSetDetail targetDetail) {
this.base = base;
this.targetDetail = targetDetail;
this.patchScriptByPatchKey = new HashMap<Patch.Key, PatchScriptX>();
}
/**
* Creates empty patch set content using basic patch set.
*
* @param base
* may be null, in which case the target will be compared to an empty baseline
* @param target
*/
public PatchSetContent(PatchSet base, PatchSet target) {
this.base = base;
this.target = target;
this.patchScriptByPatchKey = new HashMap<Patch.Key, PatchScriptX>();
}
public PatchSet getBase() {
return base;
}
public PatchSet getTarget() {
if (targetDetail != null) {
target = targetDetail.getPatchSet();
}
return target;
}
/**
* Returns null if not supplied by constructor, unless initialized by
* {@link GerritClient#loadPatchSetContent(GerritPatchSetContent, org.eclipse.core.runtime.IProgressMonitor)}
*
* @return
*/
public PatchSetDetail getTargetDetail() {
return targetDetail;
}
public void setTargetDetail(PatchSetDetail targetDetail) {
this.targetDetail = targetDetail;
}
void putPatchScriptByPatchKey(Patch.Key key, PatchScriptX script) {
patchScriptByPatchKey.put(key, script);
}
public PatchScriptX getPatchScript(Patch.Key key) {
return patchScriptByPatchKey.get(key);
}
public String getId() {
String id = ""; //$NON-NLS-1$
if (getBase() != null) {
id += getBase().getId() + "-"; //$NON-NLS-1$
}
if (getTarget() != null) {
id += getTarget().getId();
}
return id;
}
}
|