Tmf: Batch Trace Import
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / wizards / importtrace / FileAndName.java
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
13 package org.eclipse.linuxtools.tmf.ui.project.wizards.importtrace;
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
121 // ------------------------------------------------------------------------
122 // Comparator & Equals
123 // ------------------------------------------------------------------------
124
125 @Override
126 public int compareTo(FileAndName o) {
127 int retVal = getFile().compareTo(o.getFile());
128 if (retVal == 0) {
129 if (getTraceTypeId() != null) {
130 if (getTraceTypeId() != null) {
131 if (o.getTraceTypeId() != null) {
132 retVal = getTraceTypeId().compareTo(o.getTraceTypeId());
133 }
134 }
135 }
136 }
137 return retVal;
138 }
139
140 @Override
141 public int hashCode() {
142 // do not take "name" into account since it can change on the fly.
143 final int prime = 31;
144 int result = 1;
145 result = prime * result + ((fTraceTypeId == null) ? 0 : fTraceTypeId.hashCode());
146 result = prime * result + ((fFile == null) ? 0 : fFile.hashCode());
147 return result;
148 }
149
150 @Override
151 public boolean equals(Object obj) {
152 // do not take "name" into account since it can change on the fly.
153 if (this == obj) {
154 return true;
155 }
156 if (obj == null) {
157 return false;
158 }
159 if (!(obj instanceof FileAndName)) {
160 return false;
161 }
162 FileAndName other = (FileAndName) obj;
163 if (fTraceTypeId == null) {
164 if (other.fTraceTypeId != null) {
165 return false;
166 }
167 } else if (!fTraceTypeId.equals(other.fTraceTypeId)) {
168 return false;
169 }
170 if (fFile == null) {
171 if (other.fFile != null) {
172 return false;
173 }
174 } else if (!fFile.equals(other.fFile)) {
175 return false;
176 }
177 return true;
178 }
179 }
This page took 0.037885 seconds and 5 git commands to generate.