Skip to content

Commit f8993a4

Browse files
authored
Final bugs removed. Project done!
1 parent b6115b4 commit f8993a4

26 files changed

+133481
-22
lines changed

input.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
This is the first line
2-
This is the second line
3-
This is the 3rd Line which is exceeding limit of 10 ASCII characters. Thus it will be trimmed.
1+
Each
2+
Each
3+
Each
4+
Each
5+
Dich
6+
Snitch
7+
Toum
8+
Tam . Each Each Each ? Each Tam
9+
Tik Tok Bop
10+
RichN
11+
Bitch
12+
MMMM

input.txt.ndx

640 Bytes
Binary file not shown.

src/Files/FileOps.java

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
package Files;
1+
package Files;
22
import java.io.*;
33
import java.util.ArrayList;
44
import java.util.Collections;
55

6-
import test.*;
6+
import textEditor.*;
77
import util.Item;
88
import util.List;
99
import util.Node;
1010
import util.Word;
1111

12+
/**
13+
*
14+
*
15+
* {@summary }
16+
* A class to encapsulate methods for performing r/w operations on regular Files
17+
* @author dasApfel - Konstantinos Pantelis
18+
*
19+
* @see FileInputStream FileOutputStream InputStreamReader OutputStreamReader BufferedReader BufferedWriter
20+
*
21+
*
22+
*
23+
24+
*/
25+
26+
1227
public class FileOps {
1328

1429
private File f;
@@ -18,6 +33,16 @@ public class FileOps {
1833
final int tokenSize = maxSize + 4;
1934

2035

36+
/**
37+
* Class constructor
38+
* @param fNam Filename as String
39+
* @param l List instance
40+
* @param t Threshold of a line
41+
* @param low Word lower boundary
42+
* @param up Word upper boundary
43+
* @throws FileNotFoundException
44+
*/
45+
2146
public FileOps(String fNam,List l, int t,int low, int up) throws FileNotFoundException
2247
{
2348

@@ -32,11 +57,29 @@ public FileOps(String fNam,List l, int t,int low, int up) throws FileNotFoundExc
3257

3358
}
3459

60+
/**
61+
*
62+
* A getter function
63+
*/
3564
public File getFile()
3665
{
3766
return this.f;
3867
}
3968

69+
/**
70+
*
71+
* A function to read a file line - wise and store its context if between {@code (minSize, maxSize)} in a double linked list, else ignores the given context.
72+
*
73+
* @throws IOException
74+
* @throws FileNotFoundException
75+
*
76+
* @implNote Uses the function {@link Files.FileOps.formatInput()} formatInput to decide whether input will be ignored or not.
77+
* @see BufferdReader
78+
* @see InputStreamReader
79+
* @see FileInputStream
80+
*
81+
*/
82+
4083
public void retrieveContext() throws IOException,FileNotFoundException
4184
{
4285
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
@@ -80,6 +123,20 @@ public void retrieveContext() throws IOException,FileNotFoundException
80123
*
81124
* */
82125

126+
/**
127+
*
128+
* A function to store the context of a double linked list, in a .txt file.
129+
*
130+
* @throws IOException
131+
* @throws FileNotFoundException
132+
*
133+
* @implNote Stores the context in the same input file by overwriting its content.
134+
* @see BufferdWritter
135+
* @see OutputStreamWriter
136+
* @see FileOutputStream
137+
*
138+
*/
139+
83140
public void storeContext() throws IOException,FileNotFoundException
84141
{
85142

@@ -113,6 +170,33 @@ public void storeContext() throws IOException,FileNotFoundException
113170
* -Trims given string - input in case that this exceeds threshold characters.
114171
*
115172
* */
173+
/**
174+
* Constructs a LineItem if the given key {@literal String} matches the requirements. If not key is either trimmed or null is returned (empty key given)
175+
* <br><strong>Key Requirements: </strong>
176+
*
177+
* <blockquote>If a key is greater than {@code threshold} the key gets trimmed to fit the [0, threshold] range.</blockquote>
178+
* <blockquote>If an empty key is given ({@code lContext.isEmpty() == true}) null is returned.</blockquote>
179+
*
180+
*
181+
*
182+
*
183+
*
184+
*
185+
*
186+
*
187+
*
188+
*
189+
*
190+
*
191+
* @param lContext A String key.
192+
* @param lNum The line in which this key is found inside the text.
193+
* @return A LineItem if the key is valid or null.
194+
* @see util.Item
195+
* @see textEditorLineItem
196+
* @see util.List
197+
*
198+
*
199+
*/
116200

117201
public static Item formatInput(String lContext, int lNum)
118202
{
@@ -146,6 +230,24 @@ public static Item formatInput(String lContext, int lNum)
146230
*
147231
* */
148232

233+
234+
/**
235+
*Itterates through the double linked list of Line objects ({@linkplain textEditor.Line}) and stores each valid word in an ArrayList of Word objects ({@linkplain util.Word}).
236+
* <blockquote> The splitting procedure uses a regex in order to be performed. </blockquote>
237+
* <blockquote> <strong> Valid Words (Keys): </strong></blockquote>
238+
* <blockquote>
239+
* <ul>
240+
* <li> Any String that is delimited via the "\W+" regular expression is possibly valid.</li>
241+
* <li> Any possibly valid string that has a {@code key.length()} &#8707; {@code [minSize, maxSize]} is valid. </li>
242+
* </ul>
243+
* </blockquote>
244+
* @implNote <ul>
245+
* <li>Validity of a possibly valid Word - Key is checked via the {@code isValidWord()} function. </li>
246+
* <li>The final ArrayList gets sorted after it is filled.</li>
247+
* </ul>
248+
*
249+
* @return An {@literal ArrayList} of Word (- s) objects retrieved from the list in an ascending lexicographical order.
250+
*/
149251
public ArrayList<Word> fillWordMap()
150252
{
151253
int index = 0;
@@ -186,11 +288,15 @@ public ArrayList<Word> fillWordMap()
186288

187289
}
188290

291+
292+
189293
//sort the array list based on the "word"-key.
190294
Collections.sort(words);
191295

192296
///return the sorted arraylist.
193297

298+
299+
194300
return words;
195301

196302

@@ -205,7 +311,12 @@ public ArrayList<Word> fillWordMap()
205311
* Stores a created line item in a double linked list.
206312
*
207313
* */
208-
314+
/**
315+
* Gets a List instance and a LineItem and appends the given Item at the end of the list.
316+
* @param l A list reference.
317+
* @param line A line item.
318+
* @return Nothing
319+
*/
209320
public void storeLine(List l, LineItem line)
210321
{
211322

@@ -217,6 +328,14 @@ public void storeLine(List l, LineItem line)
217328
* Decides for the validity of the given string based on thresholds. (see FileOps class constructor).
218329
*
219330
* */
331+
/**
332+
* Gets a String representing an actual key and decides whether is valid or not by checking its length which should &#8707; [minSize, maxSize].
333+
* @param w
334+
* @return True if given is valid, or False
335+
*
336+
*
337+
* @see Files.FileOps.fillWordMap
338+
*/
220339

221340
private boolean isValidWord(String w)
222341
{

src/Files/FilePageAccess.java

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,35 @@
88

99
import util.Word;
1010

11+
/**
12+
*
13+
*
14+
* @author dasApfel - Konstantinos Pantelis
15+
* {@summary }
16+
* A class to encapsulate methods for performing r/w operations on RandomAccessFiles representing a dictionary (see {@linkplain RandomAccessFile} for more).
17+
*
18+
*/
19+
1120
public class FilePageAccess
1221
{
1322

23+
24+
1425
private int pageSize;
1526
private int tokenSize;
1627
private int dataPages;
1728
private int keySize;
1829
RandomAccessFile dF;
1930
ArrayList<Word> words;
2031

32+
33+
/**
34+
*
35+
* @param ps Size of a datapage in bytes.
36+
* @param k Tuple of {@literal <String, Integer>} maximum size in bytes.
37+
* @param f The name of a {@linkplain RandomAccessFile} to write the data in bytes, passed as a {@literal String}.
38+
* @throws FileNotFoundException
39+
*/
2140
public FilePageAccess(int ps, int k,String f) throws FileNotFoundException
2241
{
2342
pageSize = ps;
@@ -44,6 +63,17 @@ public int getPageSize()
4463
* Filling gets to happen in quantums of pageSize which can easily be altered.
4564
* */
4665

66+
/**
67+
*
68+
* Gets an {@linkplain ArrayList} of {@code Word.class} (tuples of {@literal <String, Integer> }) and fills a RandomAccessFile page - wise.
69+
* Uses a {@literal ByteBuffer} {@linkplain java.nio.ByteBuffer} in which {@code pageSize} bytes are allocated.
70+
*
71+
* @param words Tuples of {@literal <String, Integer>} as an {@linkplain ArrayList}.
72+
* @throws IOException
73+
* @throws FileNotFoundException
74+
* @return Nothing, only informs the {@code int datapages} which depicts the number of pages present.
75+
*
76+
*/
4777

4878
public void fillDictionary(ArrayList<Word> words) throws IOException,FileNotFoundException
4979
{
@@ -105,9 +135,10 @@ public void fillDictionary(ArrayList<Word> words) throws IOException,FileNotFoun
105135

106136
}
107137

108-
/*
109-
* Read a dictionary (RandomAccessFile) page - wise,at once.
110-
* Return the information retrieved in an arraylist.
138+
/**
139+
*
140+
* Reads a dictionary ({@literal RandomAccessFile}) page - wise,at once by utilising {@code readPage(int pageNum)} method.
141+
* @return The information retrieved in an {@linkplain ArrayList}.
111142
*
112143
*
113144
* */
@@ -134,6 +165,13 @@ public ArrayList<Word> readDictionary() throws NullPointerException, IOException
134165

135166
}
136167

168+
/**
169+
* Reads a page of the dictionary - {@literal RandomAccessFile} by utilizing a ByteBuffer (see {@linkplain java.nio.ByteBuffer})
170+
* @param pageNum Specifies the page to be accessed/read.
171+
* @return The page specified as an ArrayList (see {@linkplain java.util.ArrayList} for more).
172+
* @throws IOException
173+
* @throws NullPointerException
174+
*/
137175

138176
public ArrayList<Word> readPage(int pageNum) throws IOException,NullPointerException
139177
{
@@ -199,9 +237,17 @@ public ArrayList<Word> readPage(int pageNum) throws IOException,NullPointerExcep
199237
}
200238

201239
/*
202-
* Fill the missing parts of a string -> byte conversion with spaces (ASCII 32).
240+
* Fills the missing parts of a string -> byte conversion with spaces (ASCII 32).
203241
*
204242
* */
243+
244+
/**
245+
* Space - padding of a byte array representing a {@literal String} key.
246+
* @param s A byte array containing the byte representation of a {@literal String} key.
247+
* @return A byte array containing the byte representation of a {@literal String} key, filled up with spaces (ASCII 32) if {@code key.length < tokenSize }
248+
*
249+
*/
250+
205251
private byte[] paddBytes(byte s[])
206252
{
207253

@@ -227,12 +273,21 @@ private byte[] paddBytes(byte s[])
227273
*
228274
* */
229275

276+
/**
277+
* Closes open File.
278+
* @throws IOException
279+
*/
230280
public void close() throws IOException
231281
{
232282
dF.close();
233283

234284
}
235285

286+
/**
287+
* prints a File content after retrieved.
288+
* @throws NullPointerException
289+
* @throws IOException
290+
*/
236291
public void printFile( ) throws NullPointerException, IOException
237292
{
238293

0 commit comments

Comments
 (0)