@@ -84,20 +84,6 @@ public Inode lookup(String filename) throws FileSystemException { // TODO not ju
84
84
throw new FileSystemException (2 );
85
85
}
86
86
87
- // TODO check if needed
88
- public int datablock_pointer () {
89
- return vol .bb .getInt (offset + 40 ) * 1024 ;
90
- }
91
-
92
- // TODO check if needed
93
- public String filename_color () {
94
- String color_string = new String ();
95
- if (is_directory ()) {
96
- color_string += Main .BOLD_FONT + Main .BLUE_COL ;
97
- }
98
- return color_string ;
99
- }
100
-
101
87
/**
102
88
* Gets the owner user id.
103
89
*
@@ -206,29 +192,51 @@ public int[] stat() {
206
192
return stat ;
207
193
}
208
194
195
+ /**
196
+ * Creates and returns a DirEntryIterable.
197
+ */
209
198
public Iterable <Integer > iter_direntries () {
210
199
return new DirEntryIterable ();
211
200
}
212
201
202
+ /**
203
+ * Iterable for directory entries.
204
+ */
213
205
public class DirEntryIterable implements Iterable <Integer > {
214
206
public Iterator <Integer > iterator () {
215
207
return new DirEntryIterator ();
216
208
}
217
209
}
218
210
211
+ /**
212
+ * Iterator for directory entries.
213
+ */
219
214
public class DirEntryIterator implements Iterator <Integer > {
220
215
private int direntry_offset ;
221
216
217
+ /**
218
+ * Creates the directory entry iterator with the pointer at the first valid directory entry.
219
+ */
222
220
public DirEntryIterator () {
223
221
direntry_offset = 0 ;
224
222
225
223
valid_direntry ();
226
224
}
227
225
226
+ /**
227
+ * Checks if there's a next directory entry.
228
+ *
229
+ * @return If there's a next directory entry
230
+ */
228
231
public boolean hasNext () {
229
232
return direntry_offset < file_size ();
230
233
}
231
234
235
+ /**
236
+ * Gets the next directory entry position.
237
+ *
238
+ * @return Position of the next directory
239
+ */
232
240
public Integer next () {
233
241
if (!hasNext ()) {
234
242
throw new NoSuchElementException ("There are no more directory elements." );
@@ -242,6 +250,9 @@ public Integer next() {
242
250
}
243
251
}
244
252
253
+ /**
254
+ * Moves to the next valid directory entry.
255
+ */
245
256
private void valid_direntry () {
246
257
while (hasNext ()) {
247
258
int datablock_pt = get_datablock_pt (direntry_offset / Volume .BLOCK_LEN );
@@ -252,6 +263,9 @@ private void valid_direntry() {
252
263
}
253
264
}
254
265
266
+ /**
267
+ * Gets the next directory entry.
268
+ */
255
269
private void next_direntry () {
256
270
int datablock_pt = get_datablock_pt (direntry_offset / Volume .BLOCK_LEN );
257
271
direntry_offset += vol .bb .getShort (datablock_pt + direntry_offset % Volume .BLOCK_LEN + 4 );
0 commit comments