Made Directory a CapabilitiesProvider. WritableDirectory now extends the Directory interface.

This commit is contained in:
a2geek committed 2026-10-05 19:16:58 -05:00
1 parent 571bd3017d
commit 77e502bdcd
5 files changed
+62 -28

No files matched your search

@@ -19,6 +19,7 @@
*/
package org.applecommander.archive.shrinkit;
import org.applecommander.capability.Capability;
import org.applecommander.filestore.Directory;
import org.applecommander.filestore.FileEntry;
@@ -34,6 +35,11 @@ public class ShrinkitDirectory implements Directory {
this.files = files;
}
@Override
public boolean can(Capability capability) {
return false;
}
@Override
public Optional<Directory> getParent() {
return Optional.empty();
@@ -19,6 +19,7 @@
*/
package org.applecommander.archive.zip;
import org.applecommander.capability.Capability;
import org.applecommander.filestore.Directory;
import org.applecommander.filestore.FileEntry;
import org.applecommander.filestore.FileStore;
@@ -39,6 +40,11 @@ public class ZipDirectory implements Directory {
this.entries = entries;
}
@Override
public boolean can(Capability capability) {
return false;
}
@Override
public Optional<Directory> getParent() {
return Optional.empty();
@@ -19,35 +19,30 @@
*/
package org.applecommander.filestore;
import org.applecommander.capability.CapabilityProvider;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* A Directory represents a directory in a FileStore. Note that even
* FileStores that don't naturally support a directory do contain a root directory,
* so there will be a directory associated to each FileStore.
*/
public interface Directory {
/**
* Get the parent directory. If this is the root directory, it returns empty.
*/
/// A `Directory` represents a directory in a `FileStore`. Note that even
/// file stores that don't naturally support a directory do contain a root directory,
/// so there will be a directory associated to each `FileStore`.
public interface Directory extends CapabilityProvider {
/// Get the parent directory. If this is the root directory, it returns empty.
Optional<Directory> getParent();
/**
* Returns the FileStore that this Directory belongs to.
*/
/// Returns the FileStore that this Directory belongs to.
FileStore getFileStore();
/**
* Returns the name of this directory.
*/
/// Returns the name of this directory.
String getName();
/**
* Return all entries that are stored in this directory.
*/
/// Return all entries that are stored in this directory.
List<FileEntry> getFiles();
/**
* Filter out the <code>DirectoryEntry</code> entries in this directory.
*/
/// Filter out the `DirectoryEntry` entries in this directory.
default List<Directory> getDirectories() {
return getFiles().stream()
.map(fileEntry -> fileEntry.get(Directory.class))
@@ -55,9 +50,8 @@ public interface Directory {
.map(Optional::get)
.collect(Collectors.toList());
}
/**
* Locate a given file of the given name recursively on the disk.
*/
/// Locate a given file of the given name recursively on the disk.
default Optional<FileEntry> findFile(String name) {
for (FileEntry fileEntry : getFiles()) {
if (name.equalsIgnoreCase(fileEntry.getName())) {
@@ -19,8 +19,28 @@
*/
package org.applecommander.filestore;
/// A WritableDirectory is a Directory that allows file creation.
public interface WritableDirectory {
/// Create a file. By definition, any file created is a WritableFileEntry.
WritableFileEntry createFile();
import org.applecommander.capability.Capability;
/// A WritableDirectory is a Directory that allows general directory modification.
/// Since not all directories can perform all tasks, check the capability first,
/// otherwise an exception will be generated.
public interface WritableDirectory extends Directory {
/// Create a file. By definition, any file created is a `WritableFileEntry`.
/// @see Capability#CREATE_FILES
default WritableFileEntry createFile(String fileName) {
throw new UnsupportedOperationException("unable to create files");
}
/// Create a directory. By definition, any directory create is a `WritableDirectory`.
/// @see Capability#CREATE_DIRECTORIES
default WritableDirectory createDirectory(String directoryName) {
throw new UnsupportedOperationException("unable to create directories");
}
/// Delete a file.
/// @see Capability#DELETE_FILES
default void deleteFile(FileEntry fileEntry) {
throw new UnsupportedOperationException("unable to delete files");
}
}
@@ -19,6 +19,7 @@
*/
package org.applecommander.os.gamedos;
import org.applecommander.capability.Capability;
import org.applecommander.device.TrackSectorDevice;
import org.applecommander.filestore.Directory;
import org.applecommander.filestore.FileEntry;
@@ -28,8 +29,10 @@ import org.applecommander.util.DataBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
public class GamedosDirectory implements Directory, GamedosConstants {
private static final Set<Capability> CAPABILITIES = Set.of(Capability.WRITE_FILES, Capability.CREATE_FILES);
private final GamedosFileStore fileStore;
private final TrackSectorDevice device;
@@ -38,6 +41,11 @@ public class GamedosDirectory implements Directory, GamedosConstants {
this.device = fileStore.get(TrackSectorDevice.class).orElseThrow();
}
@Override
public boolean can(Capability capability) {
return CAPABILITIES.contains(capability);
}
@Override
public Optional<Directory> getParent() {
return Optional.empty();