NIMSDK-AOS  10.9.71
V2NIMCollectionOption.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.message.option;
2 
5 import java.io.Serializable;
6 
7 public class V2NIMCollectionOption implements Serializable {
8 
9  // 查询开始时间区间,闭区间
10  private final long beginTime;
11 
12  // 查询结束时间区间,闭区间
13  // endTime大于beginTime
14  private final long endTime;
15 
16  // 查询锚点
17  // 如果anchor为空, 则以beginTime,endTime为准
18  // 如果anchor不为空
19  // 如果direction为DESC,
20  // endTime不为0, 则必须等于anchor的时间, 否则报错
21  // endTime为0, 则以anchor为准
22  // 如果direction为ASC
23  // beginTime不为0, 则必须等于anchor的时间, 否则报错
24  // beginTime为0, 则以anchor为准
25  // 查询内部不包括anchor
26  private final V2NIMCollection anchorCollection;
27 
28  // 查询方向
29  // 默认按时间从大到小查询 V2NIMQueryDirection.V2NIM_QUERY_DIRECTION_OLDER
30  private final V2NIMQueryDirection direction;
31 
32  // 每次查询收藏条数
33  // 不超过200
34  private final int limit;
35 
36  // 收藏类型
37  // 为0表示查询所有类型
38  private final int collectionType;
39 
40  private V2NIMCollectionOption() {
41  this(0, 0, null, DEFAULT_DIRECTION, DEFAULT_LIMIT, 0);
42  }
43 
44  private V2NIMCollectionOption(long beginTime, long endTime, V2NIMCollection anchorCollection, V2NIMQueryDirection direction, int limit, int collectionType) {
45  this.beginTime = beginTime;
46  this.endTime = endTime;
47  this.anchorCollection = anchorCollection;
48  this.direction = direction == null ? DEFAULT_DIRECTION : direction;
49  this.limit = limit;
50  this.collectionType = collectionType;
51  }
52 
53  public long getBeginTime() {
54  return beginTime;
55  }
56 
57  public long getEndTime() {
58  return endTime;
59  }
60 
62  return anchorCollection;
63  }
64 
66  if (direction == null) {
67  return DEFAULT_DIRECTION;
68  } else {
69  return direction;
70  }
71  }
72 
73  public int getLimit() {
74  return limit;
75  }
76 
77  public int getCollectionType() {
78  return collectionType;
79  }
80 
81  @Override
82  public String toString() {
83  return "V2NIMCollectionOption{" +
84  "beginTime=" + beginTime +
85  ", endTime=" + endTime +
86  ", anchorCollection=" + anchorCollection +
87  ", direction=" + direction +
88  ", limit=" + limit +
89  ", collectionType=" + collectionType +
90  '}';
91  }
92 
93  private final static V2NIMQueryDirection DEFAULT_DIRECTION = V2NIMQueryDirection.V2NIM_QUERY_DIRECTION_DESC;
94  private final static int DEFAULT_LIMIT = 100;
95 
96  public static final class V2NIMCollectionOptionBuilder {
97  private long beginTime;
98  private long endTime;
99  private V2NIMQueryDirection direction = DEFAULT_DIRECTION;
100  private V2NIMCollection anchorCollection;
101  private int limit = DEFAULT_LIMIT;
102  private int collectionType;
103 
104  private V2NIMCollectionOptionBuilder() {
105  }
106 
107  public static V2NIMCollectionOptionBuilder builder() {
108  return new V2NIMCollectionOptionBuilder();
109  }
110 
111  public V2NIMCollectionOptionBuilder withBeginTime(long beginTime) {
112  this.beginTime = beginTime;
113  return this;
114  }
115 
116  public V2NIMCollectionOptionBuilder withEndTime(long endTime) {
117  this.endTime = endTime;
118  return this;
119  }
120 
121  public V2NIMCollectionOptionBuilder withDirection(V2NIMQueryDirection direction) {
122  this.direction = direction;
123  return this;
124  }
125 
126  public V2NIMCollectionOptionBuilder withAnchorCollection(V2NIMCollection anchorCollection) {
127  this.anchorCollection = anchorCollection;
128  return this;
129  }
130 
131  public V2NIMCollectionOptionBuilder withLimit(int limit) {
132  this.limit = limit;
133  return this;
134  }
135 
136  public V2NIMCollectionOptionBuilder withCollectionType(int collectionType) {
137  this.collectionType = collectionType;
138  return this;
139  }
140 
141  public V2NIMCollectionOption build() {
142  return new V2NIMCollectionOption(beginTime, endTime, anchorCollection, direction, limit, collectionType);
143  }
144  }
145 }
146