|
26 | 26 | import java.util.HashSet;
|
27 | 27 | import java.util.List;
|
28 | 28 | import java.util.Map;
|
| 29 | +import java.util.Objects; |
29 | 30 | import java.util.Set;
|
30 | 31 |
|
31 | 32 | import javax.xml.parsers.DocumentBuilder;
|
@@ -239,13 +240,12 @@ protected static String getSimpleName(String fileName) {
|
239 | 240 | protected LaunchConfiguration(String memento) throws CoreException {
|
240 | 241 | Exception ex = null;
|
241 | 242 | try {
|
242 |
| - Element root = null; |
243 | 243 | @SuppressWarnings("restriction")
|
244 | 244 | DocumentBuilder parser = org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE();
|
245 | 245 | parser.setErrorHandler(new DefaultHandler());
|
246 | 246 | StringReader reader = new StringReader(memento);
|
247 | 247 | InputSource source = new InputSource(reader);
|
248 |
| - root = parser.parse(source).getDocumentElement(); |
| 248 | + Element root = parser.parse(source).getDocumentElement(); |
249 | 249 |
|
250 | 250 | String localString = root.getAttribute(IConfigurationElementConstants.LOCAL);
|
251 | 251 | String path = root.getAttribute(IConfigurationElementConstants.PATH);
|
@@ -285,23 +285,19 @@ protected LaunchConfiguration(String memento) throws CoreException {
|
285 | 285 | @Override
|
286 | 286 | public boolean contentsEqual(ILaunchConfiguration object) {
|
287 | 287 | try {
|
288 |
| - if (object instanceof LaunchConfiguration) { |
289 |
| - LaunchConfiguration otherConfig = (LaunchConfiguration) object; |
290 |
| - return getName().equals(otherConfig.getName()) |
291 |
| - && getType().equals(otherConfig.getType()) |
292 |
| - && equalOrNull(getContainer(), otherConfig.getContainer()) |
293 |
| - && getInfo().equals(otherConfig.getInfo()); |
294 |
| - } |
295 |
| - return false; |
| 288 | + return object instanceof LaunchConfiguration otherConfig // |
| 289 | + && getName().equals(otherConfig.getName()) // |
| 290 | + && getType().equals(otherConfig.getType()) // |
| 291 | + && Objects.equals(getContainer(), otherConfig.getContainer()) // |
| 292 | + && getInfo().equals(otherConfig.getInfo()); |
296 | 293 | } catch (CoreException ce) {
|
297 | 294 | return false;
|
298 | 295 | }
|
299 | 296 | }
|
300 | 297 |
|
301 | 298 | @Override
|
302 | 299 | public ILaunchConfigurationWorkingCopy copy(String name) throws CoreException {
|
303 |
| - ILaunchConfigurationWorkingCopy copy = new LaunchConfigurationWorkingCopy(this, name); |
304 |
| - return copy; |
| 300 | + return new LaunchConfigurationWorkingCopy(this, name); |
305 | 301 | }
|
306 | 302 |
|
307 | 303 | @Override
|
@@ -362,36 +358,17 @@ public void delete(int flag) throws CoreException {
|
362 | 358 | */
|
363 | 359 | @Override
|
364 | 360 | public boolean equals(Object object) {
|
365 |
| - if (object instanceof ILaunchConfiguration) { |
| 361 | + if (object instanceof LaunchConfiguration config) { |
366 | 362 | if (isWorkingCopy()) {
|
367 | 363 | return this == object;
|
368 | 364 | }
|
369 |
| - LaunchConfiguration config = (LaunchConfiguration) object; |
370 | 365 | if (!config.isWorkingCopy()) {
|
371 |
| - return getName().equals(config.getName()) && |
372 |
| - equalOrNull(getContainer(), config.getContainer()); |
| 366 | + return getName().equals(config.getName()) && Objects.equals(getContainer(), config.getContainer()); |
373 | 367 | }
|
374 | 368 | }
|
375 | 369 | return false;
|
376 | 370 | }
|
377 | 371 |
|
378 |
| - /** |
379 |
| - * Returns whether the given objects are equal or both <code>null</code>. |
380 |
| - * |
381 |
| - * @param o1 the object |
382 |
| - * @param o2 the object to be compared to o1 |
383 |
| - * @return whether the given objects are equal or both <code>null</code> |
384 |
| - * @since 3.5 |
385 |
| - */ |
386 |
| - protected boolean equalOrNull(Object o1, Object o2) { |
387 |
| - if (o1 == null) { |
388 |
| - return o2 == null; |
389 |
| - } else if (o2 != null) { |
390 |
| - return o1.equals(o2); |
391 |
| - } |
392 |
| - return false; |
393 |
| - } |
394 |
| - |
395 | 372 | @Override
|
396 | 373 | public boolean exists() {
|
397 | 374 | IFile file = getFile();
|
@@ -542,7 +519,7 @@ public IResource[] getMappedResources() throws CoreException {
|
542 | 519 | if (types == null || types.size() != paths.size()) {
|
543 | 520 | throw new CoreException(newStatus(DebugCoreMessages.LaunchConfiguration_0, DebugPlugin.ERROR, null));
|
544 | 521 | }
|
545 |
| - ArrayList<IResource> list = new ArrayList<>(); |
| 522 | + List<IResource> list = new ArrayList<>(); |
546 | 523 | IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
547 | 524 | for(int i = 0; i < paths.size(); i++) {
|
548 | 525 | String pathStr = paths.get(i);
|
@@ -650,12 +627,7 @@ public ILaunchConfigurationWorkingCopy getWorkingCopy() throws CoreException {
|
650 | 627 |
|
651 | 628 | @Override
|
652 | 629 | public int hashCode() {
|
653 |
| - IContainer container = getContainer(); |
654 |
| - if (container == null) { |
655 |
| - return getName().hashCode(); |
656 |
| - } else { |
657 |
| - return getName().hashCode() + container.hashCode(); |
658 |
| - } |
| 630 | + return Objects.hash(getName(), getContainer()); |
659 | 631 | }
|
660 | 632 |
|
661 | 633 | @Override
|
|
0 commit comments