Skip to content

Commit

Permalink
chore(java17): use Java 17 'instanceof' syntax (#3094)
Browse files Browse the repository at this point in the history
* chore(cleanup): remove unnecessary Exception thrown in tests
* chore(java17): use instanceof pattern variable

Other Java 17 feature: No relevant candidate was found for conversion to Record
  • Loading branch information
educhastenier authored Oct 4, 2024
1 parent 21fa3e3 commit b70aa6e
Show file tree
Hide file tree
Showing 55 changed files with 74 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof Employee)) {
if (!(obj instanceof Employee other)) {
return false;
}
final Employee other = (Employee) obj;
if (experience != other.experience) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ public List<Status> getStatuses() {
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof ValidationStatus))
if (!(o instanceof ValidationStatus that))
return false;
ValidationStatus that = (ValidationStatus) o;
return Objects.equals(statusList, that.statusList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ protected ValidationStatus validate(BusinessObjectModel bom) {
for (BusinessObject bo : bom.getBusinessObjects()) {
List<Field> boFields = bo.getFields();
for (Field boField : boFields) {
if (boField instanceof RelationField) {
RelationField relationField = (RelationField) boField;
if (boField instanceof RelationField relationField) {
String fieldReferenceQualifiedName = relationField.getReference().getQualifiedName();
String boQualifiedName = bo.getQualifiedName();
if (relationField.getType() == AGGREGATION && fieldReferenceQualifiedName.equals(boQualifiedName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ protected ValidationStatus validate(BusinessObjectModel bom) {
for (BusinessObject bo : businessObjects)
fieldList.addAll(bo.getFields());
for (Field field : fieldList) {
if (field instanceof RelationField) {
RelationField relationField = (RelationField) field;
if (field instanceof RelationField relationField) {
if (relationField.getType() == AGGREGATION) {
aggregatedBusinessObjects.add(relationField.getReference());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ public int hashCode() {
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof ArchivedFlowNodeInstanceImpl))
if (!(o instanceof ArchivedFlowNodeInstanceImpl that))
return false;
if (!super.equals(o))
return false;
ArchivedFlowNodeInstanceImpl that = (ArchivedFlowNodeInstanceImpl) o;
return Objects.equals(parentContainerId, that.parentContainerId) &&
Objects.equals(rootContainerId, that.rootContainerId) &&
Objects.equals(processDefinitionId, that.processDefinitionId) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,10 @@ public int hashCode() {
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof FlowNodeInstanceImpl))
if (!(o instanceof FlowNodeInstanceImpl that))
return false;
if (!super.equals(o))
return false;
FlowNodeInstanceImpl that = (FlowNodeInstanceImpl) o;
return Objects.equals(parentContainerId, that.parentContainerId) &&
Objects.equals(rootContainerId, that.rootContainerId) &&
Objects.equals(processDefinitionId, that.processDefinitionId) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ public void setFormRequired(boolean required) {
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof FormMapping))
if (!(o instanceof FormMapping that))
return false;
FormMapping that = (FormMapping) o;
return Objects.equals(id, that.id) &&
Objects.equals(processDefinitionId, that.processDefinitionId) &&
Objects.equals(lastUpdatedBy, that.lastUpdatedBy) &&
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ public void setParentProcessDefinitionId(final Long parentProcessDefinitionId) {
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof SExpressionContext))
if (!(o instanceof SExpressionContext that))
return false;
SExpressionContext that = (SExpressionContext) o;
return Objects.equals(time, that.time) &&
Objects.equals(evaluateInDefinition, that.evaluateInDefinition) &&
Objects.equals(containerId, that.containerId) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public Object computeNewValueForLeftOperand(final SOperation operation, final Ob
final String parentPath = xpathExpression.substring(0, xpathExpression.lastIndexOf('/'));
final String attributeName = xpathExpression.substring(xpathExpression.lastIndexOf('/') + 2); // +1 for @
final Node parentNode = (Node) xpath.compile(parentPath).evaluate(document, XPathConstants.NODE);
if (parentNode instanceof Element) {
final Element element = (Element) parentNode;
if (parentNode instanceof Element element) {
if (value instanceof String) {
element.setAttribute(attributeName, getStringValue(value));
} else if (value instanceof Attr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public static List<SOperation> convertOperations(final List<Operation> operation
}

public static SDataDefinition convertDataDefinition(final DataDefinition dataDefinition) {
if (dataDefinition instanceof XMLDataDefinition) {
final XMLDataDefinition xmlDataDef = (XMLDataDefinition) dataDefinition;
if (dataDefinition instanceof XMLDataDefinition xmlDataDef) {
final SXMLDataDefinitionBuilderFactory fact = BuilderFactory.get(SXMLDataDefinitionBuilderFactory.class);
final SXMLDataDefinitionBuilder builder = fact.createNewXMLData(dataDefinition.getName())
.setElement(xmlDataDef.getElement())
Expand All @@ -107,8 +106,7 @@ public static SDataDefinition convertDataDefinition(final DataDefinition dataDef
}
final SDataDefinitionBuilderFactory fact = BuilderFactory.get(SDataDefinitionBuilderFactory.class);
SDataDefinitionBuilder builder;
if (dataDefinition instanceof TextDataDefinition) {
final TextDataDefinition textDataDefinition = (TextDataDefinition) dataDefinition;
if (dataDefinition instanceof TextDataDefinition textDataDefinition) {
builder = fact.createNewTextData(dataDefinition.getName()).setAsLongText(textDataDefinition.isLongText());
} else {
builder = fact.createNewInstance(dataDefinition.getName(), dataDefinition.getClassName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,13 @@ private void initializeActivities(final List<ActivityDefinition> activities2) {
final SActivityDefinitionImpl activity;
if (activityDefinition instanceof AutomaticTaskDefinitionImpl) {
activity = new SAutomaticTaskDefinitionImpl(activityDefinition, transitionsMap);
} else if (activityDefinition instanceof HumanTaskDefinitionImpl) {
} else if (activityDefinition instanceof HumanTaskDefinitionImpl humanTaskDefinitionImpl) {
if (activityDefinition instanceof UserTaskDefinitionImpl) {
activity = new SUserTaskDefinitionImpl((UserTaskDefinition) activityDefinition, transitionsMap);
} else {
activity = new SManualTaskDefinitionImpl((ManualTaskDefinitionImpl) activityDefinition,
transitionsMap);
}
final HumanTaskDefinitionImpl humanTaskDefinitionImpl = (HumanTaskDefinitionImpl) activityDefinition;
final UserFilterDefinition userFilter = humanTaskDefinitionImpl.getUserFilter();
final SHumanTaskDefinitionImpl sHumanTaskDefinitionImpl = (SHumanTaskDefinitionImpl) activity;
if (userFilter != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5884,10 +5884,9 @@ public List<User> getPossibleUsersOfHumanTask(final long processDefinitionId, fi
final SProcessDefinition processDefinition = processDefinitionService
.getProcessDefinition(processDefinitionId);
final SFlowNodeDefinition flowNode = processDefinition.getProcessContainer().getFlowNode(humanTaskName);
if (!(flowNode instanceof SHumanTaskDefinition)) {
if (!(flowNode instanceof SHumanTaskDefinition humanTask)) {
return Collections.emptyList();
}
final SHumanTaskDefinition humanTask = (SHumanTaskDefinition) flowNode;
final String actorName = humanTask.getActorName();
final List<Long> userIds = getUserIdsForActor(serviceAccessor, processDefinitionId, actorName, startIndex,
maxResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ public SFlowNodeInstance toFlowNodeInstance(final long processDefinitionId, fina
final long parentProcessInstanceId, final boolean createInnerActivity, final int loopCounter,
final SStateCategory stateCategory,
final long relatedActivityInstanceId) throws SActorNotFoundException, SActivityReadException {
if (!createInnerActivity && sFlowNodeDefinition instanceof SActivityDefinition) {
final SActivityDefinition activityDefinition = (SActivityDefinition) sFlowNodeDefinition;
if (!createInnerActivity && sFlowNodeDefinition instanceof SActivityDefinition activityDefinition) {
final SLoopCharacteristics loopCharacteristics = activityDefinition.getLoopCharacteristics();
if (loopCharacteristics != null) {
SFlowNodeInstanceBuilder builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
import org.bonitasoft.engine.core.process.instance.model.business.data.SProcessMultiRefBusinessDataInstance;
import org.bonitasoft.engine.core.process.instance.model.business.data.SRefBusinessDataInstance;
import org.bonitasoft.engine.core.process.instance.model.event.SBoundaryEventInstance;
import org.bonitasoft.engine.core.process.instance.model.event.SCatchEventInstance;
import org.bonitasoft.engine.core.process.instance.model.event.SIntermediateCatchEventInstance;
import org.bonitasoft.engine.core.process.instance.model.event.SThrowEventInstance;
import org.bonitasoft.engine.data.instance.api.DataInstanceContainer;
Expand Down Expand Up @@ -203,10 +202,9 @@ public void mapDataOutputOfMultiInstance(final SProcessDefinition processDefinit
if (activityDefinition != null) {// can be null if the activity was added in runtime
try {
final SLoopCharacteristics loopCharacteristics = activityDefinition.getLoopCharacteristics();
if (loopCharacteristics instanceof SMultiInstanceLoopCharacteristics
if (loopCharacteristics instanceof SMultiInstanceLoopCharacteristics miLoop
&& ((SMultiInstanceLoopCharacteristics) loopCharacteristics)
.getDataOutputItemRef() != null) {
final SMultiInstanceLoopCharacteristics miLoop = (SMultiInstanceLoopCharacteristics) loopCharacteristics;
final SBusinessDataDefinition businessData = processContainer
.getBusinessDataDefinition(miLoop.getLoopDataOutputRef());
if (businessData == null) {
Expand Down Expand Up @@ -340,8 +338,7 @@ public void registerWaitingEvent(final SProcessDefinition processDefinition,
final SFlowNodeInstance flowNodeInstance)
throws SActivityStateExecutionException {
// handle catch event
if (flowNodeInstance instanceof SIntermediateCatchEventInstance) {
final SCatchEventInstance intermediateCatchEventInstance = (SCatchEventInstance) flowNodeInstance;
if (flowNodeInstance instanceof SIntermediateCatchEventInstance intermediateCatchEventInstance) {
// handleEventTriggerInstances(processDefinition, intermediateCatchEventInstance);
final SFlowElementContainerDefinition processContainer = processDefinition.getProcessContainer();
final SIntermediateCatchEventDefinition intermediateCatchEventDefinition = (SIntermediateCatchEventDefinition) processContainer
Expand All @@ -352,8 +349,7 @@ public void registerWaitingEvent(final SProcessDefinition processDefinition,
} catch (final SBonitaException e) {
throw new SActivityStateExecutionException("unable to handle catch event " + flowNodeInstance, e);
}
} else if (flowNodeInstance instanceof SReceiveTaskInstance) {
final SReceiveTaskInstance receiveTaskInstance = (SReceiveTaskInstance) flowNodeInstance;
} else if (flowNodeInstance instanceof SReceiveTaskInstance receiveTaskInstance) {
final SFlowElementContainerDefinition processContainer = processDefinition.getProcessContainer();
final SReceiveTaskDefinition receiveTaskIDefinition = (SReceiveTaskDefinition) processContainer
.getFlowNode(receiveTaskInstance
Expand Down Expand Up @@ -433,10 +429,9 @@ public void updateExpectedDuration(final SProcessDefinition processDefinition,
final SFlowElementContainerDefinition processContainer = processDefinition.getProcessContainer();
final SFlowNodeDefinition flowNodeDefinition = processContainer
.getFlowNode(flowNodeInstance.getFlowNodeDefinitionId());
if (!(flowNodeDefinition instanceof SHumanTaskDefinition)) {
if (!(flowNodeDefinition instanceof SHumanTaskDefinition humanTaskDefinition)) {
return;
}
SHumanTaskDefinition humanTaskDefinition = (SHumanTaskDefinition) flowNodeDefinition;
final SExpression expectedDurationExpression = humanTaskDefinition.getExpectedDuration();
if (expectedDurationExpression == null) {
return;
Expand Down Expand Up @@ -490,8 +485,7 @@ public void executeOperations(final SProcessDefinition processDefinition, final
final SFlowElementContainerDefinition processContainer = processDefinition.getProcessContainer();
final SFlowNodeDefinition flowNode = processContainer
.getFlowNode(activityInstance.getFlowNodeDefinitionId());
if (flowNode instanceof SActivityDefinition) {
final SActivityDefinition activityDefinition = (SActivityDefinition) flowNode;
if (flowNode instanceof SActivityDefinition activityDefinition) {
final List<SOperation> sOperations = activityDefinition.getSOperations();
final SExpressionContext sExpressionContext = new SExpressionContext(activityInstance.getId(),
DataInstanceContainer.ACTIVITY_INSTANCE.name(),
Expand All @@ -505,8 +499,7 @@ public void executeOperations(final SProcessDefinition processDefinition, final

public void handleThrowEvent(final SProcessDefinition processDefinition, final SFlowNodeInstance flowNodeInstance)
throws SActivityStateExecutionException {
if (flowNodeInstance instanceof SThrowEventInstance) {
final SThrowEventInstance throwEventInstance = (SThrowEventInstance) flowNodeInstance;
if (flowNodeInstance instanceof SThrowEventInstance throwEventInstance) {
final SFlowElementContainerDefinition processContainer = processDefinition.getProcessContainer();
final SThrowEventDefinition eventDefinition = (SThrowEventDefinition) processContainer
.getFlowNode(throwEventInstance.getFlowNodeDefinitionId());
Expand Down Expand Up @@ -755,8 +748,7 @@ private int getNumberOfInstanceToCreateFromSimpleData(final SProcessDefinition p
DataInstanceContainer.ACTIVITY_INSTANCE.name(), parentContainerResolver);
if (loopDataInput != null) {
final Serializable value = loopDataInput.getValue();
if (value instanceof List) {
final List<?> loopDataInputCollection = (List<?>) value;
if (value instanceof List<?> loopDataInputCollection) {
return loopDataInputCollection.size();
}
throw new SActivityStateExecutionException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public StateCode execute(final SProcessDefinition processDefinition, final SFlow
final SLoopActivityInstance loopActivity = (SLoopActivityInstance) activityInstanceService
.getFlowNodeInstance(flowNodeInstance.getId());
final SLoopCharacteristics loopCharacteristics = activity.getLoopCharacteristics();
if (loopCharacteristics instanceof SStandardLoopCharacteristics) {
final SStandardLoopCharacteristics standardLoop = (SStandardLoopCharacteristics) loopCharacteristics;
if (loopCharacteristics instanceof SStandardLoopCharacteristics standardLoop) {
final SExpression loopMax = ((SStandardLoopCharacteristics) loopCharacteristics).getLoopMax();
Integer intLoopMax;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public StateCode execute(final SProcessDefinition processDefinition, final SFlow
final SActivityDefinition activity = (SActivityDefinition) processContainer
.getFlowNode(flowNodeInstance.getFlowNodeDefinitionId());
final SLoopCharacteristics loopCharacteristics = activity.getLoopCharacteristics();
if (loopCharacteristics instanceof SMultiInstanceLoopCharacteristics) {
final SMultiInstanceLoopCharacteristics miLoop = (SMultiInstanceLoopCharacteristics) loopCharacteristics;
if (loopCharacteristics instanceof SMultiInstanceLoopCharacteristics miLoop) {
final SExpression loopCardinality = miLoop.getLoopCardinality();
int numberOfInstanceMax = -1;
if (loopCardinality != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ protected long getAuthorId(long containerId, String containerType) {
try {
if (loggedUserFromSession <= 0 && DataInstanceContainer.ACTIVITY_INSTANCE.name().equals(containerType)) {
SActivityInstance activityInstance = activityInstanceService.getActivityInstance(containerId);
if (activityInstance instanceof SHumanTaskInstance) {
SHumanTaskInstance instance = (SHumanTaskInstance) activityInstance;
if (activityInstance instanceof SHumanTaskInstance instance) {
return instance.getAssigneeId();
}
}
Expand Down
Loading

0 comments on commit b70aa6e

Please sign in to comment.