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.  *      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. 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.     /**
  40.      * The empty array of this type.
  41.      */
  42.     static final NewsgroupInfo[] EMPTY_ARRAY = {};

  43.     private String newsgroup;
  44.     private long estimatedArticleCount;
  45.     private long firstArticle;
  46.     private long lastArticle;
  47.     private int postingPermission;

  48.     /**
  49.      * Constructs a new instance.
  50.      */
  51.     public NewsgroupInfo() {
  52.         // empty
  53.     }

  54.     /**
  55.      * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
  56.      *
  57.      * @return The estimated number of articles in the newsgroup.
  58.      */
  59.     @Deprecated
  60.     public int getArticleCount() {
  61.         return (int) estimatedArticleCount;
  62.     }

  63.     /**
  64.      * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
  65.      *
  66.      * @return The estimated number of articles in the newsgroup.
  67.      */
  68.     public long getArticleCountLong() {
  69.         return estimatedArticleCount;
  70.     }

  71.     /**
  72.      * Gets the number of the first article in the newsgroup.
  73.      *
  74.      * @return The number of the first article in the newsgroup.
  75.      */
  76.     @Deprecated
  77.     public int getFirstArticle() {
  78.         return (int) firstArticle;
  79.     }

  80.     /**
  81.      * Gets the number of the first article in the newsgroup.
  82.      *
  83.      * @return The number of the first article in the newsgroup.
  84.      */
  85.     public long getFirstArticleLong() {
  86.         return firstArticle;
  87.     }

  88.     /**
  89.      * Gets the number of the last article in the newsgroup.
  90.      *
  91.      * @return The number of the last article in the newsgroup.
  92.      */
  93.     @Deprecated
  94.     public int getLastArticle() {
  95.         return (int) lastArticle;
  96.     }

  97.     /**
  98.      * Gets the number of the last article in the newsgroup.
  99.      *
  100.      * @return The number of the last article in the newsgroup.
  101.      */
  102.     public long getLastArticleLong() {
  103.         return lastArticle;
  104.     }

  105.     /**
  106.      * Gets the newsgroup name.
  107.      *
  108.      * @return The name of the newsgroup.
  109.      */
  110.     public String getNewsgroup() {
  111.         return newsgroup;
  112.     }

  113.     /**
  114.      * Gets the posting permission of the newsgroup. This will be one of the {@code POSTING_PERMISSION} constants.
  115.      *
  116.      * @return The posting permission status of the newsgroup.
  117.      */
  118.     public int getPostingPermission() {
  119.         return postingPermission;
  120.     }

  121.     void setArticleCount(final long count) {
  122.         estimatedArticleCount = count;
  123.     }

  124.     void setFirstArticle(final long first) {
  125.         firstArticle = first;
  126.     }

  127.     /*
  128.      * public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(__newsgroup); buffer.append(' '); buffer.append(__lastArticle);
  129.      * buffer.append(' '); buffer.append(__firstArticle); buffer.append(' '); switch(__postingPermission) { case 1: buffer.append('m'); break; case 2:
  130.      * buffer.append('y'); break; case 3: buffer.append('n'); break; } return buffer.toString(); }
  131.      */

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

  133.     void setLastArticle(final long last) {
  134.         lastArticle = last;
  135.     }

  136.     void setNewsgroup(final String newsgroup) {
  137.         this.newsgroup = newsgroup;
  138.     }

  139.     void setPostingPermission(final int permission) {
  140.         postingPermission = permission;
  141.     }
  142. }