analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / project / wizards / importtrace / FileAndName.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
13 package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace;
14
15 import java.io.File;
16
17 import static org.eclipse.tracecompass.common.core.NonNullUtils.equalsNullable;
18
19 /**
20 * File and name internal helper class <br>
21 * it has the file, a name to display, whether the name is conflicting and a
22 * reference to the configuration element defining its trace type.
23 *
24 * @author Matthew Khouzam
25 */
26 class FileAndName implements Comparable<FileAndName> {
27
28 private final File fFile;
29 private String fTraceTypeId;
30 private String fName;
31 private boolean fConflict;
32
33 // ------------------------------------------------------------------------
34 // Constructor
35 // ------------------------------------------------------------------------
36
37 /**
38 * A file and name
39 *
40 * @param f
41 * the file, can only be set here
42 * @param n
43 * the name, can be renamed
44 *
45 */
46 public FileAndName(File f, String n) {
47 fFile = f;
48 fName = n;
49 fTraceTypeId = null;
50 }
51
52 // ------------------------------------------------------------------------
53 // Getter / Setter
54 // ------------------------------------------------------------------------
55
56 /**
57 * Get the name
58 *
59 * @return the name
60 */
61 public String getName() {
62 return fName;
63 }
64
65 /**
66 * Set the name
67 *
68 * @param name
69 * the name to set
70 */
71 public void setName(String name) {
72 this.fName = name;
73 }
74
75 /**
76 * Sets the configuration element of the
77 *
78 * @param elem
79 * the element
80 */
81 public void setTraceTypeId(String elem) {
82 fTraceTypeId = elem;
83 }
84
85 /**
86 * Gets the configuration element canonical name
87 *
88 * @return gets the configuration element canonical name
89 */
90 public String getTraceTypeId() {
91 return fTraceTypeId;
92 }
93
94 /**
95 * Get the file
96 *
97 * @return the file
98 */
99 public File getFile() {
100 return fFile;
101 }
102
103 /**
104 * Set that the name is conflicting or not
105 *
106 * @param conflict
107 * if the name is conflicting or not
108 */
109 public void setConflictingName(boolean conflict) {
110 fConflict = conflict;
111 }
112
113 /**
114 * Is the name conflicting?
115 *
116 * @return is the name conflicting?
117 */
118 public boolean isConflictingName() {
119 return fConflict;
120 }
121
122 /**
123 * Is the fileAndName renamed
124 *
125 * @return true if the name does not match the filename
126 */
127 public boolean isRenamed() {
128 return !fName.equals(fFile.getName());
129 }
130
131 // ------------------------------------------------------------------------
132 // Comparator & Equals
133 // ------------------------------------------------------------------------
134
135 @Override
136 public int compareTo(FileAndName o) {
137 int retVal = getFile().compareTo(o.getFile());
138 if (retVal == 0 && getTraceTypeId() != null && o.getTraceTypeId() != null) {
139 retVal = getTraceTypeId().compareTo(o.getTraceTypeId());
140 }
141 return retVal;
142 }
143
144 @Override
145 public int hashCode() {
146 // do not take "name" into account since it can change on the fly.
147 final int prime = 31;
148 int result = 1;
149 result = prime * result + ((fTraceTypeId == null) ? 0 : fTraceTypeId.hashCode());
150 result = prime * result + ((fFile == null) ? 0 : fFile.hashCode());
151 return result;
152 }
153
154 @Override
155 public boolean equals(Object obj) {
156 // do not take "name" into account since it can change on the fly.
157 if (this == obj) {
158 return true;
159 }
160 if (obj == null) {
161 return false;
162 }
163 if (!(obj instanceof FileAndName)) {
164 return false;
165 }
166 FileAndName other = (FileAndName) obj;
167 if (!equalsNullable(fTraceTypeId, other.fTraceTypeId)) {
168 return false;
169 }
170 if (!equalsNullable(fFile, other.fFile)) {
171 return false;
172 }
173 return true;
174 }
175 }
This page took 0.037773 seconds and 5 git commands to generate.