summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java
blob: 204c15474397200bbea5574f72e3c987bd538f05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.mapbox.mapboxsdk.style.layers;

import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Properties for Layer
 */
public class PropertyValue<T> {
    private static final String TAG = PropertyValue.class.getSimpleName();

    private final Object value;

    /* package */ PropertyValue(Object value) {
        this.value = value;
    }

    public boolean isNull() {
        return value == null;
    }

    public boolean isFunction() {
        return !isNull() && value instanceof Function;
    }

    public boolean isValue() {
        return !isNull() && !isFunction();
    }

    @Nullable
    public Function<T> getFunction() {
        if (isFunction()) {
            //noinspection unchecked
            return (Function<T>) value;
        } else {
            Log.w(TAG, "not a function, try value");
            return null;
        }
    }

    @Nullable
    public T getValue() {
        if (isValue()) {
            //noinspection unchecked
            return (T) value;
        } else {
            Log.w(TAG, "not a value, try function");
            return null;
        }
    }

    @Override
    public String toString() {
        return String.format("%s (%s)", getClass().getSimpleName(), value != null ? value.getClass().getSimpleName() : null);
    }
}