Files
react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/DynamicFromArray.java
T
Oleksandr Melnykov 6c0f73b322 Format Java code in xplat/js/react-native-github
Summary:
This diff formats the Java class files inside xplat/js/react-native-github. Since google-java-format was enabled in D16071401 we want to codemode the existing code so that users don't have to deal with formatter lint noise at diff-time.

```arc f --paths-cmd 'hg files -I "**/*.java"'```

drop-conflicts

Reviewed By: cpojer

Differential Revision: D16071725

fbshipit-source-id: fc6e3852e45742c109f0c5ac4065d64201c74204
2019-07-02 04:16:46 -07:00

103 lines
2.5 KiB
Java

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.facebook.react.bridge;
import androidx.core.util.Pools;
import javax.annotation.Nullable;
/** Implementation of Dynamic wrapping a ReadableArray. */
public class DynamicFromArray implements Dynamic {
private static final Pools.SimplePool<DynamicFromArray> sPool = new Pools.SimplePool<>(10);
private @Nullable ReadableArray mArray;
private int mIndex = -1;
// This is a pools object. Hide the constructor.
private DynamicFromArray() {}
public static DynamicFromArray create(ReadableArray array, int index) {
DynamicFromArray dynamic = sPool.acquire();
if (dynamic == null) {
dynamic = new DynamicFromArray();
}
dynamic.mArray = array;
dynamic.mIndex = index;
return dynamic;
}
@Override
public void recycle() {
mArray = null;
mIndex = -1;
sPool.release(this);
}
@Override
public boolean isNull() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
return mArray.isNull(mIndex);
}
@Override
public boolean asBoolean() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
return mArray.getBoolean(mIndex);
}
@Override
public double asDouble() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
return mArray.getDouble(mIndex);
}
@Override
public int asInt() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
return mArray.getInt(mIndex);
}
@Override
public String asString() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
return mArray.getString(mIndex);
}
@Override
public ReadableArray asArray() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
return mArray.getArray(mIndex);
}
@Override
public ReadableMap asMap() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
return mArray.getMap(mIndex);
}
@Override
public ReadableType getType() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
return mArray.getType(mIndex);
}
}