summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/Formatted.java
blob: fb2d361bfcce38f8c9393d7ffe6b34547e608a01 (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
package com.mapbox.mapboxsdk.style.types;

import android.support.annotation.Keep;
import android.support.annotation.Nullable;

import java.util.Arrays;

/**
 * Represents a string broken into sections annotated with separate formatting options.
 *
 * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#types-formatted">Style specification</a>
 */
@Keep
public class Formatted {
  private final FormattedSection[] formattedSections;

  /**
   * Create a new formatted text.
   *
   * @param formattedSections sections with formatting options
   */
  public Formatted(FormattedSection... formattedSections) {
    this.formattedSections = formattedSections;
  }

  /**
   * Returns sections with separate formatting options that are a part of this formatted text.
   *
   * @return formatted sections
   */
  public FormattedSection[] getFormattedSections() {
    return formattedSections;
  }

  public Object[] toArray() {
    Object[] sections = new Object[formattedSections.length];
    for (int i = 0; i < formattedSections.length; i++) {
      sections[i] = formattedSections[i].toArray();
    }
    return sections;
  }

  @Override
  public boolean equals(@Nullable Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    Formatted formatted = (Formatted) o;

    return Arrays.equals(formattedSections, formatted.formattedSections);
  }

  @Override
  public int hashCode() {
    return Arrays.hashCode(formattedSections);
  }
}