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 *      http://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    private String newsgroup;
047    private long estimatedArticleCount;
048    private long firstArticle;
049    private long lastArticle;
050    private int postingPermission;
051
052    @Deprecated
053    public int getArticleCount() {
054        return (int) estimatedArticleCount;
055    }
056
057    /**
058     * Get the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation.
059     *
060     * @return The estimated number of articles in the newsgroup.
061     */
062    public long getArticleCountLong() {
063        return estimatedArticleCount;
064    }
065
066    @Deprecated
067    public int getFirstArticle() {
068        return (int) firstArticle;
069    }
070
071    /**
072     * Get the number of the first article in the newsgroup.
073     *
074     * @return The number of the first article in the newsgroup.
075     */
076    public long getFirstArticleLong() {
077        return firstArticle;
078    }
079
080    @Deprecated
081    public int getLastArticle() {
082        return (int) lastArticle;
083    }
084
085    /**
086     * Get the number of the last article in the newsgroup.
087     *
088     * @return The number of the last article in the newsgroup.
089     */
090    public long getLastArticleLong() {
091        return lastArticle;
092    }
093
094    /**
095     * Get the newsgroup name.
096     *
097     * @return The name of the newsgroup.
098     */
099    public String getNewsgroup() {
100        return newsgroup;
101    }
102
103    /**
104     * Get the posting permission of the newsgroup. This will be one of the <code> POSTING_PERMISSION </code> constants.
105     *
106     * @return The posting permission status of the newsgroup.
107     */
108    public int getPostingPermission() {
109        return postingPermission;
110    }
111
112    void setArticleCount(final long count) {
113        estimatedArticleCount = count;
114    }
115
116    void setFirstArticle(final long first) {
117        firstArticle = first;
118    }
119
120    /*
121     * public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(__newsgroup); buffer.append(' '); buffer.append(__lastArticle);
122     * buffer.append(' '); buffer.append(__firstArticle); buffer.append(' '); switch(__postingPermission) { case 1: buffer.append('m'); break; case 2:
123     * buffer.append('y'); break; case 3: buffer.append('n'); break; } return buffer.toString(); }
124     */
125
126    // DEPRECATED METHODS - for API compatibility only - DO NOT USE
127
128    void setLastArticle(final long last) {
129        lastArticle = last;
130    }
131
132    void setNewsgroup(final String newsgroup) {
133        this.newsgroup = newsgroup;
134    }
135
136    void setPostingPermission(final int permission) {
137        postingPermission = permission;
138    }
139}