stat.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package model
  2. // Stat struct of Stat.
  3. // type Stat struct {
  4. // Mid int64 `json:"-"`
  5. // Following int64 `json:"following"`
  6. // Whisper int64 `json:"whisper"`
  7. // Black int64 `json:"black"`
  8. // Follower int64 `json:"follower"`
  9. // CTime time.Time `json:"-"`
  10. // MTime time.Time `json:"-"`
  11. // }
  12. // Count get count of following, including attr following, whisper.
  13. func (st *Stat) Count() int {
  14. return int(st.Following + st.Whisper)
  15. }
  16. // BlackCount get count of black, including attr black.
  17. func (st *Stat) BlackCount() int {
  18. return int(st.Black)
  19. }
  20. // Empty get if the stat is empty.
  21. func (st *Stat) Empty() bool {
  22. return st.Following == 0 && st.Whisper == 0 && st.Black == 0 && st.Follower == 0
  23. }
  24. // Fill fill by the incoming stat with its non-negative fields.
  25. func (st *Stat) Fill(ost *Stat) {
  26. if ost.Following >= 0 {
  27. st.Following = ost.Following
  28. }
  29. if ost.Whisper >= 0 {
  30. st.Whisper = ost.Whisper
  31. }
  32. if ost.Black >= 0 {
  33. st.Black = ost.Black
  34. }
  35. if ost.Follower >= 0 {
  36. st.Follower = ost.Follower
  37. }
  38. }