Skip to content

Commit

Permalink
fixup! simplify instanceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed Oct 8, 2024
1 parent 6999304 commit 158a74c
Show file tree
Hide file tree
Showing 58 changed files with 111 additions and 197 deletions.
3 changes: 1 addition & 2 deletions java/code/src/com/redhat/rhn/domain/action/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,9 @@ public boolean allServersFinished() {
*/
@Override
public boolean equals(final Object other) {
if (!(other instanceof Action)) {
if (!(other instanceof Action castOther)) {
return false;
}
Action castOther = (Action) other;
return new EqualsBuilder().append(this.getId(), castOther.getId())
.append(this.getOrg(), castOther.getOrg())
.append(this.getName(), castOther.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ public void setActionType(ActionType actionTypeIn) {
*/
@Override
public boolean equals(final Object other) {
if (!(other instanceof ActionArchType)) {
if (!(other instanceof ActionArchType castOther)) {
return false;
}
ActionArchType castOther = (ActionArchType) other;
return new EqualsBuilder().append(archTypeId, castOther.archTypeId).append(
actionStyle, castOther.actionStyle).isEquals();
}
Expand Down
3 changes: 1 addition & 2 deletions java/code/src/com/redhat/rhn/domain/action/ActionChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,9 @@ public String getLocalizedModified() {
*/
@Override
public boolean equals(Object other) {
if (!(other instanceof ActionChain)) {
if (!(other instanceof ActionChain otherActionChain)) {
return false;
}
ActionChain otherActionChain = (ActionChain) other;
return new EqualsBuilder()
.append(getLabel(), otherActionChain.getLabel())
.isEquals();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,9 @@ public void setSortOrder(Integer sortOrderIn) {
*/
@Override
public boolean equals(final Object other) {
if (!(other instanceof ActionChainEntry)) {
if (!(other instanceof ActionChainEntry otherActionChainEntry)) {
return false;
}
ActionChainEntry otherActionChainEntry = (ActionChainEntry) other;

return new EqualsBuilder()
.append(getActionId(), otherActionChainEntry.getActionId())
.append(getActionChainId(), otherActionChainEntry.getActionChainId())
Expand Down
3 changes: 1 addition & 2 deletions java/code/src/com/redhat/rhn/domain/action/ActionStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof ActionStatus)) {
if (!(o instanceof ActionStatus other)) {
return false;
}
ActionStatus other = (ActionStatus)o;
return new EqualsBuilder().append(this.getName(), other.getName())
.isEquals();
}
Expand Down
3 changes: 1 addition & 2 deletions java/code/src/com/redhat/rhn/domain/action/ActionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@ public void setMaintenancemodeOnly(boolean maintenancemodeOnlyIn) {
*/
@Override
public boolean equals(Object o) {
if (o == null || !(o instanceof ActionType)) {
if (!(o instanceof ActionType other)) {
return false;
}
ActionType other = (ActionType)o;
return new EqualsBuilder().append(this.getId(), other.getId())
.append(this.getName(), other.getName())
.append(this.getLabel(), other.getLabel())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ public boolean equals(Object oIn) {
if (this == oIn) {
return true;
}

if (!(oIn instanceof AppStreamAction)) {
if (!(oIn instanceof AppStreamAction that)) {
return false;
}

AppStreamAction that = (AppStreamAction) oIn;

return new EqualsBuilder().appendSuper(super.equals(oIn)).append(details, that.details).isEquals();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,9 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}

if (!(o instanceof SubscribeChannelsActionDetails)) {
if (!(o instanceof SubscribeChannelsActionDetails that)) {
return false;
}

SubscribeChannelsActionDetails that = (SubscribeChannelsActionDetails) o;

return new EqualsBuilder()
.append(baseChannel, that.baseChannel)
.append(channels, that.channels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,9 @@ public void setServer(Server serverIn) {
*/
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof ConfigChannelAssociation)) {
if (!(obj instanceof ConfigChannelAssociation r)) {
return false;
}

ConfigChannelAssociation r = (ConfigChannelAssociation) obj;

return new EqualsBuilder().append(r.getCreated(), getCreated())
.append(r.getModified(), getModified())
.append(r.getServer(), getServer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ public void setFileType(String fileTypeIn) {
*/
@Override
public boolean equals(final Object other) {
if (other == null || !(other instanceof ConfigDateFileAction)) {
if (!(other instanceof ConfigDateFileAction castOther)) {
return false;
}
ConfigDateFileAction castOther = (ConfigDateFileAction)other;
return new EqualsBuilder().append(getParentAction(), castOther.getParentAction())
.append(fileName, castOther.getFileName()).isEquals();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package com.redhat.rhn.domain.action.config.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.redhat.rhn.domain.action.Action;
import com.redhat.rhn.domain.action.ActionFactory;
Expand All @@ -43,11 +43,11 @@ public void testCreate() throws Exception {
ConfigRevisionActionTest.createTestRevision(usr, testAction);
ActionFactory.save(testAction);
flushAndEvict(testAction);
/**
/*
* Get action back out of db and make sure it committed correctly
*/
Action same = ActionFactory.lookupById(testAction.getId());
assertTrue(same instanceof ConfigAction);
assertInstanceOf(ConfigAction.class, same);
ConfigAction sameAction = (ConfigAction) same;

assertNotNull(sameAction.getConfigRevisionActions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package com.redhat.rhn.domain.action.config.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.redhat.rhn.domain.action.Action;
import com.redhat.rhn.domain.action.ActionFactory;
Expand Down Expand Up @@ -90,7 +90,7 @@ public void testLookupConfigRevision() throws Exception {
ActionFactory.TYPE_CONFIGFILES_DEPLOY);

assertNotNull(a);
assertTrue(a instanceof ConfigAction);
assertInstanceOf(ConfigAction.class, a);
assertNotNull(a.getActionType());

ConfigAction a2 = (ConfigAction) ActionFactoryTest.createAction(user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package com.redhat.rhn.domain.action.config.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.redhat.rhn.domain.action.Action;
import com.redhat.rhn.domain.action.ActionFactory;
Expand All @@ -43,7 +43,7 @@ public void testLookup() throws Exception {
//look it back up
Action lookedUp = ActionFactory.lookupByUserAndId(user, a.getId());
assertNotNull(lookedUp);
assertTrue(lookedUp instanceof ConfigUploadAction);
assertInstanceOf(ConfigUploadAction.class, lookedUp);

//see that we have an expected collection
Set<ConfigFileNameAssociation> set =
Expand All @@ -53,7 +53,7 @@ public void testLookup() throws Exception {

//check one of the collection elements
Object o = set.iterator().next();
assertTrue(o instanceof ConfigFileNameAssociation);
assertInstanceOf(ConfigFileNameAssociation.class, o);
assertEquals(((ConfigFileNameAssociation)o).getParentAction(), lookedUp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package com.redhat.rhn.domain.action.config.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.redhat.rhn.domain.action.Action;
import com.redhat.rhn.domain.action.ActionFactory;
Expand Down Expand Up @@ -52,7 +52,7 @@ public void testLookupConfigUploadAction() throws Exception {
Action a = ActionFactory.lookupById(id);

assertNotNull(a);
assertTrue(a instanceof ConfigUploadMtimeAction);
assertInstanceOf(ConfigUploadMtimeAction.class, a);
ConfigUploadMtimeAction cfa = (ConfigUploadMtimeAction) a;
assertNotNull(cfa.getConfigDateFileActions());
ConfigDateFileAction cfda = (ConfigDateFileAction)
Expand Down Expand Up @@ -98,12 +98,12 @@ public void testCreate() throws Exception {

ActionFactory.save(testAction);
flushAndEvict(testAction);
/**
/*
* Get action back out of db and make sure it committed correctly
*/
Action same = ActionFactory.lookupById(testAction.getId());

assertTrue(same instanceof ConfigUploadMtimeAction);
assertInstanceOf(ConfigUploadMtimeAction.class, same);
ConfigUploadMtimeAction sameAction = (ConfigUploadMtimeAction) same;

assertNotNull(sameAction.getConfigDateFileActions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof DistUpgradeChannelTask)) {
if (!(obj instanceof DistUpgradeChannelTask other)) {
return false;
}
DistUpgradeChannelTask other = (DistUpgradeChannelTask) obj;
if (channel == null) {
if (other.channel != null) {
return false;
Expand All @@ -115,9 +114,6 @@ else if (!channel.equals(other.channel)) {
else if (!details.equals(other.details)) {
return false;
}
if (task != other.task) {
return false;
}
return true;
return task == other.task;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package com.redhat.rhn.domain.action.kickstart.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.redhat.rhn.domain.action.Action;
import com.redhat.rhn.domain.action.ActionFactory;
Expand Down Expand Up @@ -52,7 +52,7 @@ public void testLookupKickstartAction() throws Exception {
Action a = ActionFactory.lookupById(id);

assertNotNull(a);
assertTrue(a instanceof KickstartInitiateAction);
assertInstanceOf(KickstartInitiateAction.class, a);
KickstartAction k = (KickstartAction) a;
assertNotNull(k.getKickstartActionDetails().getStaticDevice());
assertNotNull(k.getEarliestAction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ public void setParameter(String p) {
*/
@Override
public boolean equals(final Object other) {
if (!(other instanceof PackageActionDetails)) {
if (!(other instanceof PackageActionDetails castOther)) {
return false;
}
PackageActionDetails castOther = (PackageActionDetails) other;
return new EqualsBuilder().append((getParentAction() == null ? null :
getParentAction().getId()),
(castOther.getParentAction() == null ? null :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,9 @@ public void setSuggested(PackageName s) {
*/
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof PackageActionRemovalFailure)) {
if (!(obj instanceof PackageActionRemovalFailure p)) {
return false;
}

PackageActionRemovalFailure p = (PackageActionRemovalFailure) obj;

return new EqualsBuilder().append(this.getAction(), p.getAction())
.append(this.getServer(), p.getServer())
.append(this.getPackageName(), p.getPackageName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,9 @@ public void setServer(Server s) {
*/
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof PackageActionResult)) {
if (!(obj instanceof PackageActionResult p)) {
return false;
}

PackageActionResult p = (PackageActionResult) obj;

return new EqualsBuilder().append(this.getDetails(), p.getDetails())
.append(this.getServer(), p.getServer())
.append(this.getResultCode(), p.getResultCode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package com.redhat.rhn.domain.action.rhnpackage.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.redhat.rhn.domain.action.Action;
import com.redhat.rhn.domain.action.ActionFactory;
Expand Down Expand Up @@ -56,14 +56,14 @@ public void testLookupPackageAction() throws Exception {
UserTestUtils.createOrg("testOrg" + this.getClass().getSimpleName())),
ActionFactory.TYPE_PACKAGES_VERIFY);
assertNotNull(newA.getId());
assertTrue(newA instanceof PackageAction);
assertInstanceOf(PackageAction.class, newA);
PackageAction p = (PackageAction) newA;
assertNotNull(p.getDetails());
assertEquals(p.getDetails().size(), 1);
PackageActionDetails firstDetail =
(PackageActionDetails) p.getDetails().toArray()[0];

/**
/*
* Make sure PackageEvr was set & committed correctly
*/
Set details = p.getDetails();
Expand Down Expand Up @@ -108,11 +108,11 @@ public void testCreatePackageUpdateAction() throws Exception {
ActionFactory.save(testAction);
flushAndEvict(testAction);

/**
/*
* Get action back out of db and make sure it committed correctly
*/
Action same = ActionFactory.lookupById(testAction.getId());
assertTrue(same instanceof PackageAction);
assertInstanceOf(PackageAction.class, same);
PackageAction sameAction = (PackageAction) same;

assertNotNull(sameAction.getDetails());
Expand All @@ -133,11 +133,11 @@ public void testCreatePackageUpdateActionWithName() throws Exception {
PackageActionDetailsTest.createTestDetailsWithName(usr, testAction);
ActionFactory.save(testAction);
flushAndEvict(testAction);
/**
/*
* Get action back out of db and make sure it committed correctly
*/
Action same = ActionFactory.lookupById(testAction.getId());
assertTrue(same instanceof PackageAction);
assertInstanceOf(PackageAction.class, same);
PackageAction sameAction = (PackageAction) same;

assertNotNull(sameAction.getDetails());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Optional<List<StateResult>> getResult() {
try {
@SuppressWarnings("unchecked")
Map<String, Map<String, Object>> payload = YamlHelper.loadAs(getOutputContents(), Map.class);
payload.entrySet().stream().forEach(e -> result.add(new StateResult(e)));
payload.entrySet().forEach(e -> result.add(new StateResult(e)));
}
catch (ConstructorException ce) {
return Optional.empty();
Expand All @@ -136,12 +136,9 @@ public Optional<List<StateResult>> getResult() {

@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof ApplyStatesActionResult)) {
if (!(obj instanceof ApplyStatesActionResult result)) {
return false;
}

ApplyStatesActionResult result = (ApplyStatesActionResult) obj;

return new EqualsBuilder()
.append(this.getActionApplyStatesId(), result.getActionApplyStatesId())
.append(this.getServerId(), result.getServerId())
Expand Down
Loading

0 comments on commit 158a74c

Please sign in to comment.