Skip to content

Commit

Permalink
Turned "Cloud#type" into property
Browse files Browse the repository at this point in the history
  • Loading branch information
JaniruTEC committed Oct 31, 2023
1 parent 0442f72 commit 163deac
Show file tree
Hide file tree
Showing 26 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DropboxCloudContentRepositoryFactory(Context context) {

@Override
public boolean supports(Cloud cloud) {
return cloud.type() == DROPBOX;
return cloud.getType() == DROPBOX;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public OnedriveCloudContentRepositoryFactory(Context context) {

@Override
public boolean supports(Cloud cloud) {
return cloud.type() == ONEDRIVE;
return cloud.getType() == ONEDRIVE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public PCloudContentRepositoryFactory(Context context) {

@Override
public boolean supports(Cloud cloud) {
return cloud.type() == PCLOUD;
return cloud.getType() == PCLOUD;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public GoogleDriveCloudContentRepositoryFactory(Context context, GoogleDriveIdCa

@Override
public boolean supports(Cloud cloud) {
return cloud.type() == CloudType.GOOGLE_DRIVE;
return cloud.getType() == CloudType.GOOGLE_DRIVE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Long id() {

@NotNull
@Override
public CloudType type() {
public CloudType getType() {
return CloudType.CRYPTO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CryptoCloudContentRepositoryFactory(Lazy<CloudContentRepository> cloudCon

@Override
public boolean supports(Cloud cloud) {
return cloud.type() == CRYPTO;
return cloud.getType() == CRYPTO;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public LocalStorageContentRepositoryFactory(Context context, MimeTypes mimeTypes

@Override
public boolean supports(Cloud cloud) {
return cloud.type() == LOCAL;
return cloud.getType() == LOCAL;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public S3CloudContentRepositoryFactory(Context context, SharedPreferencesHandler

@Override
public boolean supports(Cloud cloud) {
return cloud.type() == S3;
return cloud.getType() == S3;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class WebDavCloudContentRepositoryFactory implements CloudContentReposito

@Override
public boolean supports(Cloud cloud) {
return cloud.type() == WEBDAV;
return cloud.getType() == WEBDAV;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public Cloud fromEntity(CloudEntity entity) {
public CloudEntity toEntity(Cloud domainObject) {
CloudEntity result = new CloudEntity();
result.setId(domainObject.id());
result.setType(domainObject.type().name());
switch (domainObject.type()) {
result.setType(domainObject.getType().name());
switch (domainObject.getType()) {
case DROPBOX:
result.setAccessToken(((DropboxCloud) domainObject).accessToken());
result.setUsername(((DropboxCloud) domainObject).username());
Expand Down Expand Up @@ -126,7 +126,7 @@ public CloudEntity toEntity(Cloud domainObject) {
result.setWebdavCertificate(((WebDavCloud) domainObject).certificate());
break;
default:
throw new IllegalStateException("Unhandled enum constant " + domainObject.type());
throw new IllegalStateException("Unhandled enum constant " + domainObject.getType());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public List<Cloud> clouds(CloudType cloudType) throws BackendException {
List<Cloud> allClouds = mapper.fromEntities(database.loadAll(CloudEntity.class));

for (Cloud cloud : allClouds) {
if (cloud.type().equals(cloudType)) {
if (cloud.getType().equals(cloudType)) {
cloudsFromType.add(cloud);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ internal class MasterkeyCryptoCloudProviderTest {
fun testUnlockVault() {
val cloudType: CloudType = mock()

whenever(cloud.type()).thenReturn(cloudType)
whenever(cloud.type).thenReturn(cloudType)
whenever(vault.cloud).thenReturn(cloud)
whenever(vault.cloudType).thenReturn(cloudType)
whenever(vault.format).thenReturn(8)
Expand All @@ -183,7 +183,7 @@ internal class MasterkeyCryptoCloudProviderTest {
fun testUnlockLegacyVault() {
val cloudType: CloudType = mock()

whenever(cloud.type()).thenReturn(cloudType)
whenever(cloud.type).thenReturn(cloudType)
whenever(vault.cloud).thenReturn(cloud)
whenever(vault.cloudType).thenReturn(cloudType)
whenever(vault.format).thenReturn(7)
Expand Down Expand Up @@ -217,7 +217,7 @@ internal class MasterkeyCryptoCloudProviderTest {
fun tesChangePassword(legacy: Boolean) {
val cloudType: CloudType = mock()

whenever(cloud.type()).thenReturn(cloudType)
whenever(cloud.type).thenReturn(cloudType)
whenever(vault.cloud).thenReturn(cloud)
whenever(vault.cloudType).thenReturn(cloudType)
whenever(vault.format).thenReturn(7)
Expand Down Expand Up @@ -334,7 +334,7 @@ internal class MasterkeyCryptoCloudProviderTest {
private fun testVaultPasswordVault(masterkeyContent: String, unverifiedVaultConfig: Optional<UnverifiedVaultConfig>, password: String): Boolean {
val cloudType: CloudType = mock()

whenever(cloud.type()).thenReturn(cloudType)
whenever(cloud.type).thenReturn(cloudType)
whenever(vault.cloud).thenReturn(cloud)
whenever(vault.cloudType).thenReturn(cloudType)
whenever(vault.format).thenReturn(7)
Expand Down
2 changes: 1 addition & 1 deletion domain/src/main/java/org/cryptomator/domain/Cloud.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.Serializable
interface Cloud : Serializable {

fun id(): Long?
fun type(): CloudType
val type: CloudType
fun configurationMatches(cloud: Cloud?): Boolean
fun persistent(): Boolean
fun requiresNetwork(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String username() {

@NotNull
@Override
public CloudType type() {
public CloudType getType() {
return CloudType.DROPBOX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Long id() {

@NotNull
@Override
public CloudType type() {
public CloudType getType() {
return CloudType.GOOGLE_DRIVE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String rootUri() {

@NotNull
@Override
public CloudType type() {
public CloudType getType() {
return CloudType.LOCAL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String username() {

@NotNull
@Override
public CloudType type() {
public CloudType getType() {
return CloudType.ONEDRIVE;
}

Expand Down
2 changes: 1 addition & 1 deletion domain/src/main/java/org/cryptomator/domain/PCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String username() {

@NotNull
@Override
public CloudType type() {
public CloudType getType() {
return CloudType.PCLOUD;
}

Expand Down
2 changes: 1 addition & 1 deletion domain/src/main/java/org/cryptomator/domain/S3Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public String displayName() {

@NotNull
@Override
public CloudType type() {
public CloudType getType() {
return CloudType.S3;
}

Expand Down
6 changes: 3 additions & 3 deletions domain/src/main/java/org/cryptomator/domain/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Builder withCloud(Cloud cloud) {
this.cloud = cloud;

if (cloud != null) {
this.cloudType = cloud.type();
this.cloudType = cloud.getType();
}

return this;
Expand All @@ -168,7 +168,7 @@ public Builder withCloud(Cloud cloud) {
public Builder withCloudType(CloudType cloudType) {
this.cloudType = cloudType;

if (cloud != null && cloud.type() != cloudType) {
if (cloud != null && cloud.getType() != cloudType) {
throw new IllegalStateException("Cloud type must match cloud");
}

Expand All @@ -179,7 +179,7 @@ public Builder withNamePathAndCloudFrom(CloudFolder vaultFolder) {
this.name = vaultFolder.getName();
this.path = vaultFolder.getPath();
this.cloud = vaultFolder.getCloud();
this.cloudType = cloud.type();
this.cloudType = cloud.getType();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private boolean configurationMatches(WebDavCloud cloud) {

@NotNull
@Override
public CloudType type() {
public CloudType getType() {
return CloudType.WEBDAV;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void execute() throws BackendException {
}

private boolean cloudExists(Cloud cloud) throws BackendException {
for (Cloud storedCloud : cloudRepository.clouds(cloud.type())) {
for (Cloud storedCloud : cloudRepository.clouds(cloud.getType())) {
if (cloud.id() != null && cloud.id().equals(storedCloud.id())) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ private Cloud cloudWithUsernameAndAccessTokenRemoved(Cloud cloud) {
.withAccessToken(null) //
.build();
}
throw new IllegalStateException("Logout not supported for cloud with type " + cloud.type());
throw new IllegalStateException("Logout not supported for cloud with type " + cloud.getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CloudFolderModel(cloudFolder: CloudFolder) : CloudNodeModel<CloudFolder>(c
get() = true

fun vault(): VaultModel? {
return if (toCloudNode().cloud?.type() == CloudType.CRYPTO) {
return if (toCloudNode().cloud?.type == CloudType.CRYPTO) {
VaultModel((toCloudNode().cloud as CryptoCloud).vault)
} else {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CloudModelMapper @Inject constructor() : ModelMapper<CloudModel, Cloud>()
}

override fun toModel(domainObject: Cloud): CloudModel {
return when (domainObject.type().let { CloudTypeModel.valueOf(it) }) {
return when (domainObject.type.let { CloudTypeModel.valueOf(it) }) {
CloudTypeModel.DROPBOX -> DropboxCloudModel(domainObject)
CloudTypeModel.GOOGLE_DRIVE -> GoogleDriveCloudModel(domainObject)
CloudTypeModel.LOCAL -> LocalStorageModel(domainObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ class AuthenticateCloudPresenter @Inject constructor( //
}

private fun updateUsernameOf(cloud: Cloud, username: String): Cloud {
return when (cloud.type()) {
return when (cloud.type) {
CloudType.DROPBOX -> DropboxCloud.aCopyOf(cloud as DropboxCloud).withUsername(username).build()
CloudType.ONEDRIVE -> OnedriveCloud.aCopyOf(cloud as OnedriveCloud).withUsername(username).build()
else -> throw IllegalStateException("Cloud " + cloud.type() + " is not supported")
else -> throw IllegalStateException("Cloud " + cloud.type + " is not supported")
}
}

Expand Down Expand Up @@ -336,7 +336,7 @@ class AuthenticateCloudPresenter @Inject constructor( //

fun prepareForSavingPCloud(cloud: PCloud) {
getCloudsUseCase //
.withCloudType(cloud.type()) //
.withCloudType(cloud.type) //
.run(object : DefaultResultHandler<List<Cloud>>() {
override fun onSuccess(clouds: List<Cloud>) {
clouds.firstOrNull {
Expand Down

0 comments on commit 163deac

Please sign in to comment.