Skip to main content
summaryrefslogtreecommitdiffstats
blob: 32154d20ede3c3cd7ce04320f50c1f09d4669b2f (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*******************************************************************************
 * Copyright (C) 2010, 2013 Dariusz Luksza <dariusz@luksza.org> 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
 *******************************************************************************/
package org.eclipse.egit.ui.internal.synchronize.model;

import java.util.List;

import org.eclipse.core.runtime.IPath;

/**
 * Representation of Git tree's in Git ChangeSet model
 */
public class GitModelTree extends GitModelObjectContainer {

	private final int kind;

	/**
	 * Absolute repository path
	 */
	protected final IPath path;

	private GitModelObject[] children;

	/**
	 * @param parent
	 *            parent object
	 * @param fullPath
	 *            absolute object path
	 * @param kind
	 *            type of change
	 */
	public GitModelTree(GitModelObjectContainer parent, IPath fullPath,
			int kind) {
		super(parent);
		this.kind = kind;
		this.path = fullPath;
	}

	@Override
	public String getName() {
		return path.lastSegment();
	}

	@Override
	public IPath getLocation() {
		return path;
	}

	@Override
	public int getKind() {
		return kind;
	}

	@Override
	public int repositoryHashCode() {
		return getParent().repositoryHashCode();
	}

	@Override
	public GitModelObject[] getChildren() {
		return children;
	}

	@Override
	public boolean isContainer() {
		return true;
	}

	@Override
	public void dispose() {
		if (children != null) {
			for (GitModelObject object : children)
				object.dispose();
			children = null;
		}
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getParent() == null) ? 0 : getParent().hashCode());
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GitModelTree other = (GitModelTree) obj;
		if (getParent() == null) {
			if (other.getParent() != null)
				return false;
		} else if (!getParent().equals(other.getParent()))
			return false;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ModelTree[location=" + getLocation() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
	}

	void setChildren(List<GitModelObject> children) {
		this.children = children.toArray(new GitModelObject[children.size()]);
	}

}

Back to the top