Loading core/java/android/os/WorkSource.java +15 −4 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ import android.util.proto.ProtoOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Objects; /** * Describes the source of some work that may be done by someone else. Loading Loading @@ -162,9 +161,21 @@ public class WorkSource implements Parcelable { @Override public boolean equals(Object o) { return o instanceof WorkSource && !diff((WorkSource) o) && Objects.equals(mChains, ((WorkSource) o).mChains); if (o instanceof WorkSource) { WorkSource other = (WorkSource) o; if (diff(other)) { return false; } if (mChains != null && !mChains.isEmpty()) { return mChains.equals(other.mChains); } else { return other.mChains == null || other.mChains.isEmpty(); } } return false; } @Override Loading core/tests/coretests/src/android/os/WorkSourceTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -128,6 +128,23 @@ public class WorkSourceTest extends TestCase { assertFalse(ws3.equals(ws1)); } public void testEquals_workChains_nullEmptyAreEquivalent() { // Construct a WorkSource that has no WorkChains, but whose workChains list // is non-null. WorkSource ws1 = new WorkSource(); ws1.add(100); ws1.createWorkChain().addNode(100, null); ws1.getWorkChains().clear(); WorkSource ws2 = new WorkSource(); ws2.add(100); assertEquals(ws1, ws2); ws2.createWorkChain().addNode(100, null); assertFalse(ws1.equals(ws2)); } public void testWorkSourceParcelling() { WorkSource ws = new WorkSource(); Loading Loading
core/java/android/os/WorkSource.java +15 −4 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ import android.util.proto.ProtoOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Objects; /** * Describes the source of some work that may be done by someone else. Loading Loading @@ -162,9 +161,21 @@ public class WorkSource implements Parcelable { @Override public boolean equals(Object o) { return o instanceof WorkSource && !diff((WorkSource) o) && Objects.equals(mChains, ((WorkSource) o).mChains); if (o instanceof WorkSource) { WorkSource other = (WorkSource) o; if (diff(other)) { return false; } if (mChains != null && !mChains.isEmpty()) { return mChains.equals(other.mChains); } else { return other.mChains == null || other.mChains.isEmpty(); } } return false; } @Override Loading
core/tests/coretests/src/android/os/WorkSourceTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -128,6 +128,23 @@ public class WorkSourceTest extends TestCase { assertFalse(ws3.equals(ws1)); } public void testEquals_workChains_nullEmptyAreEquivalent() { // Construct a WorkSource that has no WorkChains, but whose workChains list // is non-null. WorkSource ws1 = new WorkSource(); ws1.add(100); ws1.createWorkChain().addNode(100, null); ws1.getWorkChains().clear(); WorkSource ws2 = new WorkSource(); ws2.add(100); assertEquals(ws1, ws2); ws2.createWorkChain().addNode(100, null); assertFalse(ws1.equals(ws2)); } public void testWorkSourceParcelling() { WorkSource ws = new WorkSource(); Loading