View Javadoc
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       * A constant indicating that the posting permission of a newsgroup is unknown. For example, the NNTP GROUP command does not return posting information, so
31       * NewsgroupInfo instances obtained from that command will have an UNKNOWN_POSTING_PERMISSION.
32       */
33      public static final int UNKNOWN_POSTING_PERMISSION = 0;
34  
35      /** A constant indicating that a newsgroup is moderated. */
36      public static final int MODERATED_POSTING_PERMISSION = 1;
37  
38      /** A constant indicating that a newsgroup is public and unmoderated. */
39      public static final int PERMITTED_POSTING_PERMISSION = 2;
40  
41      /**
42       * A constant indicating that a newsgroup is closed for general posting.
43       */
44      public static final int PROHIBITED_POSTING_PERMISSION = 3;
45  
46      /**
47       * The empty array of this type.
48       */
49      static final NewsgroupInfo[] EMPTY_ARRAY = {};
50  
51      private String newsgroup;
52      private long estimatedArticleCount;
53      private long firstArticle;
54      private long lastArticle;
55      private int postingPermission;
56  
57      /**
58       * Constructs a new instance.
59       */
60      public NewsgroupInfo() {
61          // empty
62      }
63  
64      /**
65       * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
66       *
67       * @return The estimated number of articles in the newsgroup.
68       */
69      @Deprecated
70      public int getArticleCount() {
71          return (int) estimatedArticleCount;
72      }
73  
74      /**
75       * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
76       *
77       * @return The estimated number of articles in the newsgroup.
78       */
79      public long getArticleCountLong() {
80          return estimatedArticleCount;
81      }
82  
83      /**
84       * Gets the number of the first article in the newsgroup.
85       *
86       * @return The number of the first article in the newsgroup.
87       */
88      @Deprecated
89      public int getFirstArticle() {
90          return (int) firstArticle;
91      }
92  
93      /**
94       * Gets the number of the first article in the newsgroup.
95       *
96       * @return The number of the first article in the newsgroup.
97       */
98      public long getFirstArticleLong() {
99          return firstArticle;
100     }
101 
102     /**
103      * Gets the number of the last article in the newsgroup.
104      *
105      * @return The number of the last article in the newsgroup.
106      */
107     @Deprecated
108     public int getLastArticle() {
109         return (int) lastArticle;
110     }
111 
112     /**
113      * Gets the number of the last article in the newsgroup.
114      *
115      * @return The number of the last article in the newsgroup.
116      */
117     public long getLastArticleLong() {
118         return lastArticle;
119     }
120 
121     /**
122      * Gets the newsgroup name.
123      *
124      * @return The name of the newsgroup.
125      */
126     public String getNewsgroup() {
127         return newsgroup;
128     }
129 
130     /**
131      * Gets the posting permission of the newsgroup. This will be one of the {@code POSTING_PERMISSION} constants.
132      *
133      * @return The posting permission status of the newsgroup.
134      */
135     public int getPostingPermission() {
136         return postingPermission;
137     }
138 
139     void setArticleCount(final long count) {
140         estimatedArticleCount = count;
141     }
142 
143     void setFirstArticle(final long first) {
144         firstArticle = first;
145     }
146 
147     /*
148      * public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(__newsgroup); buffer.append(' '); buffer.append(__lastArticle);
149      * buffer.append(' '); buffer.append(__firstArticle); buffer.append(' '); switch(__postingPermission) { case 1: buffer.append('m'); break; case 2:
150      * buffer.append('y'); break; case 3: buffer.append('n'); break; } return buffer.toString(); }
151      */
152 
153     // DEPRECATED METHODS - for API compatibility only - DO NOT USE
154 
155     void setLastArticle(final long last) {
156         lastArticle = last;
157     }
158 
159     void setNewsgroup(final String newsgroup) {
160         this.newsgroup = newsgroup;
161     }
162 
163     void setPostingPermission(final int permission) {
164         postingPermission = permission;
165     }
166 }