    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.net.nntp;
    019
    020/**
    021 * NewsgroupInfo stores information pertaining to a newsgroup returned by the NNTP GROUP, LIST, and NEWGROUPS commands, implemented by
    022 * {@link org.apache.commons.net.nntp.NNTPClient#selectNewsgroup selectNewsgroup} , {@link org.apache.commons.net.nntp.NNTPClient#listNewsgroups listNewsgroups
    023 * } , and {@link org.apache.commons.net.nntp.NNTPClient#listNewNewsgroups listNewNewsgroups} respectively.
    024 *
    025 * @see NNTPClient
    026 */
    027
    028public final class NewsgroupInfo {
    029
    030    /**
    031     * A constant indicating that the posting permission of a newsgroup is unknown. For example, the NNTP GROUP command does not return posting information, so
    032     * NewsgroupInfo instances obtained from that command will have an UNKNOWN_POSTING_PERMISSION.
    033     */
    034    public static final int UNKNOWN_POSTING_PERMISSION = 0;
    035
    036    /** A constant indicating that a newsgroup is moderated. */
    037    public static final int MODERATED_POSTING_PERMISSION = 1;
    038
    039    /** A constant indicating that a newsgroup is public and unmoderated. */
    040    public static final int PERMITTED_POSTING_PERMISSION = 2;
    041
    042    /**
    043     * A constant indicating that a newsgroup is closed for general posting.
    044     */
    045    public static final int PROHIBITED_POSTING_PERMISSION = 3;
    046
    047    /**
    048     * The empty array of this type.
    049     */
    050    static final NewsgroupInfo[] EMPTY_ARRAY = {};
    051
    052    private String newsgroup;
    053    private long estimatedArticleCount;
    054    private long firstArticle;
    055    private long lastArticle;
    056    private int postingPermission;
    057
    058    /**
    059     * Constructs a new instance.
    060     */
    061    public NewsgroupInfo() {
    062        // empty
    063    }
    064
    065    /**
    066     * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
    067     *
    068     * @return The estimated number of articles in the newsgroup.
    069     */
    070    @Deprecated
    071    public int getArticleCount() {
    072        return (int) estimatedArticleCount;
    073    }
    074
    075    /**
    076     * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
    077     *
    078     * @return The estimated number of articles in the newsgroup.
    079     */
    080    public long getArticleCountLong() {
    081        return estimatedArticleCount;
    082    }
    083
    084    /**
    085     * Gets the number of the first article in the newsgroup.
    086     *
    087     * @return The number of the first article in the newsgroup.
    088     */
    089    @Deprecated
    090    public int getFirstArticle() {
    091        return (int) firstArticle;
    092    }
    093
    094    /**
    095     * Gets the number of the first article in the newsgroup.
    096     *
    097     * @return The number of the first article in the newsgroup.
    098     */
    099    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}