Skip to content

Commit 007ee10

Browse files
committed
Minor code simplifications in LaunchConfiguration
1 parent 2f90d3c commit 007ee10

File tree

1 file changed

+12
-40
lines changed

1 file changed

+12
-40
lines changed

debug/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.HashSet;
2727
import java.util.List;
2828
import java.util.Map;
29+
import java.util.Objects;
2930
import java.util.Set;
3031

3132
import javax.xml.parsers.DocumentBuilder;
@@ -239,13 +240,12 @@ protected static String getSimpleName(String fileName) {
239240
protected LaunchConfiguration(String memento) throws CoreException {
240241
Exception ex = null;
241242
try {
242-
Element root = null;
243243
@SuppressWarnings("restriction")
244244
DocumentBuilder parser = org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE();
245245
parser.setErrorHandler(new DefaultHandler());
246246
StringReader reader = new StringReader(memento);
247247
InputSource source = new InputSource(reader);
248-
root = parser.parse(source).getDocumentElement();
248+
Element root = parser.parse(source).getDocumentElement();
249249

250250
String localString = root.getAttribute(IConfigurationElementConstants.LOCAL);
251251
String path = root.getAttribute(IConfigurationElementConstants.PATH);
@@ -285,23 +285,19 @@ protected LaunchConfiguration(String memento) throws CoreException {
285285
@Override
286286
public boolean contentsEqual(ILaunchConfiguration object) {
287287
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());
296293
} catch (CoreException ce) {
297294
return false;
298295
}
299296
}
300297

301298
@Override
302299
public ILaunchConfigurationWorkingCopy copy(String name) throws CoreException {
303-
ILaunchConfigurationWorkingCopy copy = new LaunchConfigurationWorkingCopy(this, name);
304-
return copy;
300+
return new LaunchConfigurationWorkingCopy(this, name);
305301
}
306302

307303
@Override
@@ -362,36 +358,17 @@ public void delete(int flag) throws CoreException {
362358
*/
363359
@Override
364360
public boolean equals(Object object) {
365-
if (object instanceof ILaunchConfiguration) {
361+
if (object instanceof LaunchConfiguration config) {
366362
if (isWorkingCopy()) {
367363
return this == object;
368364
}
369-
LaunchConfiguration config = (LaunchConfiguration) object;
370365
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());
373367
}
374368
}
375369
return false;
376370
}
377371

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-
395372
@Override
396373
public boolean exists() {
397374
IFile file = getFile();
@@ -542,7 +519,7 @@ public IResource[] getMappedResources() throws CoreException {
542519
if (types == null || types.size() != paths.size()) {
543520
throw new CoreException(newStatus(DebugCoreMessages.LaunchConfiguration_0, DebugPlugin.ERROR, null));
544521
}
545-
ArrayList<IResource> list = new ArrayList<>();
522+
List<IResource> list = new ArrayList<>();
546523
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
547524
for(int i = 0; i < paths.size(); i++) {
548525
String pathStr = paths.get(i);
@@ -650,12 +627,7 @@ public ILaunchConfigurationWorkingCopy getWorkingCopy() throws CoreException {
650627

651628
@Override
652629
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());
659631
}
660632

661633
@Override

0 commit comments

Comments
 (0)