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

Commit ef3bbac7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix equals and hash code methods for the Property class" into main am:...

Merge "Fix equals and hash code methods for the Property class" into main am: 8ce40991 am: d540ee85

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3341955



Change-Id: I02fe4d05408f9ca9d7571d4771f802fb8887d2e0
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents b898b15f d540ee85
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -292,6 +292,10 @@ public abstract class PackageManager {
     * <p>
     * The value of a property will only have a single type, as defined by
     * the property itself.
     *
     * <p class="note"><strong>Note:</strong>
     * In android version {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} and earlier,
     * the {@code equals} and {@code hashCode} methods for this class may not function as expected.
     */
    public static final class Property implements Parcelable {
        private static final int TYPE_BOOLEAN = 1;
@@ -523,6 +527,40 @@ public abstract class PackageManager {
                return new Property[size];
            }
        };

        @Override
        public boolean equals(Object obj) {
            if (!(obj instanceof Property)) {
                return false;
            }
            final Property property = (Property) obj;
            return mType == property.mType &&
                    Objects.equals(mName, property.mName) &&
                    Objects.equals(mClassName, property.mClassName) &&
                    Objects.equals(mPackageName, property.mPackageName) &&
                    (mType == TYPE_BOOLEAN ? mBooleanValue == property.mBooleanValue :
                     mType == TYPE_FLOAT ? Float.compare(mFloatValue, property.mFloatValue) == 0 :
                     mType == TYPE_INTEGER ? mIntegerValue == property.mIntegerValue :
                     mType == TYPE_RESOURCE ? mIntegerValue == property.mIntegerValue :
                     mStringValue.equals(property.mStringValue));
        }

        @Override
        public int hashCode() {
            int result = Objects.hash(mName, mType, mClassName, mPackageName);
            if (mType == TYPE_BOOLEAN) {
                result = 31 * result + (mBooleanValue ? 1 : 0);
            } else if (mType == TYPE_FLOAT) {
                result = 31 * result + Float.floatToIntBits(mFloatValue);
            } else if (mType == TYPE_INTEGER) {
                result = 31 * result + mIntegerValue;
            } else if (mType == TYPE_RESOURCE) {
                result = 31 * result + mIntegerValue;
            } else if (mType == TYPE_STRING) {
                result = 31 * result + mStringValue.hashCode();
            }
            return result;
        }
    }

    /**