/*******************************************************************************
- * Copyright (c) 2012, 2015 Ericsson
+ * Copyright (c) 2012, 2016 Ericsson
* Copyright (c) 2010, 2011 École Polytechnique de Montréal
* Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
*
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend;
import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
@Override
public int getQuarkAbsolute(String... attribute)
throws AttributeNotFoundException {
- return getAttributeTree().getQuarkDontAdd(-1, attribute);
+ int quark = getAttributeTree().getQuarkDontAdd(ROOT_ATTRIBUTE, attribute);
+ if (quark == INVALID_ATTRIBUTE) {
+ throw new AttributeNotFoundException(getSSID() + " Path:" + Arrays.toString(attribute)); //$NON-NLS-1$
+ }
+ return quark;
+ }
+
+ @Override
+ public int optQuarkAbsolute(String... attribute) {
+ return getAttributeTree().getQuarkDontAdd(ROOT_ATTRIBUTE, attribute);
}
@Override
public int getQuarkAbsoluteAndAdd(String... attribute) {
- return getAttributeTree().getQuarkAndAdd(-1, attribute);
+ return getAttributeTree().getQuarkAndAdd(ROOT_ATTRIBUTE, attribute);
}
@Override
public int getQuarkRelative(int startingNodeQuark, String... subPath)
throws AttributeNotFoundException {
+ int quark = getAttributeTree().getQuarkDontAdd(startingNodeQuark, subPath);
+ if (quark == INVALID_ATTRIBUTE) {
+ throw new AttributeNotFoundException(getSSID() + " Quark:" + startingNodeQuark + ", SubPath:" + Arrays.toString(subPath)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return quark;
+ }
+
+ @Override
+ public int optQuarkRelative(int startingNodeQuark, String... subPath) {
return getAttributeTree().getQuarkDontAdd(startingNodeQuark, subPath);
}
}
@Override
- public List<Integer> getQuarks(String... pattern) {
- List<Integer> quarks = new LinkedList<>();
+ public List<@NonNull Integer> getQuarks(String... pattern) {
+ List<@NonNull Integer> quarks = new LinkedList<>();
List<String> prefix = new LinkedList<>();
List<String> suffix = new LinkedList<>();
boolean split = false;
return quarks;
}
- try {
- if (prefix.size() == 0) {
- /*
- * If 'prefix' is empty, this means the wildcard was the first
- * element. Look for the root node's sub-attributes.
- */
- startingAttribute = -1;
- } else {
- startingAttribute = getQuarkAbsolute(prefixStr);
+ if (prefix.isEmpty()) {
+ /*
+ * If 'prefix' is empty, this means the wildcard was the first
+ * element. Look for the root node's sub-attributes.
+ */
+ startingAttribute = ROOT_ATTRIBUTE;
+ } else {
+ startingAttribute = optQuarkAbsolute(prefixStr);
+ if (startingAttribute == INVALID_ATTRIBUTE) {
+ /* That attribute path did not exist, return the empty array */
+ return quarks;
}
+ }
+ try {
directChildren = getSubAttributes(startingAttribute, false);
} catch (AttributeNotFoundException e) {
- /* That attribute path did not exist, return the empty array */
- return quarks;
+ /* Should not happen, starting attribute is a valid quark */
+ throw new IllegalStateException();
}
/*
* 'suffix' part of the initial pattern.
*/
for (int childQuark : directChildren) {
- int matchingQuark;
- try {
- matchingQuark = getQuarkRelative(childQuark, suffixStr);
- } catch (AttributeNotFoundException e) {
- continue;
+ int matchingQuark = optQuarkRelative(childQuark, suffixStr);
+ if (matchingQuark != INVALID_ATTRIBUTE) {
+ quarks.add(matchingQuark);
}
- quarks.add(matchingQuark);
}
return quarks;
* @param newStateIntervals
* The new List of state values to use as ongoing state info
*/
- protected void replaceOngoingState(@NonNull List<ITmfStateInterval> newStateIntervals) {
+ protected void replaceOngoingState(@NonNull List<@NonNull ITmfStateInterval> newStateIntervals) {
transState.replaceOngoingState(newStateIntervals);
}
}
final int nbAttr = getNbAttributes();
- List<ITmfStateInterval> stateInfo = new ArrayList<>(nbAttr);
+ List<@Nullable ITmfStateInterval> stateInfo = new ArrayList<>(nbAttr);
/* Bring the size of the array to the current number of attributes */
for (int i = 0; i < nbAttr; i++) {