summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops.java
blob: f9b2929350e75df73690cdc8d541f0933c535fb7 (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
57
58
59
60
61
62
63
64
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;

/**
 * {@link Stops} implementation for categorical functions
 *
 * @param <I> the {@link Stop} input type
 * @param <O> the {@link Stop} output type
 */
public class CategoricalStops<I, O> extends IterableStops<I, O, Stop<I, O>> {

  private final Stop<I, O>[] stops;

  /**
   * Create a categorical {@link Stops} implementation. Use through {@link Stops#categorical(Stop[])}
   *
   * @param stops the stops
   */
  @SafeVarargs
  public CategoricalStops(@NonNull @Size(min = 1) Stop<I, O>... stops) {
    this.stops = stops;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Map<String, Object> toValueObject() {
    Map<String, Object> map = super.toValueObject();
    map.put("stops", toValueObjects(stops));
    return map;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String getTypeName() {
    return "categorical";
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Iterator<Stop<I, O>> iterator() {
    return Arrays.asList(stops).iterator();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public int size() {
    return stops.length;
  }

}