Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,55 @@
*/
package com.owncloud.android.lib.resources.status;

import androidx.annotation.NonNull;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* Enum for Boolean Type in OCCapability parameters, with values:
* -1 - Unknown
* 0 - False
* 1 - True
* 0 - False
* 1 - True
*/
@AllArgsConstructor
public enum CapabilityBooleanType {
UNKNOWN (-1),
FALSE (0),
TRUE (1);
UNKNOWN(-1),
FALSE(0),
TRUE(1);

@Getter private int value;
@Getter
private int value;

public static CapabilityBooleanType fromValue(int value)
{
switch (value)
{
public static @NonNull
CapabilityBooleanType fromValue(int value) {
switch (value) {
case -1:
return UNKNOWN;
case 0:
return FALSE;
case 1:
return TRUE;
}
return null;
return UNKNOWN;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the key you could then just go for UNKNOWN.getValue() etc. instead of duplicating the int-values here :)

}

public static CapabilityBooleanType fromBooleanValue(boolean boolValue){
if (boolValue){
public static CapabilityBooleanType fromBooleanValue(boolean boolValue) {
if (boolValue) {
return TRUE;
} else {
return FALSE;
}
}

public boolean isUnknown(){
public boolean isUnknown() {
return getValue() == -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here UNKNOWN.getValue() or maybe UNKNOWN.value, same for the other checks

}

public boolean isFalse(){
public boolean isFalse() {
return getValue() == 0;
}

public boolean isTrue(){
public boolean isTrue() {
return getValue() == 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2020 Tobias Kaminsky
* Copyright (C) 2020 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

package com.owncloud.android.lib.resources.status;

import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class CapabilityBooleanTypeTest {

@Test
public void test() {
assertTrue(CapabilityBooleanType.fromBooleanValue(true).isTrue());
assertTrue(CapabilityBooleanType.fromBooleanValue(false).isFalse());

assertTrue(CapabilityBooleanType.fromValue(-2).isUnknown());
assertTrue(CapabilityBooleanType.fromValue(-1).isUnknown());
assertTrue(CapabilityBooleanType.fromValue(-0).isFalse());
assertTrue(CapabilityBooleanType.fromValue(1).isTrue());
assertTrue(CapabilityBooleanType.fromValue(2).isUnknown());

assertTrue(CapabilityBooleanType.valueOf("UNKNOWN").isUnknown());
assertTrue(CapabilityBooleanType.valueOf("FALSE").isFalse());
assertTrue(CapabilityBooleanType.valueOf("TRUE").isTrue());
}

@Test(expected = IllegalArgumentException.class)
public void testException() {
CapabilityBooleanType.valueOf("wrongValue");
}

}