BadgeNotification.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package cn.seecoder.courselearning.android;
  14. import com.alibaba.fastjson.annotation.JSONField;
  15. import cn.seecoder.courselearning.util.ValidatorUtils;
  16. public class BadgeNotification {
  17. @JSONField(name = "add_num")
  18. private Integer addNum;
  19. @JSONField(name = "class")
  20. private String badgeClass;
  21. @JSONField(name = "set_num")
  22. private Integer setNum;
  23. public Integer getAddNum() {
  24. return addNum;
  25. }
  26. public String getBadgeClass() {
  27. return badgeClass;
  28. }
  29. public Integer getSetNum() {
  30. return setNum;
  31. }
  32. public BadgeNotification(Integer addNum, String badgeClass) {
  33. this.addNum = builder().addNum;
  34. this.badgeClass = badgeClass;
  35. }
  36. public BadgeNotification(Builder builder) {
  37. this.addNum = builder.addNum;
  38. this.badgeClass = builder.badgeClass;
  39. this.setNum = builder.setNum;
  40. }
  41. public void check() {
  42. if (this.addNum != null) {
  43. ValidatorUtils.checkArgument(this.addNum.intValue() > 0 && this.addNum.intValue() < 100, "add_num should locate between 0 and 100");
  44. }
  45. if (this.setNum != null) {
  46. ValidatorUtils.checkArgument(this.setNum.intValue() >= 0 && this.setNum.intValue() < 100, "set_num should locate between 0 and 100");
  47. }
  48. }
  49. /**
  50. * builder
  51. */
  52. public static Builder builder() {
  53. return new Builder();
  54. }
  55. public static class Builder {
  56. private Integer addNum;
  57. private String badgeClass;
  58. private Integer setNum;
  59. public Builder setAddNum(Integer addNum) {
  60. this.addNum = addNum;
  61. return this;
  62. }
  63. public Builder setSetNum(Integer setNum) {
  64. this.setNum = setNum;
  65. return this;
  66. }
  67. public Builder setBadgeClass(String badgeClass) {
  68. this.badgeClass = badgeClass;
  69. return this;
  70. }
  71. public BadgeNotification build() {
  72. return new BadgeNotification(this);
  73. }
  74. }
  75. }