NIMSDK-AOS  10.9.90
V2NIMCreateTopicParams.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.topic.params;
2 
3 /**
4  * 创建 Topic 参数。
5  */
6 public class V2NIMCreateTopicParams {
7  private static final int MAX_TOPIC_NAME_LENGTH = 128;
8 
9  /**
10  * Topic 类型;未设置时默认值为 0。
11  */
12  private final Integer type;
13  /**
14  * Topic 名称。
15  */
16  private final String topicName;
17  /**
18  * 服务端扩展字段。
19  */
20  private final String serverExtension;
21 
22  /**
23  * 构造创建 Topic 参数。
24  *
25  * @param type Topic 类型;如果设置,则必须大于 0
26  * @param topicName Topic 名称,最大长度为 128 个字符
27  * @param serverExtension 服务端扩展字段
28  */
29  public V2NIMCreateTopicParams(int type, String topicName, String serverExtension) {
30  this.type = type;
31  this.topicName = topicName;
32  this.serverExtension = serverExtension;
33  }
34 
35  /**
36  * 构造创建 Topic 参数。
37  *
38  * @param topicName Topic 名称,最大长度为 128 个字符
39  * @param serverExtension 服务端扩展字段
40  */
41  public V2NIMCreateTopicParams(String topicName, String serverExtension) {
42  this.type = null;
43  this.topicName = topicName;
44  this.serverExtension = serverExtension;
45  }
46 
47  /**
48  * 返回 Topic 类型。
49  *
50  * @return Topic 类型;未指定时为 0
51  */
52  public int getType() {
53  return type == null ? 0 : type;
54  }
55 
56  /**
57  * Topic 类型是否已显式设置。
58  *
59  * @return `true` 表示已显式设置 Topic 类型,否则为 `false`
60  */
61  public boolean hasType() {
62  return type != null;
63  }
64 
65  /**
66  * 返回 Topic 名称。
67  *
68  * @return Topic 名称,最大长度为 128 个字符
69  */
70  public String getTopicName() {
71  return topicName;
72  }
73 
74  /**
75  * 返回服务端扩展字段。
76  *
77  * @return 服务端扩展字段
78  */
79  public String getServerExtension() {
80  return serverExtension;
81  }
82 
83  /**
84  * 返回参数非法原因。
85  *
86  * @return 参数合法时返回 `null`,否则返回具体错误原因
87  */
88  public String isValidWithErrorMsg() {
89  if (type != null && type <= 0) {
90  return "type must be greater than 0";
91  }
92  if (topicName != null && topicName.length() > MAX_TOPIC_NAME_LENGTH) {
93  return "topicName length must be less than or equal to 128";
94  }
95  return null;
96  }
97 
98  /**
99  * 参数是否合法。
100  *
101  * @return `true` 表示参数合法,否则为 `false`
102  */
103  public boolean isValid() {
104  return isValidWithErrorMsg() == null;
105  }
106 }
V2NIMCreateTopicParams(int type, String topicName, String serverExtension)
构造创建 Topic 参数。
V2NIMCreateTopicParams(String topicName, String serverExtension)
构造创建 Topic 参数。
boolean hasType()
Topic 类型是否已显式设置。