All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.telegram.telegrambots.abilitybots.api.objects.Stats Maven / Gradle / Ivy

There is a newer version: 7.10.0
Show newest version
package org.telegram.telegrambots.abilitybots.api.objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;

import java.io.Serializable;
import java.util.Objects;

/**
 * Basic POJO to track ability and reply hits. The current implementation is NOT thread safe.
 *
 * @author Abbas Abou Daya
 */
public final class Stats implements Serializable {
  @JsonProperty
  private final String name;
  @JsonProperty
  private long hits;

  private Stats(String name) {
    this.name = name;
  }

  @JsonCreator
  public static Stats createStats(@JsonProperty("name") String name, @JsonProperty("hits") long hits) {
    return new Stats(name);
  }

  public String name() {
    return name;
  }

  public long hits() {
    return hits;
  }

  public void hit() {
    hits++;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Stats that = (Stats) o;
    return hits == that.hits &&
        Objects.equals(name, that.name);
  }

  @Override
  public int hashCode() {
    return Objects.hash(name, hits);
  }

  @Override
  public String toString() {
    return MoreObjects.toStringHelper(this)
        .add("name", name)
        .add("hits", hits)
        .toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy