Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 828c910e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Implements HubEndpointSession.equals" into main

parents 46a27ac5 7fde6fc8
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.hardware.location.ContextHubTransactionHelper;
import android.hardware.location.IContextHubTransactionCallback;
import android.util.CloseGuard;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

/**
@@ -160,6 +161,32 @@ public class HubEndpointSession implements AutoCloseable {
        return stringBuilder.toString();
    }

    @Override
    public boolean equals(@Nullable Object object) {
        if (object == this) {
            return true;
        }

        boolean isEqual = false;
        if (object instanceof HubEndpointSession other) {
            isEqual = (other.getId() == mId);
            if (mServiceDescriptor != null) {
                isEqual &= mServiceDescriptor.equals(other.getServiceDescriptor());
            } else {
                isEqual &= (other.getServiceDescriptor() == null);
            }
            isEqual &=
                    mInitiator.equals(other.mInitiator) && mDestination.equals(other.mDestination);
        }

        return isEqual;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mId, mServiceDescriptor, mInitiator, mDestination);
    }

    /** @hide */
    protected void finalize() throws Throwable {
        try {