Use generics
This commit is contained in:
parent
e489bd05d7
commit
0577001a25
@ -19,7 +19,7 @@
|
||||
package org.warp.filesponge;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -33,22 +33,22 @@ import org.warp.filesponge.value.FileURI;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class SecureFileAccessor implements FileAccessor {
|
||||
public class SecureFileAccessor<FURI extends FileURI, FC extends FileContent> implements FileAccessor<FURI, FC> {
|
||||
|
||||
private final FileAccessor fileAccessor;
|
||||
private final FileAccessor<FURI, FC> fileAccessor;
|
||||
|
||||
@Override
|
||||
public void delete(@NotNull FileURI fileURI) {
|
||||
public void delete(@NotNull FURI fileURI) {
|
||||
fileAccessor.delete(fileURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Optional<FileContent>> getContent(@NotNull FileURI fileURI, boolean offlineOnly) {
|
||||
public CompletionStage<Optional<FC>> getContent(@NotNull FURI fileURI, boolean offlineOnly) {
|
||||
return fileAccessor.getContent(fileURI, offlineOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FileStatus getStatus(@NotNull FileURI fileURI) {
|
||||
public @NotNull FileStatus getStatus(@NotNull FURI fileURI) {
|
||||
return fileAccessor.getStatus(fileURI);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.warp.filesponge.api;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.warp.filesponge.value.FileContent;
|
||||
import org.warp.filesponge.value.FileStatus;
|
||||
@ -28,14 +28,14 @@ import org.warp.filesponge.value.FileURI;
|
||||
/**
|
||||
* FileAccessor can be used to access files from the client side
|
||||
*/
|
||||
public interface FileAccessor {
|
||||
public interface FileAccessor<FURI extends FileURI, FC extends FileContent> {
|
||||
|
||||
/**
|
||||
* Request file deletion
|
||||
*
|
||||
* @param fileURI File URI
|
||||
*/
|
||||
void delete(@NotNull FileURI fileURI);
|
||||
void delete(@NotNull FURI fileURI);
|
||||
|
||||
/**
|
||||
* Get file content
|
||||
@ -44,7 +44,7 @@ public interface FileAccessor {
|
||||
* @param offlineOnly true to get the file from cache
|
||||
* @return content if found. If the request is offline the future will complete instantly
|
||||
*/
|
||||
CompletableFuture<Optional<FileContent>> getContent(@NotNull FileURI fileURI, boolean offlineOnly);
|
||||
CompletionStage<Optional<FC>> getContent(@NotNull FURI fileURI, boolean offlineOnly);
|
||||
|
||||
/**
|
||||
* Get file status
|
||||
@ -52,5 +52,5 @@ public interface FileAccessor {
|
||||
* @param fileURI File URI
|
||||
* @return status of this file
|
||||
*/
|
||||
@NotNull FileStatus getStatus(@NotNull FileURI fileURI);
|
||||
@NotNull FileStatus getStatus(@NotNull FURI fileURI);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import org.warp.filesponge.value.FileURI;
|
||||
/**
|
||||
* FileActor sends signals to a mirror
|
||||
*/
|
||||
public interface FileActor {
|
||||
public interface FileActor<FURI extends FileURI> {
|
||||
|
||||
/**
|
||||
* Send a "delete file" signal
|
||||
@ -33,7 +33,7 @@ public interface FileActor {
|
||||
* @param fileURI File URI
|
||||
* @return true if the signal can be sent
|
||||
*/
|
||||
boolean deleteFile(FileURI fileURI);
|
||||
boolean deleteFile(FURI fileURI);
|
||||
|
||||
/**
|
||||
* Send a "download file" signal
|
||||
@ -41,7 +41,7 @@ public interface FileActor {
|
||||
* @param fileURI File URI
|
||||
* @return true if the signal can be sent
|
||||
*/
|
||||
boolean downloadFile(FileURI fileURI);
|
||||
boolean downloadFile(FURI fileURI);
|
||||
|
||||
/**
|
||||
* Check if this actor can handle signals for this file
|
||||
@ -49,7 +49,7 @@ public interface FileActor {
|
||||
* @param fileURI File URI
|
||||
* @return true if the actor can send signals related to this file
|
||||
*/
|
||||
boolean canHandleFile(FileURI fileURI);
|
||||
boolean canHandleFile(FURI fileURI);
|
||||
|
||||
/**
|
||||
* Send a "download file" signal
|
||||
|
@ -27,7 +27,7 @@ import org.warp.filesponge.value.FileURI;
|
||||
/**
|
||||
* FileSource receives responses from a mirror
|
||||
*/
|
||||
public interface FileSource {
|
||||
public interface FileSource<FURI extends FileURI, FTYPE extends FileType> {
|
||||
|
||||
/**
|
||||
* Called when the mirror is online
|
||||
@ -42,14 +42,14 @@ public interface FileSource {
|
||||
/**
|
||||
* Called when the mirror notifies you that a new file exists
|
||||
*/
|
||||
boolean onNewFile(@NotNull FileURI fileURI, @NotNull FileType fileType);
|
||||
boolean onNewFile(@NotNull FURI fileURI, @NotNull FTYPE fileType);
|
||||
|
||||
/**
|
||||
* Called when the mirror notifies you details about a file.
|
||||
* <p>
|
||||
* {@link this#onNewFile(FileURI, FileType)} must have been already called
|
||||
*/
|
||||
void onFile(@NotNull FileURI fileURI, @NotNull FileSourceAvailability fileAvailability, long totalSize);
|
||||
void onFile(@NotNull FURI fileURI, @NotNull FileSourceAvailability fileAvailability, long totalSize);
|
||||
|
||||
/**
|
||||
* Called when the mirror notifies you the bytes of a part of a file.
|
||||
@ -57,5 +57,5 @@ public interface FileSource {
|
||||
* {@link this#onNewFile(FileURI, FileType)} and {@link this#onFile(FileURI, FileSourceAvailability, long)} must
|
||||
* have been already called
|
||||
*/
|
||||
void onFilePiece(@NotNull FileURI fileURI, long offset, long size, @NotNull ByteBuffer piece);
|
||||
void onFilePiece(@NotNull FURI fileURI, long offset, long size, @NotNull ByteBuffer piece);
|
||||
}
|
||||
|
@ -19,11 +19,13 @@
|
||||
package org.warp.filesponge.api;
|
||||
|
||||
import org.warp.filesponge.SecureFileAccessor;
|
||||
import org.warp.filesponge.value.FileContent;
|
||||
import org.warp.filesponge.value.FileURI;
|
||||
|
||||
/**
|
||||
* FileAccessor can be used to manage FileSponge and access files from the client side
|
||||
*/
|
||||
public interface FileSpongeClient extends FileAccessor {
|
||||
public interface FileSpongeClient<FURI extends FileURI, FC extends FileContent> extends FileAccessor<FURI, FC> {
|
||||
|
||||
void optimizeStorage();
|
||||
|
||||
@ -32,7 +34,7 @@ public interface FileSpongeClient extends FileAccessor {
|
||||
*
|
||||
* @return limited instance of itself
|
||||
*/
|
||||
default FileAccessor asFileAccessor() {
|
||||
return new SecureFileAccessor(this);
|
||||
default FileAccessor<FURI, FC> asFileAccessor() {
|
||||
return new SecureFileAccessor<>(this);
|
||||
}
|
||||
}
|
||||
|
32
src/main/lombok/org/warp/filesponge/api/FileStorage.java
Normal file
32
src/main/lombok/org/warp/filesponge/api/FileStorage.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* FileSponge
|
||||
* Copyright (C) 2020 Andrea Cavalli
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.warp.filesponge.api;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.warp.filesponge.value.FileContent;
|
||||
import org.warp.filesponge.value.FileType;
|
||||
import org.warp.filesponge.value.FileURI;
|
||||
import org.warp.filesponge.value.MirrorURI;
|
||||
|
||||
public interface FileStorage<FURI extends FileURI, FTYPE extends FileType, MURI extends MirrorURI, FC extends FileContent> {
|
||||
|
||||
void newFile(@NotNull FURI fileURI, @NotNull FTYPE fileType);
|
||||
|
||||
FC readFileData(@NotNull FURI fileURI);
|
||||
}
|
@ -19,26 +19,25 @@
|
||||
package org.warp.filesponge.extra.api;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalLong;
|
||||
import org.warp.filesponge.value.FileURI;
|
||||
|
||||
/**
|
||||
* Translate File URIs to "fileId" and back
|
||||
*/
|
||||
public interface FileURITranslator {
|
||||
public interface FileURITranslator<FURI extends FileURI, FID> {
|
||||
|
||||
Optional<FileURI> getURI(long fileId);
|
||||
Optional<FURI> getURI(FID fileId);
|
||||
|
||||
OptionalLong getFileId(FileURI fileURI);
|
||||
Optional<FID> getFileId(FURI fileURI);
|
||||
|
||||
/**
|
||||
* @throws AlreadyAssignedException Throw if the uri has another fileId assigned
|
||||
*/
|
||||
void setFileId(FileURI fileURI, long fileId) throws AlreadyAssignedException;
|
||||
void setFileId(FURI fileURI, FID fileId) throws AlreadyAssignedException;
|
||||
|
||||
Optional<FileURI> delete(long fileId);
|
||||
Optional<FURI> delete(FID fileId);
|
||||
|
||||
OptionalLong delete(FileURI fileURI);
|
||||
Optional<FID> delete(FURI fileURI);
|
||||
|
||||
void clear();
|
||||
}
|
||||
|
@ -23,17 +23,17 @@ import org.warp.filesponge.value.FileURI;
|
||||
/**
|
||||
* Create an unique "fileId" for each File URI
|
||||
*/
|
||||
public interface URIObfuscator {
|
||||
public interface URIObfuscator<FURI extends FileURI, FID> {
|
||||
|
||||
FileURI deobfuscateFileId(long fileId);
|
||||
FURI deobfuscateFileId(FID fileId);
|
||||
|
||||
void getFileId(FileURI fileURI);
|
||||
void getFileId(FURI fileURI);
|
||||
|
||||
void setURIValue(FileURI fileURI, long fileId);
|
||||
void setURIValue(FURI fileURI, FID fileId);
|
||||
|
||||
FileURI delete(long fileId);
|
||||
FURI delete(FID fileId);
|
||||
|
||||
long delete(FileURI fileURI);
|
||||
FID delete(FURI fileURI);
|
||||
|
||||
void clear();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user