NewsgroupInfo.java

  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. package org.apache.commons.net.nntp;

  18. /**
  19.  * NewsgroupInfo stores information pertaining to a newsgroup returned by the NNTP GROUP, LIST, and NEWGROUPS commands, implemented by
  20.  * {@link org.apache.commons.net.nntp.NNTPClient#selectNewsgroup selectNewsgroup } , {@link org.apache.commons.net.nntp.NNTPClient#listNewsgroups listNewsgroups
  21.  * } , and {@link org.apache.commons.net.nntp.NNTPClient#listNewNewsgroups listNewNewsgroups } respectively.
  22.  *
  23.  * @see NNTPClient
  24.  */

  25. public final class NewsgroupInfo {
  26.     /**
  27.      * A constant indicating that the posting permission of a newsgroup is unknown. For example, the NNTP GROUP command does not return posting information, so
  28.      * NewsgroupInfo instances obtained from that command will have an UNKNOWN_POSTING_PERMISSION.
  29.      */
  30.     public static final int UNKNOWN_POSTING_PERMISSION = 0;

  31.     /** A constant indicating that a newsgroup is moderated. */
  32.     public static final int MODERATED_POSTING_PERMISSION = 1;

  33.     /** A constant indicating that a newsgroup is public and unmoderated. */
  34.     public static final int PERMITTED_POSTING_PERMISSION = 2;

  35.     /**
  36.      * A constant indicating that a newsgroup is closed for general posting.
  37.      */
  38.     public static final int PROHIBITED_POSTING_PERMISSION = 3;

  39.     private String newsgroup;
  40.     private long estimatedArticleCount;
  41.     private long firstArticle;
  42.     private long lastArticle;
  43.     private int postingPermission;

  44.     @Deprecated
  45.     public int getArticleCount() {
  46.         return (int) estimatedArticleCount;
  47.     }

  48.     /**
  49.      * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
  50.      *
  51.      * @return The estimated number of articles in the newsgroup.
  52.      */
  53.     public long getArticleCountLong() {
  54.         return estimatedArticleCount;
  55.     }

  56.     @Deprecated
  57.     public int getFirstArticle() {
  58.         return (int) firstArticle;
  59.     }

  60.     /**
  61.      * Gets the number of the first article in the newsgroup.
  62.      *
  63.      * @return The number of the first article in the newsgroup.
  64.      */
  65.     public long getFirstArticleLong() {
  66.         return firstArticle;
  67.     }

  68.     @Deprecated
  69.     public int getLastArticle() {
  70.         return (int) lastArticle;
  71.     }

  72.     /**
  73.      * Gets the number of the last article in the newsgroup.
  74.      *
  75.      * @return The number of the last article in the newsgroup.
  76.      */
  77.     public long getLastArticleLong() {
  78.         return lastArticle;
  79.     }

  80.     /**
  81.      * Gets the newsgroup name.
  82.      *
  83.      * @return The name of the newsgroup.
  84.      */
  85.     public String getNewsgroup() {
  86.         return newsgroup;
  87.     }

  88.     /**
  89.      * Gets the posting permission of the newsgroup. This will be one of the <code>POSTING_PERMISSION</code> constants.
  90.      *
  91.      * @return The posting permission status of the newsgroup.
  92.      */
  93.     public int getPostingPermission() {
  94.         return postingPermission;
  95.     }

  96.     void setArticleCount(final long count) {
  97.         estimatedArticleCount = count;
  98.     }

  99.     void setFirstArticle(final long first) {
  100.         firstArticle = first;
  101.     }

  102.     /*
  103.      * public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(__newsgroup); buffer.append(' '); buffer.append(__lastArticle);
  104.      * buffer.append(' '); buffer.append(__firstArticle); buffer.append(' '); switch(__postingPermission) { case 1: buffer.append('m'); break; case 2:
  105.      * buffer.append('y'); break; case 3: buffer.append('n'); break; } return buffer.toString(); }
  106.      */

  107.     // DEPRECATED METHODS - for API compatibility only - DO NOT USE

  108.     void setLastArticle(final long last) {
  109.         lastArticle = last;
  110.     }

  111.     void setNewsgroup(final String newsgroup) {
  112.         this.newsgroup = newsgroup;
  113.     }

  114.     void setPostingPermission(final int permission) {
  115.         postingPermission = permission;
  116.     }
  117. }