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     * A constant indicating that the posting permission of a newsgroup is unknown. For example, the NNTP GROUP command does not return posting information, so
031     * NewsgroupInfo instances obtained from that command will have an UNKNOWN_POSTING_PERMISSION.
032     */
033    public static final int UNKNOWN_POSTING_PERMISSION = 0;
034
035    /** A constant indicating that a newsgroup is moderated. */
036    public static final int MODERATED_POSTING_PERMISSION = 1;
037
038    /** A constant indicating that a newsgroup is public and unmoderated. */
039    public static final int PERMITTED_POSTING_PERMISSION = 2;
040
041    /**
042     * A constant indicating that a newsgroup is closed for general posting.
043     */
044    public static final int PROHIBITED_POSTING_PERMISSION = 3;
045
046    /**
047     * The empty array of this type.
048     */
049    static final NewsgroupInfo[] EMPTY_ARRAY = {};
050
051    private String newsgroup;
052    private long estimatedArticleCount;
053    private long firstArticle;
054    private long lastArticle;
055    private int postingPermission;
056
057    /**
058     * Constructs a new instance.
059     */
060    public NewsgroupInfo() {
061        // empty
062    }
063
064    /**
065     * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
066     *
067     * @return The estimated number of articles in the newsgroup.
068     */
069    @Deprecated
070    public int getArticleCount() {
071        return (int) estimatedArticleCount;
072    }
073
074    /**
075     * Gets the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
076     *
077     * @return The estimated number of articles in the newsgroup.
078     */
079    public long getArticleCountLong() {
080        return estimatedArticleCount;
081    }
082
083    /**
084     * Gets the number of the first article in the newsgroup.
085     *
086     * @return The number of the first article in the newsgroup.
087     */
088    @Deprecated
089    public int getFirstArticle() {
090        return (int) firstArticle;
091    }
092
093    /**
094     * Gets the number of the first article in the newsgroup.
095     *
096     * @return The number of the first article in the newsgroup.
097     */
098    public long getFirstArticleLong() {
099        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}