001 package com.croftsoft.core.net.news; 002 003 import java.util.*; 004 005 import com.croftsoft.core.lang.NullArgumentException; 006 007 /********************************************************************* 008 * Newsgroup metadata. 009 * 010 * @author 011 * <a href="https://www.croftsoft.com/">David Wallace Croft</A> 012 * @version 013 * 2001-08-03 014 * @since 015 * 1997-05-11 016 *********************************************************************/ 017 018 public final class Newsgroup 019 implements java.io.Serializable 020 ////////////////////////////////////////////////////////////////////// 021 ////////////////////////////////////////////////////////////////////// 022 { 023 024 private static final long serialVersionUID = 1L; 025 026 // 027 028 private final long estimated; 029 030 private final long firstArticle; 031 032 private final long lastArticle; 033 034 private final String groupName; 035 036 // 037 038 // private final String serverName; 039 040 // private final boolean postingAllowed; 041 042 ////////////////////////////////////////////////////////////////////// 043 ////////////////////////////////////////////////////////////////////// 044 045 /********************************************************************* 046 * Parses the GROUP command resonse to get the newsgroup metadata. 047 * 048 * <pre> 049 * 211 n f l s group selected 050 * (n = estimated number of articles in group, 051 * f = first article number in the group, 052 * l = last article number in the group, 053 * s = name of the group.) 054 * 411 no such news group 055 * </pre> 056 *********************************************************************/ 057 public static Newsgroup parse ( String groupCommandResponse ) 058 ////////////////////////////////////////////////////////////////////// 059 { 060 NullArgumentException.check ( groupCommandResponse ); 061 062 try 063 { 064 StringTokenizer stringTokenizer 065 = new StringTokenizer ( groupCommandResponse, " " ); 066 067 String responseCode = stringTokenizer.nextToken ( ); 068 069 if ( "411".equals ( responseCode ) ) 070 { 071 return null; 072 } 073 074 if ( !"211".equals ( responseCode ) ) 075 { 076 throw new IllegalArgumentException ( groupCommandResponse ); 077 } 078 079 long estimated 080 = Long.parseLong ( stringTokenizer.nextToken ( ) ); 081 082 long first 083 = Long.parseLong ( stringTokenizer.nextToken ( ) ); 084 085 long last 086 = Long.parseLong ( stringTokenizer.nextToken ( ) ); 087 088 String group = stringTokenizer.nextToken ( ); 089 090 return new Newsgroup ( estimated, first, last, group ); 091 } 092 catch ( Exception ex ) 093 { 094 throw new IllegalArgumentException ( groupCommandResponse ); 095 } 096 } 097 098 ////////////////////////////////////////////////////////////////////// 099 ////////////////////////////////////////////////////////////////////// 100 101 public Newsgroup ( 102 long estimated, 103 long firstArticle, 104 long lastArticle, 105 String groupName ) 106 ////////////////////////////////////////////////////////////////////// 107 { 108 this.estimated = estimated; 109 110 this.firstArticle = firstArticle; 111 112 this.lastArticle = lastArticle; 113 114 NullArgumentException.check ( this.groupName = groupName ); 115 } 116 117 ////////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////// 119 120 public long getEstimated ( ) { return estimated; } 121 122 public long getFirstArticle ( ) { return firstArticle; } 123 124 public long getLastArticle ( ) { return lastArticle; } 125 126 public String getGroupName ( ) { return groupName; } 127 128 ////////////////////////////////////////////////////////////////////// 129 ////////////////////////////////////////////////////////////////////// 130 }