/*
 * Copyright 2017-present The Material Motion Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.android.material.motion.streams;

import android.support.annotation.VisibleForTesting;
import android.util.Property;

import java.util.WeakHashMap;

public final class ReactiveProperties {

  private static final WeakHashMap<Object[], UnscopedReactiveProperty> reactiveProperties =
    new WeakHashMap<>();
  private static final Object[] key = new Object[2];

  @VisibleForTesting
  public ReactiveProperties() {
    throw new UnsupportedOperationException();
  }

  public static <T, O> ReactiveProperty<T> of(O target, Property<O, T> property) {
    key[0] = target;
    key[1] = property;

    //noinspection unchecked
    UnscopedReactiveProperty<O, T> reactiveProperty = reactiveProperties.get(key);
    if (reactiveProperty == null) {
      reactiveProperty = new UnscopedReactiveProperty<>(target, property);
      reactiveProperties.put(new Object[]{target, property}, reactiveProperty);
    }
    return reactiveProperty;
  }
}

@@ -741,16 +741,63 @@
 esting;%0A
+import android.support.v4.util.SimpleArrayMap;%0A
 import a
@@ -936,20 +936,41 @@
 ject
-%5B%5D, Unscoped
+, SimpleArrayMap%3CProperty%3C?, ?%3E, 
 Reac
@@ -981,26 +981,28 @@
 Property
-%3E reactive
+%3C?%3E%3E%3E target
 Properti
@@ -1005,20 +1005,16 @@
 erties =
-%0A   
  new Wea
@@ -1030,61 +1030,8 @@
 %3E();
-%0A  private static final Object%5B%5D key = new Object%5B2%5D;
 %0A%0A  
@@ -1224,90 +1224,235 @@
     
-key%5B0%5D = target;%0A    key%5B1%5D = property;%0A%0A    //noinspection unchecked%0A    Unscoped
+SimpleArrayMap%3CProperty%3C?, ?%3E, ReactiveProperty%3C?%3E%3E properties = targetProperties.get(target);%0A    if (properties == null) %7B%0A      properties = new SimpleArrayMap%3C%3E();%0A      targetProperties.put(target, properties);%0A    %7D%0A%0A    
 Reac
@@ -1464,20 +1464,17 @@
 roperty%3C
-O, T
+?
 %3E reacti
@@ -1486,25 +1486,17 @@
 perty = 
-reactiveP
+p
 ropertie
@@ -1505,10 +1505,15 @@
 get(
-ke
+propert
 y);%0A
@@ -1625,33 +1625,25 @@
 rty);%0A      
-reactiveP
+p
 roperties.pu
@@ -1648,37 +1648,16 @@
 put(
-new Object%5B%5D%7Btarget, 
 property
 %7D, r
@@ -1652,17 +1652,16 @@
 property
-%7D
 , reacti
@@ -1683,18 +1683,70 @@
   %7D%0A
-    return
+%0A    //noinspection unchecked%0A    return (ReactiveProperty%3CT%3E)
  rea

Fix ReactiveProperties map.