Commit | Line | Data |
---|---|---|
d04ec5a7 MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Matthew Khouzam - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
1de10308 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace; |
d04ec5a7 MK |
14 | |
15 | import java.io.File; | |
16 | ||
17 | /** | |
18 | * File and name internal helper class <br> | |
19 | * it has the file, a name to display, whether the name is conflicting and a | |
20 | * reference to the configuration element defining its trace type. | |
21 | * | |
22 | * @author Matthew Khouzam | |
23 | * @since 2.0 | |
24 | */ | |
25 | class FileAndName implements Comparable<FileAndName> { | |
26 | ||
27 | final private File fFile; | |
28 | private String fTraceTypeId; | |
29 | private String fName; | |
30 | private boolean fConflict; | |
31 | ||
32 | // ------------------------------------------------------------------------ | |
33 | // Constructor | |
34 | // ------------------------------------------------------------------------ | |
35 | ||
36 | /** | |
37 | * A file and name | |
38 | * | |
39 | * @param f | |
40 | * the file, can only be set here | |
41 | * @param n | |
42 | * the name, can be renamed | |
43 | * | |
44 | */ | |
45 | public FileAndName(File f, String n) { | |
46 | fFile = f; | |
47 | fName = n; | |
48 | fTraceTypeId = null; | |
49 | } | |
50 | ||
51 | // ------------------------------------------------------------------------ | |
52 | // Getter / Setter | |
53 | // ------------------------------------------------------------------------ | |
54 | ||
55 | /** | |
56 | * Get the name | |
57 | * | |
58 | * @return the name | |
59 | */ | |
60 | public String getName() { | |
61 | return fName; | |
62 | } | |
63 | ||
64 | /** | |
65 | * Set the name | |
66 | * | |
67 | * @param name | |
68 | * the name to set | |
69 | */ | |
70 | public void setName(String name) { | |
71 | this.fName = name; | |
72 | } | |
73 | ||
74 | /** | |
75 | * Sets the configuration element of the | |
76 | * | |
77 | * @param elem | |
78 | * the element | |
79 | */ | |
80 | public void setTraceTypeId(String elem) { | |
81 | fTraceTypeId = elem; | |
82 | } | |
83 | ||
84 | /** | |
85 | * Gets the configuration element canonical name | |
86 | * | |
87 | * @return gets the configuration element canonical name | |
88 | */ | |
89 | public String getTraceTypeId() { | |
90 | return fTraceTypeId; | |
91 | } | |
92 | ||
93 | /** | |
94 | * Get the file | |
95 | * | |
96 | * @return the file | |
97 | */ | |
98 | public File getFile() { | |
99 | return fFile; | |
100 | } | |
101 | ||
102 | /** | |
103 | * Set that the name is conflicting or not | |
104 | * | |
105 | * @param conflict | |
106 | * if the name is conflicting or not | |
107 | */ | |
108 | public void setConflictingName(boolean conflict) { | |
109 | fConflict = conflict; | |
110 | } | |
111 | ||
112 | /** | |
113 | * Is the name conflicting? | |
114 | * | |
115 | * @return is the name conflicting? | |
116 | */ | |
117 | public boolean isConflictingName() { | |
118 | return fConflict; | |
119 | } | |
120 | ||
a2d29ca1 MK |
121 | /** |
122 | * Is the fileAndName renamed | |
123 | * | |
124 | * @return true if the name does not match the filename | |
125 | */ | |
126 | public boolean isRenamed() { | |
127 | return !fName.equals(fFile.getName()); | |
128 | } | |
129 | ||
d04ec5a7 MK |
130 | // ------------------------------------------------------------------------ |
131 | // Comparator & Equals | |
132 | // ------------------------------------------------------------------------ | |
133 | ||
134 | @Override | |
135 | public int compareTo(FileAndName o) { | |
136 | int retVal = getFile().compareTo(o.getFile()); | |
137 | if (retVal == 0) { | |
138 | if (getTraceTypeId() != null) { | |
139 | if (getTraceTypeId() != null) { | |
140 | if (o.getTraceTypeId() != null) { | |
141 | retVal = getTraceTypeId().compareTo(o.getTraceTypeId()); | |
142 | } | |
143 | } | |
144 | } | |
145 | } | |
146 | return retVal; | |
147 | } | |
148 | ||
149 | @Override | |
150 | public int hashCode() { | |
151 | // do not take "name" into account since it can change on the fly. | |
152 | final int prime = 31; | |
153 | int result = 1; | |
154 | result = prime * result + ((fTraceTypeId == null) ? 0 : fTraceTypeId.hashCode()); | |
155 | result = prime * result + ((fFile == null) ? 0 : fFile.hashCode()); | |
156 | return result; | |
157 | } | |
158 | ||
159 | @Override | |
160 | public boolean equals(Object obj) { | |
161 | // do not take "name" into account since it can change on the fly. | |
162 | if (this == obj) { | |
163 | return true; | |
164 | } | |
165 | if (obj == null) { | |
166 | return false; | |
167 | } | |
168 | if (!(obj instanceof FileAndName)) { | |
169 | return false; | |
170 | } | |
171 | FileAndName other = (FileAndName) obj; | |
172 | if (fTraceTypeId == null) { | |
173 | if (other.fTraceTypeId != null) { | |
174 | return false; | |
175 | } | |
176 | } else if (!fTraceTypeId.equals(other.fTraceTypeId)) { | |
177 | return false; | |
178 | } | |
179 | if (fFile == null) { | |
180 | if (other.fFile != null) { | |
181 | return false; | |
182 | } | |
183 | } else if (!fFile.equals(other.fFile)) { | |
184 | return false; | |
185 | } | |
186 | return true; | |
187 | } | |
188 | } |