    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
    022 * the NNTP GROUP, LIST, and NEWGROUPS commands, implemented by
    023 * {@link org.apache.commons.net.nntp.NNTPClient#selectNewsgroup selectNewsgroup }
    024 * ,
    025 * {@link org.apache.commons.net.nntp.NNTPClient#listNewsgroups listNewsgroups }
    026 * , and
    027 * {@link org.apache.commons.net.nntp.NNTPClient#listNewNewsgroups listNewNewsgroups }
    028 *  respectively.
    029 *
    030 * @see NNTPClient
    031 */
    032
    033public final class NewsgroupInfo
    034{
    035    /**
    036     * A constant indicating that the posting permission of a newsgroup is
    037     * unknown.  For example, the NNTP GROUP command does not return posting
    038     * information, so NewsgroupInfo instances obtained from that command
    039     * willhave an UNKNOWN_POSTING_PERMISSION.
    040     */
    041    public static final int UNKNOWN_POSTING_PERMISSION = 0;
    042
    043    /** A constant indicating that a newsgroup is moderated. */
    044    public static final int MODERATED_POSTING_PERMISSION = 1;
    045
    046    /** A constant indicating that a newsgroup is public and unmoderated. */
    047    public static final int PERMITTED_POSTING_PERMISSION = 2;
    048
    049    /**
    050     * A constant indicating that a newsgroup is closed for general posting.
    051     */
    052    public static final int PROHIBITED_POSTING_PERMISSION = 3;
    053
    054    private String newsgroup;
    055    private long estimatedArticleCount;
    056    private long firstArticle;
    057    private long lastArticle;
    058    private int postingPermission;
    059
    060    void setNewsgroup(final String newsgroup)
    061    {
    062        this.newsgroup = newsgroup;
    063    }
    064
    065    void setArticleCount(final long count)
    066    {
    067        estimatedArticleCount = count;
    068    }
    069
    070    void setFirstArticle(final long first)
    071    {
    072        firstArticle = first;
    073    }
    074
    075    void setLastArticle(final long last)
    076    {
    077        lastArticle = last;
    078    }
    079
    080    void setPostingPermission(final int permission)
    081    {
    082        postingPermission = permission;
    083    }
    084
    085    /**
    086     * Get the newsgroup name.
    087     * <p>
    088     * @return The name of the newsgroup.
    089     */
    090    public String getNewsgroup()
    091    {
    092        return newsgroup;
    093    }
    094
    095    /**
    096     * Get the estimated number of articles in the newsgroup.  The
    097     * accuracy of this value will depend on the server implementation.
    098     * <p>
    099     * @return The estimated number of articles in the newsgroup.
    100     */
    101    public long getArticleCountLong()
    102    {
    103        return estimatedArticleCount;
    104    }
    105
    106    /**
    107     * Get the number of the first article in the newsgroup.
    108     * <p>
    109     * @return The number of the first article in the newsgroup.
    110     */
    111    public long getFirstArticleLong()
    112    {
    113        return firstArticle;
    114    }
    115
    116    /**
    117     * Get the number of the last article in the newsgroup.
    118     * <p>
    119     * @return The number of the last article in the newsgroup.
    120     */
    121    public long getLastArticleLong()
    122    {
    123        return lastArticle;
    124    }
    125
    126    /**
    127     * Get the posting permission of the newsgroup.  This will be one of
    128     * the <code> POSTING_PERMISSION </code> constants.
    129     * <p>
    130     * @return The posting permission status of the newsgroup.
    131     */
    132    public int getPostingPermission()
    133    {
    134        return postingPermission;
    135    }
    136
    137    /*
    138    public String toString() {
    139      StringBuilder buffer = new StringBuilder();
    140      buffer.append(__newsgroup);
    141      buffer.append(' ');
    142      buffer.append(__lastArticle);
    143      buffer.append(' ');
    144      buffer.append(__firstArticle);
    145      buffer.append(' ');
    146      switch(__postingPermission) {
    147        case 1: buffer.append('m'); break;
    148        case 2: buffer.append('y'); break;
    149        case 3: buffer.append('n'); break;
    150      }
    151      return buffer.toString();
    152}
    153    */
    154
    155    // DEPRECATED METHODS - for API compatibility only - DO NOT USE
    156
    157    @Deprecated
    158    public int getArticleCount() {
    159        return (int) estimatedArticleCount;
    160    }
    161
    162    @Deprecated
    163    public int getFirstArticle() {
    164        return (int) firstArticle;
    165    }
    166
    167    @Deprecated
    168    public int getLastArticle() {
    169        return (int) lastArticle;
    170    }
    171}