package com.mapbox.mapboxsdk.style.functions.stops; import android.support.annotation.NonNull; import android.support.annotation.Size; import java.util.Arrays; import java.util.Iterator; import java.util.Map; /** * The {@link Stops} implementation for exponential functions * * @param the input type * @param the output type */ public class ExponentialStops extends IterableStops> { private float base; private final Stop[] stops; /** * Create exponential stops with an explicit base. Use through {@link Stops#exponential(Stop[])} * * @param base The exponential base of the interpolation curve. It controls the rate at which the function output * increases. Higher values make the output increase more towards the high end of the range. * With values close to 1 the output increases linearly. * @param stops the stops */ @SafeVarargs public ExponentialStops(Float base, @NonNull @Size(min = 1) Stop... stops) { this.base = base != null ? base : 1.0f; this.stops = stops; } /** * Create exponential stops without an explicit base. Use through {@link Stops#exponential(Stop[])} * * @param stops the stops */ @SafeVarargs public ExponentialStops(@NonNull @Size(min = 1) Stop... stops) { this(null, stops); } /** * Set the exponential base * * @param base the base to use in the exponential function * @return this (for chaining) */ public ExponentialStops withBase(float base) { this.base = base; return this; } /** * @return The exponential base */ public float getBase() { return base; } /** * {@inheritDoc} */ @Override public Map toValueObject() { Map map = super.toValueObject(); map.put("base", base); map.put("stops", toValueObjects(stops)); return map; } /** * {@inheritDoc} */ @Override public String getTypeName() { return "exponential"; } /** * {@inheritDoc} */ @Override public Iterator> iterator() { return Arrays.asList(stops).iterator(); } /** * {@inheritDoc} */ @Override public int size() { return stops.length; } }