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