Allowing more visibility into what the OverrideFileEntryReader is doing

to assist in future debugging. Enable with `-vvvvvv` (6 `v`'s).
This commit is contained in:
Rob Greene 2022-06-21 20:06:32 -05:00
parent 6468f3af46
commit e7c10faf3b
1 changed files with 44 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.logging.Logger;
/**
* Allow programmatic control of what is in the results of the file entry.
@ -31,6 +32,8 @@ import java.util.Optional;
* It can also be used to layer in results and overrides.
*/
public class OverrideFileEntryReader implements FileEntryReader {
private static Logger LOG = Logger.getLogger(OverrideFileEntryReader.class.getName());
private Optional<FileEntryReader> parent = Optional.empty();
private Optional<String> filename = Optional.empty();
private Optional<String> prodosFiletype = Optional.empty();
@ -109,97 +112,138 @@ public class OverrideFileEntryReader implements FileEntryReader {
public Builder filename(String filename) {
Objects.requireNonNull(filename);
LOG.finest(() -> String.format("Setting filename to '%s'", filename));
fileEntryReader.filename = Optional.of(filename);
return this;
}
public Builder filename(Optional<String> filename) {
Objects.requireNonNull(filename);
filename.ifPresent(name -> {
LOG.finest(() -> String.format("Setting filename to '%s'", name));
});
fileEntryReader.filename = filename;
return this;
}
public Builder prodosFiletype(String filetype) {
Objects.requireNonNull(filetype);
LOG.finest(() -> String.format("Setting file type to '%s'", filetype));
fileEntryReader.prodosFiletype = Optional.of(filetype);
return this;
}
public Builder prodosFiletype(Optional<String> filetype) {
Objects.requireNonNull(filetype);
filetype.ifPresent(type -> {
LOG.finest(() -> String.format("Setting file type to '%s'", type));
});
fileEntryReader.prodosFiletype = filetype;
return this;
}
public Builder locked(boolean locked) {
LOG.finest(() -> String.format("Setting locked to '%b'", locked));
fileEntryReader.locked = Optional.of(locked);
return this;
}
public Builder locked(Optional<Boolean> locked) {
locked.ifPresent(flag -> {
LOG.finest(() -> String.format("Setting locked to '%b'", flag));
});
Objects.requireNonNull(locked);
fileEntryReader.locked = locked;
return this;
}
public Builder fileData(byte[] fileData) {
Objects.requireNonNull(fileData);
LOG.finest(() -> String.format("Setting data fork to %d bytes.", fileData.length));
fileEntryReader.fileData = Optional.of(fileData);
return this;
}
public Builder fileData(Optional<byte[]> fileData) {
Objects.requireNonNull(fileData);
fileData.ifPresent(data -> {
LOG.finest(() -> String.format("Setting data fork to %d bytes.", data.length));
});
fileEntryReader.fileData = fileData;
return this;
}
public Builder resourceData(byte[] resourceData) {
Objects.requireNonNull(resourceData);
LOG.finest(() -> String.format("Setting data fork to %d bytes.", resourceData.length));
fileEntryReader.resourceData = Optional.of(resourceData);
return this;
}
public Builder resourceData(Optional<byte[]> resourceData) {
Objects.requireNonNull(resourceData);
resourceData.ifPresent(data -> {
LOG.finest(() -> String.format("Setting resource fork to %d bytes.", data.length));
});
LOG.finest(() -> String.format("Setting file data to %d bytes.", resourceData.orElse(new byte[0]).length));
fileEntryReader.resourceData = resourceData;
return this;
}
public Builder binaryAddress(int binaryAddress) {
fileEntryReader.binaryAddress = Optional.of(binaryAddress);
LOG.finest(() -> String.format("Setting address to $%04xs.", binaryAddress));
return this;
}
public Builder binaryAddress(Optional<Integer> binaryAddress) {
Objects.requireNonNull(binaryAddress);
binaryAddress.ifPresent(addr -> {
LOG.finest(() -> String.format("Setting address to $%04xs.", addr));
});
fileEntryReader.binaryAddress = binaryAddress;
return this;
}
public Builder binaryLength(int binaryLength) {
LOG.finest(() -> String.format("Setting binary length to %04x.", binaryLength));
fileEntryReader.binaryLength = Optional.of(binaryLength);
return this;
}
public Builder binaryLength(Optional<Integer> binaryLength) {
Objects.requireNonNull(binaryLength);
binaryLength.ifPresent(length -> {
LOG.finest(() -> String.format("Setting binary length to %04x.", length));
});
fileEntryReader.binaryLength = binaryLength;
return this;
}
public Builder auxiliaryType(int auxiliaryType) {
LOG.finest(() -> String.format("Setting aux type to $%04x.", auxiliaryType));
fileEntryReader.auxiliaryType = Optional.of(auxiliaryType);
return this;
}
public Builder auxiliaryType(Optional<Integer> auxiliaryType) {
Objects.requireNonNull(auxiliaryType);
auxiliaryType.ifPresent(type -> {
LOG.finest(() -> String.format("Setting aux type to $%04x.", type));
});
fileEntryReader.auxiliaryType = auxiliaryType;
return this;
}
public Builder creationDate(Date creationDate) {
Objects.requireNonNull(creationDate);
LOG.finest(() -> String.format("Setting creation date to %s.", creationDate));
fileEntryReader.creationDate = Optional.of(creationDate);
return this;
}
public Builder creationDate(Optional<Date> creationDate) {
Objects.requireNonNull(creationDate);
creationDate.ifPresent(date -> {
LOG.finest(() -> String.format("Setting creation date to %s.", date));
});
fileEntryReader.creationDate = creationDate;
return this;
}
public Builder lastModificationDate(Date lastModificationDate) {
Objects.requireNonNull(lastModificationDate);
LOG.finest(() -> String.format("Setting last modification date to %s.", lastModificationDate));
fileEntryReader.lastModificationDate = Optional.of(lastModificationDate);
return this;
}
public Builder lastModificationDate(Optional<Date> lastModificationDate) {
Objects.requireNonNull(lastModificationDate);
lastModificationDate.ifPresent(date -> {
LOG.finest(() -> String.format("Setting last modification date to %s.", date));
});
fileEntryReader.lastModificationDate = lastModificationDate;
return this;
}