From a4524c1bc56a9d593380c4c72919c27ab9497535 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Tue, 17 Dec 2013 16:44:44 -0500 Subject: [PATCH] tmf: Switch tmf.core to Java 7 + fix warnings Change-Id: I32fb093edb6bf70fdbe9a5ad1a9c8239a1e9ed05 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/19927 Reviewed-by: Matthew Khouzam Tested-by: Hudson CI IP-Clean: Matthew Khouzam --- org.eclipse.linuxtools.tmf.core/.classpath | 2 +- .../.settings/org.eclipse.jdt.core.prefs | 10 +- .../META-INF/MANIFEST.MF | 2 +- .../tmf/core/analysis/TmfAnalysisType.java | 4 +- .../core/component/TmfProviderManager.java | 6 +- .../request/TmfCoalescedEventRequest.java | 2 +- .../tmf/core/request/TmfRequestExecutor.java | 4 +- .../tmf/core/statesystem/Attribute.java | 6 +- .../tmf/core/statesystem/AttributeTree.java | 16 +-- .../tmf/core/statesystem/StateSystem.java | 12 +- .../tmf/core/statesystem/TransientState.java | 12 +- .../statesystem/backends/InMemoryBackend.java | 2 +- .../backends/historytree/HTNode.java | 2 +- .../backends/historytree/HistoryTree.java | 114 ++++++++---------- .../ThreadedHistoryTreeBackend.java | 4 +- .../partial/PartialHistoryBackend.java | 3 +- .../AbstractTmfMipmapStateProvider.java | 4 +- .../statesystem/mipmap/TmfMipmapFeature.java | 4 +- .../core/trace/indexer/BTreeNodeCache.java | 2 +- .../core/trace/indexer/TmfMemoryIndex.java | 2 +- .../analysis/TmfAbstractAnalysisModule.java | 8 +- .../tmf/core/analysis/TmfAnalysisManager.java | 10 +- .../tmf/core/component/TmfEventProvider.java | 5 +- .../core/ctfadaptor/CtfIteratorManager.java | 6 +- .../tmf/core/ctfadaptor/CtfTmfEvent.java | 2 +- .../core/ctfadaptor/CtfTmfEventFactory.java | 2 +- .../tmf/core/ctfadaptor/CtfTmfEventField.java | 6 +- .../tmf/core/event/TmfEventField.java | 2 +- .../tmf/core/event/TmfEventTypeManager.java | 4 +- .../core/event/matching/TmfEventMatches.java | 2 +- .../core/event/matching/TmfEventMatching.java | 4 +- .../matching/TmfNetworkEventMatching.java | 4 +- .../filter/model/TmfFilterCompareNode.java | 2 +- .../filter/model/TmfFilterContainsNode.java | 2 +- .../filter/model/TmfFilterEqualsNode.java | 2 +- .../filter/model/TmfFilterEventTypeNode.java | 2 +- .../filter/model/TmfFilterMatchesNode.java | 2 +- .../tmf/core/filter/model/TmfFilterNode.java | 2 +- .../core/filter/model/TmfFilterTreeNode.java | 4 +- .../filter/xml/TmfFilterContentHandler.java | 2 +- .../tmf/core/signal/TmfSignalManager.java | 10 +- .../statesystem/AbstractTmfStateProvider.java | 2 +- .../TmfStateSystemAnalysisModule.java | 2 +- .../statesystem/TmfStateSystemOperations.java | 6 +- .../core/statistics/TmfEventsStatistics.java | 6 +- .../core/statistics/TmfStateStatistics.java | 6 +- .../SyncAlgorithmFullyIncremental.java | 10 +- .../SynchronizationBackend.java | 107 +++++++--------- .../core/timestamp/TmfTimePreferences.java | 2 +- .../core/timestamp/TmfTimestampFormat.java | 2 +- .../linuxtools/tmf/core/trace/TmfTrace.java | 21 ++-- .../tmf/core/trace/TmfTraceManager.java | 2 +- 52 files changed, 206 insertions(+), 256 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core/.classpath b/org.eclipse.linuxtools.tmf.core/.classpath index ad32c83a78..098194ca4b 100644 --- a/org.eclipse.linuxtools.tmf.core/.classpath +++ b/org.eclipse.linuxtools.tmf.core/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.linuxtools.tmf.core/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.tmf.core/.settings/org.eclipse.jdt.core.prefs index 4a0ac9dbf4..ca286c1897 100644 --- a/org.eclipse.linuxtools.tmf.core/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.tmf.core/.settings/org.eclipse.jdt.core.prefs @@ -6,9 +6,9 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -24,7 +24,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod= org.eclipse.jdt.core.compiler.problem.discouragedReference=error org.eclipse.jdt.core.compiler.problem.emptyStatement=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=error org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled org.eclipse.jdt.core.compiler.problem.fieldHiding=error @@ -75,7 +75,7 @@ org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning org.eclipse.jdt.core.compiler.problem.redundantNullCheck=error -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=error org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=error org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=error @@ -110,7 +110,7 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=error org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 diff --git a/org.eclipse.linuxtools.tmf.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.core/META-INF/MANIFEST.MF index 151937282e..1ce0fe7d67 100644 --- a/org.eclipse.linuxtools.tmf.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.core/META-INF/MANIFEST.MF @@ -7,7 +7,7 @@ Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.linuxtools.tmf.core;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.tmf.core.Activator Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, org.eclipse.linuxtools.ctf.core;bundle-version="3.0.0" diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/analysis/TmfAnalysisType.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/analysis/TmfAnalysisType.java index 3a5a78aace..757d90786c 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/analysis/TmfAnalysisType.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/analysis/TmfAnalysisType.java @@ -71,7 +71,7 @@ public final class TmfAnalysisType { * The mapping of available trace type IDs to their corresponding * configuration element */ - private final Map fAnalysisTypeAttributes = new HashMap(); + private final Map fAnalysisTypeAttributes = new HashMap<>(); private static TmfAnalysisType fInstance = null; @@ -84,7 +84,7 @@ public final class TmfAnalysisType { public static IConfigurationElement[] getTypeElements() { IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID); - List typeElements = new LinkedList(); + List typeElements = new LinkedList<>(); for (IConfigurationElement element : elements) { if (element.getName().equals(MODULE_ELEM)) { typeElements.add(element); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/component/TmfProviderManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/component/TmfProviderManager.java index 63d7d4376d..b07783dea1 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/component/TmfProviderManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/component/TmfProviderManager.java @@ -40,7 +40,7 @@ public class TmfProviderManager { // ------------------------------------------------------------------------ private static Map, List> fProviders = - new HashMap, List>(); + new HashMap<>(); /** * Registers [provider] as a provider of [eventType] @@ -85,7 +85,7 @@ public class TmfProviderManager { public static TmfEventProvider[] getProviders(Class eventType) { List list = fProviders.get(eventType); if (list == null) { - list = new ArrayList(); + list = new ArrayList<>(); } TmfEventProvider[] result = new TmfEventProvider[list.size()]; return list.toArray(result); @@ -107,7 +107,7 @@ public class TmfProviderManager { return getProviders(eventType); } TmfEventProvider[] list = getProviders(eventType); - List result = new ArrayList(); + List result = new ArrayList<>(); if (list != null) { for (TmfEventProvider provider : list) { if (provider.getClass() == providerType) { diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedEventRequest.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedEventRequest.java index 5b1c5688cb..91d787cdff 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedEventRequest.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfCoalescedEventRequest.java @@ -36,7 +36,7 @@ public class TmfCoalescedEventRequest extends TmfEventRequest { // ------------------------------------------------------------------------ /** The list of coalesced requests */ - private final List fRequests = new ArrayList(); + private final List fRequests = new ArrayList<>(); /** * We do not use super.fRange, because in the case of coalesced requests, diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfRequestExecutor.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfRequestExecutor.java index d62fcb7d1a..b3d9028942 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfRequestExecutor.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/request/TmfRequestExecutor.java @@ -56,8 +56,8 @@ public class TmfRequestExecutor implements Executor { private final String fExecutorName; // The request queues - private final Queue fForegroundTasks = new ArrayBlockingQueue(100); - private final Queue fBackgroundTasks = new ArrayBlockingQueue(100); + private final Queue fForegroundTasks = new ArrayBlockingQueue<>(100); + private final Queue fBackgroundTasks = new ArrayBlockingQueue<>(100); // The tasks private TmfEventThread fActiveTask; diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java index 093615b481..fec8dc4c1f 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java @@ -44,7 +44,7 @@ abstract class Attribute { this.parent = parent; this.quark = quark; this.name = name; - this.subAttributes = new ArrayList(); + this.subAttributes = new ArrayList<>(); } /** @@ -118,7 +118,7 @@ abstract class Attribute { * @return */ String[] getFullAttribute() { - LinkedList list = new LinkedList(); + LinkedList list = new LinkedList<>(); Attribute curNode = this; /* Add recursive parents to the list, but stop at the root node */ @@ -200,7 +200,7 @@ final class AlphaNumAttribute extends Attribute { AlphaNumAttribute(Attribute parent, String name, int quark) { super(parent, name, quark); - this.subAttributesMap = new HashMap(); + this.subAttributesMap = new HashMap<>(); } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java index 88f9c5f5fa..73ced1eec2 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java @@ -70,7 +70,7 @@ public final class AttributeTree { /* Message for exceptions, shouldn't be externalized */ final String errorMessage = "The attribute tree file section is either invalid or corrupted."; //$NON-NLS-1$ - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); byte[] curByteArray; String curFullString; String[] curStringArray; @@ -143,12 +143,10 @@ public final class AttributeTree { * @return The total number of bytes written. */ int writeSelf(File file, long pos) { - RandomAccessFile raf = null; int total = 0; byte[] curByteArray; - try { - raf = new RandomAccessFile(file, "rw"); //$NON-NLS-1$ + try (RandomAccessFile raf = new RandomAccessFile(file, "rw");) { //$NON-NLS-1$ raf.seek(pos); /* Write the almost-magic number */ @@ -186,14 +184,6 @@ public final class AttributeTree { } catch (IOException e) { e.printStackTrace(); - } finally { - if (raf != null) { - try { - raf.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } } return total; } @@ -329,7 +319,7 @@ public final class AttributeTree { */ List getSubAttributes(int attributeQuark, boolean recursive) throws AttributeNotFoundException { - List listOfChildren = new ArrayList(); + List listOfChildren = new ArrayList<>(); Attribute startingAttribute; /* Check if the quark is valid */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java index eb368500ca..4a27539e68 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java @@ -235,9 +235,9 @@ public class StateSystem implements ITmfStateSystemBuilder { @Override public List getQuarks(String... pattern) { - List quarks = new LinkedList(); - List prefix = new LinkedList(); - List suffix = new LinkedList(); + List quarks = new LinkedList<>(); + List prefix = new LinkedList<>(); + List suffix = new LinkedList<>(); boolean split = false; String[] prefixStr; String[] suffixStr; @@ -506,7 +506,7 @@ public class StateSystem implements ITmfStateSystemBuilder { throw new StateSystemDisposedException(); } - List stateInfo = new ArrayList(getNbAttributes()); + List stateInfo = new ArrayList<>(getNbAttributes()); /* Bring the size of the array to the current number of attributes */ for (int i = 0; i < getNbAttributes(); i++) { @@ -611,7 +611,7 @@ public class StateSystem implements ITmfStateSystemBuilder { } /* Get the initial state at time T1 */ - intervals = new ArrayList(); + intervals = new ArrayList<>(); currentInterval = querySingleState(t1, attributeQuark); intervals.add(currentInterval); @@ -657,7 +657,7 @@ public class StateSystem implements ITmfStateSystemBuilder { } /* Get the initial state at time T1 */ - intervals = new ArrayList(); + intervals = new ArrayList<>(); currentInterval = querySingleState(t1, attributeQuark); intervals.add(currentInterval); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java index 276446c80c..84bfb24747 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java @@ -54,9 +54,9 @@ class TransientState { TransientState(IStateHistoryBackend backend) { this.backend = backend; isActive = true; - ongoingStateInfo = new ArrayList(); - ongoingStateStartTimes = new ArrayList(); - stateValueTypes = new ArrayList(); + ongoingStateInfo = new ArrayList<>(); + ongoingStateStartTimes = new ArrayList<>(); + stateValueTypes = new ArrayList<>(); if (backend != null) { latestTime = backend.getStartTime(); @@ -117,9 +117,9 @@ class TransientState { */ synchronized void replaceOngoingState(List newStateIntervals) { int size = newStateIntervals.size(); - ongoingStateInfo = new ArrayList(size); - ongoingStateStartTimes = new ArrayList(size); - stateValueTypes = new ArrayList(size); + ongoingStateInfo = new ArrayList<>(size); + ongoingStateStartTimes = new ArrayList<>(size); + stateValueTypes = new ArrayList<>(size); for (ITmfStateInterval interval : newStateIntervals) { ongoingStateInfo.add(interval.getStateValue()); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java index 61d999613e..5777826c75 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java @@ -83,7 +83,7 @@ public class InMemoryBackend implements IStateHistoryBackend { public InMemoryBackend(long startTime) { this.startTime = startTime; this.latestTime = startTime; - this.intervals = new TreeSet(END_COMPARATOR); + this.intervals = new TreeSet<>(END_COMPARATOR); } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java index 2a06d2d116..d2eca6af6a 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java @@ -70,7 +70,7 @@ abstract class HTNode { this.stringSectionOffset = config.getBlockSize(); this.isDone = false; - this.intervals = new ArrayList(); + this.intervals = new ArrayList<>(); } /** diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java index 9faa62b36b..576a2d4e7b 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java @@ -91,7 +91,7 @@ class HistoryTree { config = conf; treeEnd = conf.getTreeStart(); nodeCount = 0; - latestBranch = new ArrayList(); + latestBranch = new ArrayList<>(); /* Prepare the IO object */ treeIO = new HT_IO(config, true); @@ -128,57 +128,53 @@ class HistoryTree { throw new IOException("Empty target file"); //$NON-NLS-1$ } - FileInputStream fis = new FileInputStream(existingStateFile); - ByteBuffer buffer = ByteBuffer.allocate(TREE_HEADER_SIZE); - FileChannel fc = fis.getChannel(); - buffer.order(ByteOrder.LITTLE_ENDIAN); - buffer.clear(); - fc.read(buffer); - buffer.flip(); + try (FileInputStream fis = new FileInputStream(existingStateFile); + FileChannel fc = fis.getChannel();) { - /* - * Check the magic number to make sure we're opening the right type of - * file - */ - res = buffer.getInt(); - if (res != HISTORY_FILE_MAGIC_NUMBER) { - fc.close(); - fis.close(); - throw new IOException("Wrong magic number"); //$NON-NLS-1$ - } + ByteBuffer buffer = ByteBuffer.allocate(TREE_HEADER_SIZE); - res = buffer.getInt(); /* File format version number */ - if (res != FILE_VERSION) { - fc.close(); - fis.close(); - throw new IOException("Mismatching History Tree file format versions"); //$NON-NLS-1$ - } + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.clear(); + fc.read(buffer); + buffer.flip(); - res = buffer.getInt(); /* Event handler's version number */ - if (res != expProviderVersion && - expProviderVersion != ITmfStateProvider.IGNORE_PROVIDER_VERSION) { /* - * The existing history was built using an event handler that doesn't - * match the current one in the framework. - * - * Information could be all wrong. Instead of keeping an incorrect - * history file, a rebuild is done. + * Check the magic number to make sure we're opening the right type + * of file */ - fc.close(); - fis.close(); - throw new IOException("Mismatching event handler versions"); //$NON-NLS-1$ - } + res = buffer.getInt(); + if (res != HISTORY_FILE_MAGIC_NUMBER) { + throw new IOException("Wrong magic number"); //$NON-NLS-1$ + } - bs = buffer.getInt(); /* Block Size */ - maxc = buffer.getInt(); /* Max nb of children per node */ + res = buffer.getInt(); /* File format version number */ + if (res != FILE_VERSION) { + throw new IOException("Mismatching History Tree file format versions"); //$NON-NLS-1$ + } - this.nodeCount = buffer.getInt(); - rootNodeSeqNb = buffer.getInt(); - startTime = buffer.getLong(); + res = buffer.getInt(); /* Event handler's version number */ + if (res != expProviderVersion && + expProviderVersion != ITmfStateProvider.IGNORE_PROVIDER_VERSION) { + /* + * The existing history was built using an event handler that + * doesn't match the current one in the framework. + * + * Information could be all wrong. Instead of keeping an + * incorrect history file, a rebuild is done. + */ + throw new IOException("Mismatching event handler versions"); //$NON-NLS-1$ + } + + bs = buffer.getInt(); /* Block Size */ + maxc = buffer.getInt(); /* Max nb of children per node */ + + this.nodeCount = buffer.getInt(); + rootNodeSeqNb = buffer.getInt(); + startTime = buffer.getLong(); + + this.config = new HTConfig(existingStateFile, bs, maxc, expProviderVersion, startTime); + } - this.config = new HTConfig(existingStateFile, bs, maxc, expProviderVersion, startTime); - fc.close(); - fis.close(); /* * FIXME We close fis here and the TreeIO will then reopen the same * file, not extremely elegant. But how to pass the information here to @@ -194,8 +190,6 @@ class HistoryTree { * with was is actually in the root node. */ if (startTime != latestBranch.get(0).getNodeStart()) { - fc.close(); - fis.close(); throw new IOException("Inconsistent start times in the" + //$NON-NLS-1$ "history file, it might be corrupted."); //$NON-NLS-1$ } @@ -211,7 +205,6 @@ class HistoryTree { * The greatest timestamp present in the history tree */ void closeTree(long requestedEndTime) { - FileChannel fc; ByteBuffer buffer; int i, res; @@ -230,13 +223,12 @@ class HistoryTree { treeIO.writeNode(latestBranch.get(i)); } - fc = treeIO.getFcOut(); - buffer = ByteBuffer.allocate(TREE_HEADER_SIZE); - buffer.order(ByteOrder.LITTLE_ENDIAN); - buffer.clear(); + try (FileChannel fc = treeIO.getFcOut();) { + buffer = ByteBuffer.allocate(TREE_HEADER_SIZE); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.clear(); - /* Save the config of the tree to the header of the file */ - try { + /* Save the config of the tree to the header of the file */ fc.position(0); buffer.putInt(HISTORY_FILE_MAGIC_NUMBER); @@ -261,12 +253,12 @@ class HistoryTree { /* done writing the file header */ } catch (IOException e) { - /* We should not have any problems at this point... */ - } finally { - try { - fc.close(); - } catch (IOException e) { - } + /* + * If we were able to write so far, there should not be any problem + * at this point... + */ + // FIXME still, the IOException should be propagated upwards + throw new RuntimeException(); } return; } @@ -353,7 +345,7 @@ class HistoryTree { private void rebuildLatestBranch(int rootNodeSeqNb) throws ClosedChannelException { HTNode nextChildNode; - this.latestBranch = new ArrayList(); + this.latestBranch = new ArrayList<>(); nextChildNode = treeIO.readNode(rootNodeSeqNb); latestBranch.add((CoreNode) nextChildNode); @@ -486,7 +478,7 @@ class HistoryTree { /* Rebuild a new latestBranch */ depth = latestBranch.size(); - latestBranch = new ArrayList(); + latestBranch = new ArrayList<>(); latestBranch.add(newRootNode); for (i = 1; i < depth + 1; i++) { prevNode = latestBranch.get(i - 1); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java index fd3e939cee..4c1695fcc9 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java @@ -66,7 +66,7 @@ public final class ThreadedHistoryTreeBackend extends HistoryTreeBackend throws IOException { super(newStateFile, blockSize, maxChildren, providerVersion, startTime); - intervalQueue = new ArrayBlockingQueue(queueSize); + intervalQueue = new ArrayBlockingQueue<>(queueSize); shtThread = new Thread(this, "History Tree Thread"); //$NON-NLS-1$ shtThread.start(); } @@ -94,7 +94,7 @@ public final class ThreadedHistoryTreeBackend extends HistoryTreeBackend int providerVersion, int queueSize) throws IOException { super(newStateFile, providerVersion, startTime); - intervalQueue = new ArrayBlockingQueue(queueSize); + intervalQueue = new ArrayBlockingQueue<>(queueSize); shtThread = new Thread(this, "History Tree Thread"); //$NON-NLS-1$ shtThread.start(); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java index 4a978b17e0..bd37954809 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java @@ -70,8 +70,7 @@ public class PartialHistoryBackend implements IStateHistoryBackend { private final IStateHistoryBackend innerHistory; /** Checkpoints map, */ - private final TreeMap checkpoints = - new TreeMap(); + private final TreeMap checkpoints = new TreeMap<>(); /** Latch tracking if the initial checkpoint registration is done */ private final CountDownLatch checkpointsReady = new CountDownLatch(1); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/mipmap/AbstractTmfMipmapStateProvider.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/mipmap/AbstractTmfMipmapStateProvider.java index a83d6bb981..859bb933af 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/mipmap/AbstractTmfMipmapStateProvider.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/mipmap/AbstractTmfMipmapStateProvider.java @@ -75,7 +75,7 @@ public abstract class AbstractTmfMipmapStateProvider extends AbstractTmfStatePro /** * Map of mipmap features per attribute. The map's key is the base attribute quark. */ - private Map> featureMap = new HashMap>(); + private Map> featureMap = new HashMap<>(); // ------------------------------------------------------------------------ // Constructor @@ -161,7 +161,7 @@ public abstract class AbstractTmfMipmapStateProvider extends AbstractTmfStatePro if (features != null) { return features; } - features = new LinkedHashSet(); + features = new LinkedHashSet<>(); if (value.isNull()) { return features; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/mipmap/TmfMipmapFeature.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/mipmap/TmfMipmapFeature.java index d687e7cd2e..8942f40e66 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/mipmap/TmfMipmapFeature.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/mipmap/TmfMipmapFeature.java @@ -38,13 +38,13 @@ public abstract class TmfMipmapFeature implements ITmfMipmapFeature { /** The current start time for the state value */ protected long currentStartTime; /** The list of ongoing state intervals per mipmap level */ - protected List> intervals = new ArrayList>(); + protected List> intervals = new ArrayList<>(); /** The state system used to store the mipmap attributes */ protected ITmfStateSystemBuilder ss; private int mipmapResolution; private int mipmapQuark; - private List levelQuarks = new ArrayList(); + private List levelQuarks = new ArrayList<>(); /** * Constructor diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/indexer/BTreeNodeCache.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/indexer/BTreeNodeCache.java index c03ba077cf..a0b8488564 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/indexer/BTreeNodeCache.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/indexer/BTreeNodeCache.java @@ -42,7 +42,7 @@ public class BTreeNodeCache { * kept at the front of the double-ended queue and the least recently used * node is kept at the back. */ - private final Deque fCachedNodes = new ArrayDeque(CACHE_SIZE); + private final Deque fCachedNodes = new ArrayDeque<>(CACHE_SIZE); private int fCcheMisses = 0; diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/indexer/TmfMemoryIndex.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/indexer/TmfMemoryIndex.java index 03fbcb2972..62ad4ff762 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/indexer/TmfMemoryIndex.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/indexer/TmfMemoryIndex.java @@ -37,7 +37,7 @@ public class TmfMemoryIndex implements ITmfCheckpointIndex, ICheckpointCollectio * @param trace the trace */ public TmfMemoryIndex(ITmfTrace trace) { - fCheckpoints = new ArrayList(); + fCheckpoints = new ArrayList<>(); } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java index 1e35af3073..116f268825 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java @@ -46,10 +46,10 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements private String fName, fId; private boolean fAutomatic = false, fStarted = false; private ITmfTrace fTrace; - private final Map fParameters = new HashMap(); - private final List fParameterNames = new ArrayList(); - private final List fOutputs = new ArrayList(); - private List fParameterProviders = new ArrayList(); + private final Map fParameters = new HashMap<>(); + private final List fParameterNames = new ArrayList<>(); + private final List fOutputs = new ArrayList<>(); + private List fParameterProviders = new ArrayList<>(); private Job fJob = null; private final Object syncObj = new Object(); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisManager.java index 9569bdae40..20fdfe421a 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisManager.java @@ -34,9 +34,9 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; */ public class TmfAnalysisManager { - private static final Map fAnalysisModules = new HashMap(); - private static final Map>> fParameterProviders = new HashMap>>(); - private static final Map, IAnalysisParameterProvider> fParamProviderInstances = new HashMap, IAnalysisParameterProvider>(); + private static final Map fAnalysisModules = new HashMap<>(); + private static final Map>> fParameterProviders = new HashMap<>(); + private static final Map, IAnalysisParameterProvider> fParamProviderInstances = new HashMap<>(); /** * Gets all available analysis module helpers @@ -66,7 +66,7 @@ public class TmfAnalysisManager { */ public static Map getAnalysisModules(Class traceclass) { Map allModules = getAnalysisModules(); - Map map = new HashMap(); + Map map = new HashMap<>(); for (IAnalysisModuleHelper module : allModules.values()) { if (module.appliesToTraceType(traceclass)) { map.put(module.getId(), module); @@ -114,7 +114,7 @@ public class TmfAnalysisManager { * @return A parameter provider if one applies to the trace, null otherwise */ public static List getParameterProviders(IAnalysisModule module, ITmfTrace trace) { - List providerList = new ArrayList(); + List providerList = new ArrayList<>(); synchronized (fParameterProviders) { if (!fParameterProviders.containsKey(module.getId())) { return providerList; diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/TmfEventProvider.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/TmfEventProvider.java index 5d1a6783d7..0716386a1d 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/TmfEventProvider.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/TmfEventProvider.java @@ -64,8 +64,7 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent /** List of coalesced requests * @since 3.0*/ - protected final List fPendingCoalescedRequests = - new ArrayList(); + protected final List fPendingCoalescedRequests = new ArrayList<>(); /** The type of event handled by this provider * @since 3.0*/ @@ -97,7 +96,7 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent public TmfEventProvider() { super(); fQueueSize = DEFAULT_QUEUE_SIZE; - fDataQueue = new LinkedBlockingQueue(fQueueSize); + fDataQueue = new LinkedBlockingQueue<>(fQueueSize); fExecutor = new TmfRequestExecutor(); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java index afe436d121..5ebd93406e 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java @@ -33,7 +33,7 @@ public abstract class CtfIteratorManager { /* * The map of traces to trace managers. */ - private static HashMap map = new HashMap(); + private static HashMap map = new HashMap<>(); /** * Registers a trace to the iterator manager, the trace can now get @@ -120,8 +120,8 @@ class CtfTraceManager { private final Random fRnd; public CtfTraceManager(CtfTmfTrace trace) { - fMap = new HashMap(); - fRandomAccess = new ArrayList(); + fMap = new HashMap<>(); + fRandomAccess = new ArrayList<>(); fRnd = new Random(System.nanoTime()); fTrace = trace; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java index 2265ce91e7..59423d37be 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java @@ -158,7 +158,7 @@ public class CtfTmfEvent extends TmfEvent @Override public Set listCustomAttributes() { if (fDeclaration == null) { - return new HashSet(); + return new HashSet<>(); } return fDeclaration.getCustomAttributes(); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventFactory.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventFactory.java index fc8b905f31..a7832ca996 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventFactory.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventFactory.java @@ -130,7 +130,7 @@ public final class CtfTmfEventFactory { * mess, and put them into something ITmfEventField can cope with. */ private static CtfTmfEventField[] parseFields(EventDefinition eventDef) { - List fields = new ArrayList(); + List fields = new ArrayList<>(); StructDefinition structFields = eventDef.getFields(); for (Map.Entry entry : structFields.getDefinitions().entrySet()) { diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java index 242731eef1..77b6276a14 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java @@ -153,7 +153,7 @@ public abstract class CtfTmfEventField extends TmfEventField { String curFieldName = null; Definition curFieldDef; CtfTmfEventField curField; - List list = new ArrayList(); + List list = new ArrayList<>(); /* Recursively parse the fields */ for (Entry entry : strDef.getDefinitions().entrySet()) { curFieldName = entry.getKey(); @@ -293,7 +293,7 @@ final class CTFIntegerArrayField extends CtfTmfEventField { @Override public synchronized String getFormattedValue() { if (formattedValue == null) { - List strings = new ArrayList(); + List strings = new ArrayList<>(); for (long value : getValue()) { strings.add(IntegerDefinition.formatNumber(value, base, signed)); } @@ -333,7 +333,7 @@ final class CTFArrayField extends CtfTmfEventField { @Override public synchronized String getFormattedValue() { if (formattedValue == null) { - List strings = new ArrayList(); + List strings = new ArrayList<>(); for (CtfTmfEventField element : getValue()) { strings.add(element.getFormattedValue()); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java index 4123369cc0..3e1d9b8cfe 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java @@ -64,7 +64,7 @@ public class TmfEventField implements ITmfEventField { /* Fill the fFieldNames and fNameMapping structures */ final int nbFields = (fFields != null) ? fFields.length : 0; fFieldNames = new String[nbFields]; - fNameMapping = new HashMap(); + fNameMapping = new HashMap<>(); for (int i = 0; i < nbFields; i++) { final String curName = fFields[i].getName(); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java index f89fc5dd82..b2c3f8e0f6 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java @@ -44,7 +44,7 @@ public final class TmfEventTypeManager { * The singleton constructor */ private TmfEventTypeManager() { - fEventTypes = new HashMap>(); + fEventTypes = new HashMap<>(); } /** @@ -70,7 +70,7 @@ public final class TmfEventTypeManager { public synchronized void add(final String context, final ITmfEventType type) { HashMap types = fEventTypes.get(context); if (types == null) { - types = new HashMap(); + types = new HashMap<>(); } types.put(type.getName(), type); fEventTypes.put(context, types); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfEventMatches.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfEventMatches.java index 8cf3e5ec24..1eb0bfdacc 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfEventMatches.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfEventMatches.java @@ -36,7 +36,7 @@ public class TmfEventMatches implements IMatchProcessingUnit { * Constructor */ public TmfEventMatches() { - fMatches = new ArrayList(); + fMatches = new ArrayList<>(); } /** diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfEventMatching.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfEventMatching.java index ec5d1e9531..a7fcf7377d 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfEventMatching.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfEventMatching.java @@ -56,9 +56,9 @@ public abstract class TmfEventMatching implements ITmfEventMatching { */ private final IMatchProcessingUnit fMatches; - private static final Map> fMatchDefinitions = new HashMap>(); + private static final Map> fMatchDefinitions = new HashMap<>(); - private final Map fMatchMap = new HashMap(); + private final Map fMatchMap = new HashMap<>(); /** * Constructor with multiple traces and a match processing object diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfNetworkEventMatching.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfNetworkEventMatching.java index f26ac73f8f..5e75c7d6cc 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfNetworkEventMatching.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/matching/TmfNetworkEventMatching.java @@ -35,12 +35,12 @@ public class TmfNetworkEventMatching extends TmfEventMatching { /** * Hashtables for unmatches incoming events */ - private final List, ITmfEvent>> fUnmatchedIn = new ArrayList, ITmfEvent>>(); + private final List, ITmfEvent>> fUnmatchedIn = new ArrayList<>(); /** * Hashtables for unmatches outgoing events */ - private final List, ITmfEvent>> fUnmatchedOut = new ArrayList, ITmfEvent>>(); + private final List, ITmfEvent>> fUnmatchedOut = new ArrayList<>(); /** * Enum for in and out types diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java index 781268236a..af24a6b9a0 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterCompareNode.java @@ -201,7 +201,7 @@ public class TmfFilterCompareNode extends TmfFilterTreeNode { @Override public List getValidChildren() { - return new ArrayList(0); + return new ArrayList<>(0); } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterContainsNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterContainsNode.java index c0dd25342e..d75708e8c0 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterContainsNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterContainsNode.java @@ -124,7 +124,7 @@ public class TmfFilterContainsNode extends TmfFilterTreeNode { @Override public List getValidChildren() { - return new ArrayList(0); + return new ArrayList<>(0); } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEqualsNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEqualsNode.java index 586b13b2ab..27ce8df549 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEqualsNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEqualsNode.java @@ -124,7 +124,7 @@ public class TmfFilterEqualsNode extends TmfFilterTreeNode { @Override public List getValidChildren() { - return new ArrayList(0); + return new ArrayList<>(0); } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEventTypeNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEventTypeNode.java index ff0791ed25..9134bd1d1f 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEventTypeNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterEventTypeNode.java @@ -105,7 +105,7 @@ public class TmfFilterEventTypeNode extends TmfFilterTreeNode { if (getChildrenCount() == 0) { return super.getValidChildren(); } - return new ArrayList(0); // only one child allowed + return new ArrayList<>(0); // only one child allowed } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterMatchesNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterMatchesNode.java index aad75a0235..fc8b918dd9 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterMatchesNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterMatchesNode.java @@ -120,7 +120,7 @@ public class TmfFilterMatchesNode extends TmfFilterTreeNode { @Override public List getValidChildren() { - return new ArrayList(0); + return new ArrayList<>(0); } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java index fdd1137dd8..ab3eeb6aa9 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterNode.java @@ -83,7 +83,7 @@ public class TmfFilterNode extends TmfFilterTreeNode { if (getChildrenCount() == 0) { return super.getValidChildren(); } - return new ArrayList(0); // only one child allowed + return new ArrayList<>(0); // only one child allowed } @Override diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java index b0f4cdc05c..d6e90d9524 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/model/TmfFilterTreeNode.java @@ -40,7 +40,7 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable }; private ITmfFilterTreeNode parent = null; - private ArrayList children = new ArrayList(); + private ArrayList children = new ArrayList<>(); /** * @param parent @@ -159,7 +159,7 @@ public abstract class TmfFilterTreeNode implements ITmfFilterTreeNode, Cloneable try { TmfFilterTreeNode clone = (TmfFilterTreeNode) super.clone(); clone.parent = null; - clone.children = new ArrayList(children.size()); + clone.children = new ArrayList<>(children.size()); for (ITmfFilterTreeNode child : getChildren()) { clone.addChild(child.clone()); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/xml/TmfFilterContentHandler.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/xml/TmfFilterContentHandler.java index 9cc87af79e..cff55a609d 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/xml/TmfFilterContentHandler.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/filter/xml/TmfFilterContentHandler.java @@ -49,7 +49,7 @@ public class TmfFilterContentHandler extends DefaultHandler { */ public TmfFilterContentHandler() { super(); - fFilterTreeStack = new Stack(); + fFilterTreeStack = new Stack<>(); } /** diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfSignalManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfSignalManager.java index 1ad50f7455..2ec18a84bf 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfSignalManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfSignalManager.java @@ -37,8 +37,8 @@ public class TmfSignalManager { // Note: listeners could be restricted to ITmfComponents but there is no // harm in letting anyone use this since it is not tied to anything but // the signal data type. - private static Map fListeners = new HashMap(); - private static Map fVIPListeners = new HashMap(); + private static Map fListeners = new HashMap<>(); + private static Map fVIPListeners = new HashMap<>(); // If requested, add universal signal tracer // TODO: Temporary solution: should be enabled/disabled dynamically @@ -104,7 +104,7 @@ public class TmfSignalManager { * @return */ private static Method[] getSignalHandlerMethods(Object listener) { - List handlers = new ArrayList(); + List handlers = new ArrayList<>(); Method[] methods = listener.getClass().getMethods(); for (Method method : methods) { if (method.isAnnotationPresent(TmfSignalHandler.class)) { @@ -151,10 +151,10 @@ public class TmfSignalManager { // Build the list of listener methods that are registered for this signal Class signalClass = signal.getClass(); - Map> targets = new HashMap>(); + Map> targets = new HashMap<>(); targets.clear(); for (Map.Entry entry : listeners.entrySet()) { - List matchingMethods = new ArrayList(); + List matchingMethods = new ArrayList<>(); for (Method method : entry.getValue()) { if (method.getParameterTypes()[0].isAssignableFrom(signalClass)) { matchingMethods.add(method); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractTmfStateProvider.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractTmfStateProvider.java index 36eb476cd2..bf48c60661 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractTmfStateProvider.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/AbstractTmfStateProvider.java @@ -67,7 +67,7 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider { Class eventType, String id) { this.trace = trace; this.eventType = eventType; - eventsQueue = new ArrayBlockingQueue(DEFAULT_EVENTS_QUEUE_SIZE); + eventsQueue = new ArrayBlockingQueue<>(DEFAULT_EVENTS_QUEUE_SIZE); ssAssigned = false; String id2 = (id == null ? "Unamed" : id); //$NON-NLS-1$ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java index e480656f2b..6f4b11fe52 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java @@ -138,7 +138,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo @Override public Map getStateSystems() { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put(getId(), fStateSystem); return map; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemOperations.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemOperations.java index c74f1ec087..1de8409012 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemOperations.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemOperations.java @@ -199,9 +199,9 @@ public final class TmfStateSystemOperations { private static List queryAttributeRange(ITmfStateSystem ss, long t1, long t2, int baseQuark, String featureString) throws AttributeNotFoundException, TimeRangeException, StateValueTypeException { - Pair timeRange = new Pair(t1, t2); + Pair timeRange = new Pair<>(t1, t2); int mipmapQuark = -1; - List intervals = new ArrayList(); + List intervals = new ArrayList<>(); try { try { mipmapQuark = ss.getQuarkRelative(baseQuark, featureString); @@ -314,7 +314,7 @@ public final class TmfStateSystemOperations { } long startTime = Math.max(timeRange.getFirst(), Math.min(currentLevelInterval.getEndTime() + 1, timeRange.getSecond())); - return new Pair(startTime, timeRange.getSecond()); + return new Pair<>(startTime, timeRange.getSecond()); } private static boolean isFullyOverlapped(Pair range, diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java index a3673a0431..ad2bfbea50 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java @@ -146,7 +146,7 @@ public class TmfEventsStatistics implements ITmfStatistics { HistogramQueryRequest req = new HistogramQueryRequest(borders, end); sendAndWait(req); - List results = new LinkedList(req.getResults()); + List results = new LinkedList<>(req.getResults()); return results; } @@ -253,7 +253,7 @@ public class TmfEventsStatistics implements ITmfStatistics { public StatsPerTypeRequest(ITmfTrace trace, TmfTimeRange range) { super(trace.getEventType(), range, 0, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.BACKGROUND); - this.stats = new HashMap(); + this.stats = new HashMap<>(); } public Map getResults() { @@ -320,7 +320,7 @@ public class TmfEventsStatistics implements ITmfStatistics { ITmfEventRequest.ExecutionType.BACKGROUND); /* Prepare the results map, with all counts at 0 */ - results = new TreeMap(); + results = new TreeMap<>(); for (long border : borders) { results.put(border, 0L); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java index e8d48b39b4..76ae92c2e7 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java @@ -211,7 +211,7 @@ public class TmfStateStatistics implements ITmfStatistics { @Override public List histogramQuery(final long start, final long end, final int nb) { - final List list = new LinkedList(); + final List list = new LinkedList<>(); final long increment = (end - start) / nb; if (!totalsStats.waitUntilBuilt()) { @@ -277,7 +277,7 @@ public class TmfStateStatistics implements ITmfStatistics { /* We need the complete state history to be built to answer this. */ typesStats.waitUntilBuilt(); - Map map = new HashMap(); + Map map = new HashMap<>(); long endTime = typesStats.getCurrentEndTime(); try { @@ -335,7 +335,7 @@ public class TmfStateStatistics implements ITmfStatistics { // end time, and answer as soon as possible... typesStats.waitUntilBuilt(); - Map map = new HashMap(); + Map map = new HashMap<>(); /* Make sure the start/end times are within the state history, so we * don't get TimeRange exceptions. diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/synchronization/SyncAlgorithmFullyIncremental.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/synchronization/SyncAlgorithmFullyIncremental.java index 7360e7f85f..6cb695ab3f 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/synchronization/SyncAlgorithmFullyIncremental.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/synchronization/SyncAlgorithmFullyIncremental.java @@ -56,7 +56,7 @@ public class SyncAlgorithmFullyIncremental extends SynchronizationAlgorithm { * Initialization of the attributes */ public SyncAlgorithmFullyIncremental() { - fSyncs = new LinkedList(); + fSyncs = new LinkedList<>(); } /** @@ -162,7 +162,7 @@ public class SyncAlgorithmFullyIncremental extends SynchronizationAlgorithm { @Override public Map> getStats() { - Map> statmap = new LinkedHashMap>(); + Map> statmap = new LinkedHashMap<>(); for (ConvexHull traceSync : fSyncs) { statmap.put(traceSync.getReferenceTrace() + " <==> " + traceSync.getOtherTrace(), traceSync.getStats()); //$NON-NLS-1$ } @@ -189,13 +189,13 @@ public class SyncAlgorithmFullyIncremental extends SynchronizationAlgorithm { * The list of meaningful points on the upper hull (received by the * reference trace, below in a graph) */ - private final LinkedList fUpperBoundList = new LinkedList(); + private final LinkedList fUpperBoundList = new LinkedList<>(); /** * The list of meaninful points on the lower hull (sent by the reference * trace, above in a graph) */ - private final LinkedList fLowerBoundList = new LinkedList(); + private final LinkedList fLowerBoundList = new LinkedList<>(); /** Points forming the line with maximum slope */ private final SyncPoint[] fLmax; @@ -213,7 +213,7 @@ public class SyncAlgorithmFullyIncremental extends SynchronizationAlgorithm { private String fReferenceTrace = "", fOtherTrace = ""; //$NON-NLS-1$//$NON-NLS-2$ private SyncQuality fQuality; - private Map fStats = new LinkedHashMap(); + private Map fStats = new LinkedHashMap<>(); /** * Initialization of the attributes diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/synchronization/SynchronizationBackend.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/synchronization/SynchronizationBackend.java index 1950b3aa73..534410a779 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/synchronization/SynchronizationBackend.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/synchronization/SynchronizationBackend.java @@ -90,37 +90,31 @@ public class SynchronizationBackend { return; } - FileInputStream fis = new FileInputStream(syncFile); - ByteBuffer buffer = ByteBuffer.allocate(HEADER_SIZE); - FileChannel fc = fis.getChannel(); - buffer.clear(); - fc.read(buffer); - buffer.flip(); - - /* - * Check the magic number,to make sure we're opening the right type of - * file - */ - res = buffer.getInt(); - if (res != SYNC_FILE_MAGIC_NUMBER) { - fc.close(); - fis.close(); - throw new IOException("Selected file does not" + //$NON-NLS-1$ - "look like a synchronization file"); //$NON-NLS-1$ - } + try (FileInputStream fis = new FileInputStream(syncFile); + FileChannel fc = fis.getChannel();) { + ByteBuffer buffer = ByteBuffer.allocate(HEADER_SIZE); + buffer.clear(); + fc.read(buffer); + buffer.flip(); - res = buffer.getInt(); /* Major version number */ - if (res != FILE_VERSION) { - fc.close(); - fis.close(); - throw new IOException("Select synchronization file is of an older " //$NON-NLS-1$ - + "format. Synchronization will have to be computed again."); //$NON-NLS-1$ - } + /* + * Check the magic number,to make sure we're opening the right type + * of file + */ + res = buffer.getInt(); + if (res != SYNC_FILE_MAGIC_NUMBER) { + throw new IOException("Selected file does not" + //$NON-NLS-1$ + "look like a synchronization file"); //$NON-NLS-1$ + } - res = buffer.getInt(); /* Minor version number */ + res = buffer.getInt(); /* Major version number */ + if (res != FILE_VERSION) { + throw new IOException("Select synchronization file is of an older " //$NON-NLS-1$ + + "format. Synchronization will have to be computed again."); //$NON-NLS-1$ + } - fc.close(); - fis.close(); + res = buffer.getInt(); /* Minor version number */ + } } /** @@ -136,24 +130,18 @@ public class SynchronizationBackend { return null; } - /* Set the position after the header */ - FileInputStream fis = new FileInputStream(fSyncFile); - FileChannel fc = fis.getChannel().position(HEADER_SIZE); + try (/* Set the position after the header */ + FileInputStream fis = new FileInputStream(fSyncFile); + FileChannel fc = fis.getChannel().position(HEADER_SIZE); + /* Read the input stream */ + ObjectInputStream ois = new ObjectInputStream(fis);) { - /* Read the input stream */ - ObjectInputStream ois = new ObjectInputStream(fis); - SyncAlgorithmFullyIncremental syncAlgo = null; - try { - syncAlgo = (SyncAlgorithmFullyIncremental) ois.readObject(); + return (SynchronizationAlgorithm) ois.readObject(); } catch (ClassNotFoundException e) { - + return null; } - ois.close(); - fc.close(); - fis.close(); - return syncAlgo; } /** @@ -170,20 +158,13 @@ public class SynchronizationBackend { return; } - FileChannel fc; - FileOutputStream fos; - ObjectOutputStream oos; - ByteBuffer buffer; - int res; - - fos = new FileOutputStream(fSyncFile, false); - fc = fos.getChannel(); + /* Save the header of the file */ + try (FileOutputStream fos = new FileOutputStream(fSyncFile, false); + FileChannel fc = fos.getChannel();) { - buffer = ByteBuffer.allocate(HEADER_SIZE); - buffer.clear(); + ByteBuffer buffer = ByteBuffer.allocate(HEADER_SIZE); + buffer.clear(); - /* Save the header of the file */ - try { fc.position(0); buffer.putInt(SYNC_FILE_MAGIC_NUMBER); @@ -191,26 +172,22 @@ public class SynchronizationBackend { buffer.putInt(FILE_VERSION); buffer.flip(); - res = fc.write(buffer); + int res = fc.write(buffer); assert (res <= HEADER_SIZE); /* done writing the file header */ fc.position(HEADER_SIZE); - oos = new ObjectOutputStream(fos); - oos.writeObject(syncAlgo); - oos.close(); + try (ObjectOutputStream oos = new ObjectOutputStream(fos);) { + oos.writeObject(syncAlgo); + } + } catch (FileNotFoundException e) { + /* Send this upwards */ + throw e; } catch (IOException e) { - /* We should not have any problems at this point... */ + /* Handle other cases of IOException's */ Activator.logError("Error saving trace synchronization data", e); //$NON-NLS-1$ - } finally { - try { - fc.close(); - fos.close(); - } catch (IOException e) { - Activator.logError("Error closing synchronization file", e); //$NON-NLS-1$ - } } return; diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimePreferences.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimePreferences.java index 900208ab9a..be8e17d31f 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimePreferences.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimePreferences.java @@ -137,7 +137,7 @@ public class TmfTimePreferences { } private static Map getPreferenceMap(boolean defaultValues) { - Map prefsMap = new HashMap(); + Map prefsMap = new HashMap<>(); IEclipsePreferences prefs = defaultValues ? DefaultScope.INSTANCE.getNode(Activator.PLUGIN_ID) : InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); prefToMap(prefs, prefsMap, ITmfTimePreferencesConstants.SUBSEC, SUBSEC_DEFAULT); prefToMap(prefs, prefsMap, ITmfTimePreferencesConstants.TIME_DELIMITER, TIME_DELIMITER_DEFAULT); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java index bbf2d34290..efb9d9108c 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java @@ -222,7 +222,7 @@ public class TmfTimestampFormat extends SimpleDateFormat { private String fPattern; // The timestamp pattern - private List fSupplPatterns = new ArrayList(); + private List fSupplPatterns = new ArrayList<>(); /** * The supplementary pattern letters. Can be redefined by sub-classes diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java index 5dcd7574eb..a60b55b2d7 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java @@ -18,7 +18,6 @@ package org.eclipse.linuxtools.tmf.core.trace; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; @@ -133,12 +132,12 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { * @since 2.0 */ protected final Map fStateSystems = - new LinkedHashMap(); + new LinkedHashMap<>(); private ITmfTimestampTransform fTsTransform; private final Map fAnalysisModules = - new LinkedHashMap(); + new LinkedHashMap<>(); private static final String SYNCHRONIZATION_FORMULA_FILE = "sync_formula"; //$NON-NLS-1$ @@ -358,7 +357,7 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { */ @Override public Map getAnalysisModules(Class moduleclass) { - Map modules = new HashMap(); + Map modules = new HashMap<>(); for (Entry entry : fAnalysisModules.entrySet()) { if (moduleclass.isAssignableFrom(entry.getValue().getClass())) { modules.put(entry.getKey(), moduleclass.cast(entry.getValue())); @@ -882,18 +881,12 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { File sync_file = getSyncFormulaFile(); if (sync_file != null && sync_file.exists()) { - try { - FileInputStream fis = new FileInputStream(sync_file); - ObjectInputStream ois = new ObjectInputStream(fis); + try (FileInputStream fis = new FileInputStream(sync_file); + ObjectInputStream ois = new ObjectInputStream(fis);) { + fTsTransform = (ITmfTimestampTransform) ois.readObject(); - ois.close(); - fis.close(); - } catch (ClassNotFoundException e1) { - fTsTransform = TmfTimestampTransform.IDENTITY; - } catch (FileNotFoundException e1) { - fTsTransform = TmfTimestampTransform.IDENTITY; - } catch (IOException e1) { + } catch (ClassNotFoundException | IOException e) { fTsTransform = TmfTimestampTransform.IDENTITY; } } else { diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java index affd091bd2..257539beeb 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java @@ -64,7 +64,7 @@ public final class TmfTraceManager { // ------------------------------------------------------------------------ private TmfTraceManager() { - fTraces = new LinkedHashMap(); + fTraces = new LinkedHashMap<>(); TmfSignalManager.registerVIP(this); } -- 2.34.1