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