1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.commons.net.nntp;
19
20 /**
21 * NewsgroupInfo stores information pertaining to a newsgroup returned by the NNTP GROUP, LIST, and NEWGROUPS commands, implemented by
22 * {@link org.apache.commons.net.nntp.NNTPClient#selectNewsgroup selectNewsgroup} , {@link org.apache.commons.net.nntp.NNTPClient#listNewsgroups listNewsgroups
23 * } , and {@link org.apache.commons.net.nntp.NNTPClient#listNewNewsgroups listNewNewsgroups} respectively.
24 *
25 * @see NNTPClient
26 */
27
28 public final class NewsgroupInfo {
29
30 /**
31 * A constant indicating that the posting permission of a newsgroup is unknown. For example, the NNTP GROUP command does not return posting information, so
32 * NewsgroupInfo instances obtained from that command will have an UNKNOWN_POSTING_PERMISSION.
33 */
34 public static final int UNKNOWN_POSTING_PERMISSION = 0;
35
36 /** A constant indicating that a newsgroup is moderated. */
37 public static final int MODERATED_POSTING_PERMISSION = 1;
38
39 /** A constant indicating that a newsgroup is public and unmoderated. */
40 public static final int PERMITTED_POSTING_PERMISSION = 2;
41
42 /**
43 * A constant indicating that a newsgroup is closed for general posting.
44 */
45 public static final int PROHIBITED_POSTING_PERMISSION = 3;
46
47 /**
48 * The empty array of this type.
49 */
50 static final NewsgroupInfo[] EMPTY_ARRAY = {};
51
52 private String newsgroup;
53 private long estimatedArticleCount;
54 private long firstArticle;
55 private long lastArticle;
56 private int postingPermission;
57
58 /**
59 * Constructs a new instance.
60 */
61 public NewsgroupInfo() {
62 // empty
63 }
64
65 /**
66 * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
67 *
68 * @return The estimated number of articles in the newsgroup.
69 */
70 @Deprecated
71 public int getArticleCount() {
72 return (int) estimatedArticleCount;
73 }
74
75 /**
76 * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
77 *
78 * @return The estimated number of articles in the newsgroup.
79 */
80 public long getArticleCountLong() {
81 return estimatedArticleCount;
82 }
83
84 /**
85 * Gets the number of the first article in the newsgroup.
86 *
87 * @return The number of the first article in the newsgroup.
88 */
89 @Deprecated
90 public int getFirstArticle() {
91 return (int) firstArticle;
92 }
93
94 /**
95 * Gets the number of the first article in the newsgroup.
96 *
97 * @return The number of the first article in the newsgroup.
98 */
99 public long getFirstArticleLong() {
100 return firstArticle;
101 }
102
103 /**
104 * Gets the number of the last article in the newsgroup.
105 *
106 * @return The number of the last article in the newsgroup.
107 */
108 @Deprecated
109 public int getLastArticle() {
110 return (int) lastArticle;
111 }
112
113 /**
114 * Gets the number of the last article in the newsgroup.
115 *
116 * @return The number of the last article in the newsgroup.
117 */
118 public long getLastArticleLong() {
119 return lastArticle;
120 }
121
122 /**
123 * Gets the newsgroup name.
124 *
125 * @return The name of the newsgroup.
126 */
127 public String getNewsgroup() {
128 return newsgroup;
129 }
130
131 /**
132 * Gets the posting permission of the newsgroup. This will be one of the {@code POSTING_PERMISSION} constants.
133 *
134 * @return The posting permission status of the newsgroup.
135 */
136 public int getPostingPermission() {
137 return postingPermission;
138 }
139
140 void setArticleCount(final long count) {
141 estimatedArticleCount = count;
142 }
143
144 void setFirstArticle(final long first) {
145 firstArticle = first;
146 }
147
148 /*
149 * public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(__newsgroup); buffer.append(' '); buffer.append(__lastArticle);
150 * buffer.append(' '); buffer.append(__firstArticle); buffer.append(' '); switch(__postingPermission) { case 1: buffer.append('m'); break; case 2:
151 * buffer.append('y'); break; case 3: buffer.append('n'); break; } return buffer.toString(); }
152 */
153
154 // DEPRECATED METHODS - for API compatibility only - DO NOT USE
155
156 void setLastArticle(final long last) {
157 lastArticle = last;
158 }
159
160 void setNewsgroup(final String newsgroup) {
161 this.newsgroup = newsgroup;
162 }
163
164 void setPostingPermission(final int permission) {
165 postingPermission = permission;
166 }
167 }