Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ad232b5c2a4e24b1bfd2db397c4be1cccdf6b220 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*******************************************************************************
 * Copyright (c) 2000, 2008 QNX Software Systems 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:
 *     QNX Software Systems - Initial API and implementation
 *     Anton Leherbauer (Wind River Systems)
 *     IBM Corporation
 *******************************************************************************/
package org.eclipse.cdt.internal.core.model;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

public abstract class APathEntry extends PathEntry {

	public static IPath[] NO_EXCLUSION_PATTERNS = {};
	IPath[] exclusionPatterns;
	IPath basePath;
	IPath baseRef;
	private final static char[][] UNINIT_PATTERNS = new char[][] { "Non-initialized yet".toCharArray() }; //$NON-NLS-1$
	char[][]fullCharExclusionPatterns = UNINIT_PATTERNS;

	/**
	 * 
	 * @param kind
	 * @param basePath
	 * @param baseRef
	 * @param path
	 * @param exclusionPatterns
	 * @param isExported
	 */
	public APathEntry (int kind, IPath basePath, IPath baseRef, IPath path, IPath[] exclusionPatterns, boolean isExported) {
		super(kind, path, isExported);
		this.basePath = (basePath == null) ? Path.EMPTY : basePath;
		this.baseRef = (baseRef == null) ? Path.EMPTY : baseRef;
		this.exclusionPatterns = (exclusionPatterns == null) ? NO_EXCLUSION_PATTERNS : exclusionPatterns;
	}

	/**
	 * Returns the exclusion patterns
	 * @return IPath[]
	 */
	public IPath[] getExclusionPatterns() {
		return exclusionPatterns;
	}

	/**
	 * Returns the base Path
	 * @return IPath
	 */
	public IPath getBasePath() {
		return basePath;
	}

	/**
	 * 
	 * @return
	 */
	public IPath getBaseReference() {
		return baseRef;
	}

	/**
	 * Returns a char based representation of the exclusions patterns full path.
	 */
	public char[][] fullExclusionPatternChars() {
		if (this.fullCharExclusionPatterns == UNINIT_PATTERNS) {
			int length = this.exclusionPatterns.length;
			this.fullCharExclusionPatterns = new char[length][];
			IPath prefixPath = this.path.removeTrailingSeparator();
			for (int i = 0; i < length; i++) {
				this.fullCharExclusionPatterns[i] = 
					prefixPath.append(this.exclusionPatterns[i]).toString().toCharArray();
			}
		}
		return this.fullCharExclusionPatterns;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof APathEntry) {
			APathEntry otherEntry = (APathEntry)obj;
			if (!super.equals(otherEntry)) {
				return false;
			}
			IPath[] otherExcludes = otherEntry.getExclusionPatterns();
			if (exclusionPatterns != otherExcludes) {
				int excludeLength = (exclusionPatterns == null) ? 0 : exclusionPatterns.length;
				if (otherExcludes.length != excludeLength) {
					return false;
				}
				
				Set<String> excludeSet = new HashSet<String>();
				Set<String> otherSet = new HashSet<String>();
				for (int i=0; i < excludeLength; i++) {
					if (exclusionPatterns[i] != otherExcludes[i]) {
						// compare toStrings instead of IPaths
						// since IPath.equals is specified to ignore trailing separators
						excludeSet.add(exclusionPatterns[i].toString());
						otherSet.add(otherExcludes[i].toString());
					}
				}
				if (!excludeSet.equals(otherSet)) {
					return false;
				}
			}
			IPath otherBasePath = otherEntry.getBasePath();
			if (basePath != null) {
				if (otherBasePath != null && !basePath.equals(otherBasePath)) {
					return false;
				}
			}
			IPath otherBaseRef = otherEntry.getBaseReference();
			if (baseRef != null) {
				if (otherBaseRef != null && !baseRef.equals(otherBaseRef)) {
					return false;
				}
			}
			return true;
		}
		return super.equals(obj);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append(super.toString());
		if (basePath != null && !basePath.isEmpty()) {
			sb.append(" base-path:").append(basePath.toString()); //$NON-NLS-1$
		}
		if (baseRef != null && !baseRef.isEmpty()) {
			sb.append(" base-ref:").append(baseRef.toString()); //$NON-NLS-1$
		}
		return sb.toString();
	}
}

Back to the top