import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
this(modelFactory, node, container, new ArrayList<ITmfXmlStateAttribute>(), eventField);
}
- private TmfXmlReadWriteStateValue(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes, String eventField) {
+ private TmfXmlReadWriteStateValue(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes, @Nullable String eventField) {
super(modelFactory, node, container, attributes, eventField);
}
@Override
- protected ITmfStateSystemBuilder getStateSystem() {
+ protected @Nullable ITmfStateSystemBuilder getStateSystem() {
return (ITmfStateSystemBuilder) super.getStateSystem();
}
/* Process the XML Element state value */
String type = node.getAttribute(TmfXmlStrings.TYPE);
String value = getSsContainer().getAttributeValue(node.getAttribute(TmfXmlStrings.VALUE));
+ if (value == null) {
+ throw new IllegalStateException();
+ }
switch (type) {
case TmfXmlStrings.TYPE_INT: {
List<Element> children = XmlUtils.getChildElements(node);
List<ITmfXmlStateAttribute> childAttributes = new ArrayList<>();
for (Element child : children) {
+ if (child == null) {
+ continue;
+ }
ITmfXmlStateAttribute queryAttribute = modelFactory.createStateAttribute(child, getSsContainer());
childAttributes.add(queryAttribute);
}
@Override
protected void processValue(int quark, long timestamp, ITmfStateValue value) throws AttributeNotFoundException, TimeRangeException, StateValueTypeException {
+ ITmfStateSystemBuilder ss = getStateSystem();
+ if (ss == null) {
+ throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
+ }
switch (getStackType()) {
case POP:
- getStateSystem().popAttribute(timestamp, quark);
+ ss.popAttribute(timestamp, quark);
break;
case PUSH:
- getStateSystem().pushAttribute(timestamp, value, quark);
+ ss.pushAttribute(timestamp, value, quark);
break;
case NULL:
case PEEK:
default:
- getStateSystem().modifyAttribute(timestamp, value, quark);
+ ss.modifyAttribute(timestamp, value, quark);
break;
}
}
@Override
protected void incrementValue(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
- getStateSystem().incrementAttribute(timestamp, quark);
+ ITmfStateSystemBuilder ss = getStateSystem();
+ if (ss == null) {
+ throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
+ }
+ ss.incrementAttribute(timestamp, quark);
+ }
+ }
+
+ private static @Nullable ITmfStateValue incrementByType(int quark, ITmfStateSystem ss, ITmfStateValue stateValue) throws AttributeNotFoundException {
+ ITmfStateValue value = null;
+ switch (stateValue.getType()) {
+ case LONG: {
+ long incrementLong = stateValue.unboxLong();
+ ITmfStateValue currentState = ss.queryOngoingState(quark);
+ long currentValue = (currentState.isNull() ? 0 : currentState.unboxLong());
+ value = TmfStateValue.newValueLong(incrementLong + currentValue);
+ return value;
+ }
+ case INTEGER: {
+ int increment = stateValue.unboxInt();
+ ITmfStateValue currentState = ss.queryOngoingState(quark);
+ int currentValue = (currentState.isNull() ? 0 : currentState.unboxInt());
+ value = TmfStateValue.newValueInt(increment + currentValue);
+ return value;
+ }
+ case DOUBLE:
+ case NULL:
+ case STRING:
+ default:
}
+ return value;
}
/* This state value uses a constant value, defined in the XML */
}
@Override
- public ITmfStateValue getValue(ITmfEvent event) {
+ public ITmfStateValue getValue(@Nullable ITmfEvent event) {
return fValue;
}
@Override
public void incrementValue(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
ITmfStateSystem ss = getStateSystem();
- switch (fValue.getType()) {
- case LONG: {
- long incrementLong = fValue.unboxLong();
- long currentValue = ss.queryOngoingState(quark).unboxLong();
- ITmfStateValue value = TmfStateValue.newValueLong(incrementLong + currentValue);
- processValue(quark, timestamp, value);
- return;
+ if (ss == null) {
+ throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
}
- case INTEGER: {
- int increment = fValue.unboxInt();
- int currentValue = ss.queryOngoingState(quark).unboxInt();
- ITmfStateValue value = TmfStateValue.newValueInt(increment + currentValue);
+ ITmfStateValue value = incrementByType(quark, ss, fValue);
+ if (value != null) {
processValue(quark, timestamp, value);
- break;
- }
- case DOUBLE:
- case NULL:
- case STRING:
- default:
+ } else {
Activator.logWarning("TmfXmlStateValue: The increment value is not a number type"); //$NON-NLS-1$
- break;
}
}
+
}
/* The state value uses the value of an event field */
}
@Override
- public ITmfStateValue getValue(ITmfEvent event) {
+ public ITmfStateValue getValue(@Nullable ITmfEvent event) {
if (event == null) {
Activator.logWarning("XML State value: requested an event field, but event is null"); //$NON-NLS-1$
return TmfStateValue.nullValue();
@Override
public void incrementValue(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
ITmfStateSystem ss = getSsContainer().getStateSystem();
- ITmfStateValue incrementValue = getValue(event);
- switch (incrementValue.getType()) {
- case INTEGER: {
- int increment = incrementValue.unboxInt();
- int currentValue = ss.queryOngoingState(quark).unboxInt();
- ITmfStateValue value = TmfStateValue.newValueInt(increment + currentValue);
- processValue(quark, timestamp, value);
- break;
+ if (ss == null) {
+ throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
}
- case LONG: {
- long incrementLong = incrementValue.unboxLong();
- long currentValue = ss.queryOngoingState(quark).unboxLong();
- ITmfStateValue value = TmfStateValue.newValueLong(incrementLong + currentValue);
+ ITmfStateValue incrementValue = getValue(event);
+ ITmfStateValue value = incrementByType(quark, ss, incrementValue);
+ if (value != null) {
processValue(quark, timestamp, value);
- break;
- }
- case DOUBLE:
- case NULL:
- case STRING:
- default:
+ } else {
Activator.logWarning(String.format("TmfXmlStateValue: The event field increment %s is not a number type but a %s", fFieldName, incrementValue.getType())); //$NON-NLS-1$
- break;
}
}
}
private class TmfXmlStateValueEventName extends TmfXmlStateValueTypeReadWrite {
@Override
- public ITmfStateValue getValue(ITmfEvent event) {
+ public ITmfStateValue getValue(@Nullable ITmfEvent event) {
if (event == null) {
Activator.logWarning("XML State value: request event name, but event is null"); //$NON-NLS-1$
return TmfStateValue.nullValue();
}
- return TmfStateValue.newValueString(event.getType().getName());
+ return TmfStateValue.newValueString(event.getName());
}
}
private class TmfXmlStateValueDelete extends TmfXmlStateValueTypeReadWrite {
@Override
- public ITmfStateValue getValue(ITmfEvent event) throws AttributeNotFoundException {
+ public ITmfStateValue getValue(@Nullable ITmfEvent event) throws AttributeNotFoundException {
return TmfStateValue.nullValue();
}
}
@Override
- public ITmfStateValue getValue(ITmfEvent event) throws AttributeNotFoundException {
+ public ITmfStateValue getValue(@Nullable ITmfEvent event) throws AttributeNotFoundException {
/* Query the state system for the value */
ITmfStateValue value = TmfStateValue.nullValue();
int quarkQuery = IXmlStateSystemContainer.ROOT_QUARK;
ITmfStateSystem ss = getStateSystem();
+ if (ss == null) {
+ throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
+ }
for (ITmfXmlStateAttribute attribute : fQueryValue) {
quarkQuery = attribute.getAttributeQuark(event, quarkQuery);
*/
if (quarkQuery != IXmlStateSystemContainer.ERROR_QUARK) {
value = ss.queryOngoingState(quarkQuery);
+ if (value == null) {
+ throw new IllegalStateException();
+ }
}
return value;
}
@Override
public void incrementValue(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
ITmfStateSystem ss = getStateSystem();
- ITmfStateValue incrementValue = getValue(event);
- switch (incrementValue.getType()) {
- case INTEGER: {
- int increment = incrementValue.unboxInt();
- int currentValue = ss.queryOngoingState(quark).unboxInt();
- ITmfStateValue value = TmfStateValue.newValueInt(increment + currentValue);
- processValue(quark, timestamp, value);
- break;
+ if (ss == null) {
+ throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
}
- case LONG: {
- long incrementLong = incrementValue.unboxLong();
- long currentValue = ss.queryOngoingState(quark).unboxLong();
- ITmfStateValue value = TmfStateValue.newValueLong(incrementLong + currentValue);
+
+ ITmfStateValue incrementValue = getValue(event);
+ ITmfStateValue value = incrementByType(quark, ss, incrementValue);
+ if (value != null) {
processValue(quark, timestamp, value);
- break;
- }
- case DOUBLE:
- case NULL:
- case STRING:
- default:
+ } else {
Activator.logWarning("TmfXmlStateValue: The query result increment is not a number type"); //$NON-NLS-1$
- break;
}
}
}