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

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

import java.util.Arrays;

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

  /**
   * Creates a formatted section.
   *
   * @param text      displayed string
   * @param fontScale scale of the font, 1.0 is default
   * @param fontStack main and fallback fonts that are a part of the style
   */
  @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
  public FormattedSection(@NonNull String text, double 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, 1.0 is default
   */
  @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
  public FormattedSection(@NonNull String text, double fontScale) {
    this.text = text;
    this.fontScale = fontScale;
  }

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

  /**
   * Returns displayed text's font scale.
   *
   * @return font scale, defaults to 1.0
   */
  public double 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(@Nullable Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    FormattedSection section = (FormattedSection) o;

    return Double.compare(section.fontScale, fontScale) == 0
      && (text != null ? text.equals(section.text) : section.text == null)
      && Arrays.equals(fontStack, section.fontStack);
  }

  @Override
  public int hashCode() {
    int result;
    long temp;
    result = text != null ? text.hashCode() : 0;
    temp = Double.doubleToLongBits(fontScale);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    result = 31 * result + Arrays.hashCode(fontStack);
    return result;
  }
}