1/**
2 * Copyright(C) 1998
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : January 1, 1998.
11 * @author : Salih Yurttas.
12 */
13
14
15import java.io.*;
16
17public class StringList {
18
19 private static final int N = 16;
20
21 private String[] list;
22
23 private int count=0;
24
25 private String inFileName,
26 outFileName;
27
28 public StringList() {
29 list = new String[N];
30
31 for (int i=0; i<N; i++)
32 list[i] = "";
33 }
34
35 public StringList(final int size) {
36 list = new String[size];
37
38 for (int i=0; i<size; i++)
39 list[i] = "";
40 }
41
42 public StringList(final StringList l) {
43 int size = l.length();
44 list = new String[size];
45 count = l.count;
46
47 for (int i=0; i<size; i++)
48 list[i] = l.list[i];
49 }
50
51 public int length() {
52 return list.length;
53 }
54
55 public int size() {
56 return count;
57 }
58
59 public String getStringAt(final int i) {
60 return list[i];
61 }
62
63 public void setStringAt(final int i,
64 final String value) {
65 list[i] = value;
66 }
67
68 public void setInFileName(final String inFileName) {
69 this.inFileName = inFileName;
70 }
71
72 public String getInFileName() {
73 return inFileName;
74 }
75
76 public void setOutFileName(final String outFileName) {
77 this.outFileName = outFileName;
78 }
79
80 public String getOutFileName() {
81 return outFileName;
82 }
83
84 public void getStringList()
85 throws IOException
86 {
87 DataInputStream dInS = new DataInputStream(System.in);
88 Reader kR = new BufferedReader(new InputStreamReader(dInS));
89 StreamTokenizer kTokens = new StreamTokenizer(kR);
90
91 System.out.print("inFileName : ");
92 System.out.flush();
93 kTokens.nextToken();
94 String inFileName = kTokens.sval;
95
96 FileInputStream fInS = new FileInputStream(inFileName);
97 Reader fR = new BufferedReader(new InputStreamReader(fInS));
98 StreamTokenizer fTokens = new StreamTokenizer(fR);
99
100 while(fTokens.nextToken() != fTokens.TT_EOF)
101 list[count++] = fTokens.sval;
102 }
103
104 public void getStringList(final String inFileName)
105 throws IOException
106 {
107 FileInputStream fInS = new FileInputStream(inFileName);
108 Reader fR = new BufferedReader(new InputStreamReader(fInS));
109 StreamTokenizer fTokens = new StreamTokenizer(fR);
110
111 while(fTokens.nextToken() != fTokens.TT_EOF)
112 list[count++] = fTokens.sval;
113 }
114
115 public void putStringList()
116 throws IOException
117 {
118 DataInputStream dInS = new DataInputStream(System.in);
119 Reader kR = new BufferedReader(new InputStreamReader(dInS));
120 StreamTokenizer kTokens = new StreamTokenizer(kR);
121
122 System.out.print("outFileName : ");
123 System.out.flush();
124 kTokens.nextToken();
125 String outFileName = kTokens.sval;
126
127 FileOutputStream fOutS = new FileOutputStream(outFileName);
128 PrintWriter pOutL = new PrintWriter(fOutS);
129
130 int size = count;
131
132 for (int i=0; i<size; i++)
133 pOutL.println(list[i]);
134
135 pOutL.close();
136 }
137
138 public void putStringList(final String outFileName)
139 throws IOException
140 {
141 FileOutputStream fOutS = new FileOutputStream(outFileName);
142 PrintWriter pOutL = new PrintWriter(fOutS);
143
144 int size = count;
145
146 for (int i=0; i<size; i++)
147 pOutL.println(list[i]);
148
149 pOutL.close();
150 }
151
152}