summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java
blob: 7d0caec992e7ed50ed92fc54ef01fc93caf382be (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.mapbox.mapboxsdk.style.types;

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

import java.util.Arrays;

/**
 * A component of the {@link Formatted}.
 */
@Keep
public class FormattedSection {
  private final String text;
  private final Number fontScale;
  private final String[] fontStack;

  /**
   * Creates a formatted section.
   *
   * @param text      displayed string
   * @param fontScale scale of the font, setting to null will fall back to style's default settings
   * @param fontStack main and fallback fonts that are a part of the style,
   *                  setting null will fall back to style's default settings
   */
  public FormattedSection(@NonNull String text, @Nullable Number fontScale, @Nullable String[] fontStack) {
    this.text = text;
    this.fontScale = fontScale;
    this.fontStack = fontStack;
  }

  /**
   * Creates a formatted section.
   *
   * @param text      displayed string
   * @param fontScale scale of the font, setting to null will fall back to style's default settings
   */
  public FormattedSection(@NonNull String text, @Nullable Number fontScale) {
    this(text, fontScale, null);
  }

  /**
   * Creates a formatted section.
   *
   * @param text displayed string
   */
  public FormattedSection(@NonNull String text) {
    this(text, null, null);
  }

  /**
   * Creates a formatted section.
   *
   * @param text      displayed string
   * @param fontStack main and fallback fonts that are a part of the style,
   *                  setting null will fall back to style's default settings
   */
  public FormattedSection(@NonNull String text, @Nullable String[] fontStack) {
    this(text, null, fontStack);
  }

  /**
   * Returns the displayed text.
   *
   * @return text
   */
  @NonNull
  public String getText() {
    return text;
  }

  /**
   * Returns displayed text's font scale.
   *
   * @return font scale
   */
  @Nullable
  public Number getFontScale() {
    return fontScale;
  }

  /**
   * Returns the font stack with main and fallback fonts.
   *
   * @return font stack
   */
  @Nullable
  public String[] getFontStack() {
    return fontStack;
  }

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

    FormattedSection that = (FormattedSection) o;

    if (text != null ? !text.equals(that.text) : that.text != null) {
      return false;
    }
    if (fontScale != null ? !fontScale.equals(that.fontScale) : that.fontScale != null) {
      return false;
    }
    // Probably incorrect - comparing Object[] arrays with Arrays.equals
    return Arrays.equals(fontStack, that.fontStack);
  }

  @Override
  public int hashCode() {
    int result = text != null ? text.hashCode() : 0;
    result = 31 * result + (fontScale != null ? fontScale.hashCode() : 0);
    result = 31 * result + Arrays.hashCode(fontStack);
    return result;
  }
}