-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save the OS name in the backup (#152)
- Defines OS enum - Implements OS name parsing logic - Adds OS name to manifests - Shows OS name during restore Resolves #151 {minor} Signed-off-by: Esta Nagy <[email protected]>
- Loading branch information
Showing
8 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...arj-core/src/main/java/com/github/nagyesta/filebarj/core/model/enums/OperatingSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.nagyesta.filebarj.core.model.enums; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Represents the current OS. | ||
*/ | ||
public enum OperatingSystem { | ||
/** | ||
* Windows. | ||
*/ | ||
WINDOWS("win"), | ||
/** | ||
* Mac OS. | ||
*/ | ||
MAC("mac"), | ||
/** | ||
* Linux. | ||
*/ | ||
LINUX("linux"), | ||
/** | ||
* Catch-all for any OS not matching the above. | ||
*/ | ||
UNKNOWN(null); | ||
|
||
private final String nameToken; | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param nameToken the OS name token we need to search for in the OS name. | ||
*/ | ||
OperatingSystem(final String nameToken) { | ||
this.nameToken = nameToken; | ||
} | ||
|
||
/** | ||
* Parses the OS name. | ||
* | ||
* @param name the OS name | ||
* @return the matching constant or UNKNOWN | ||
*/ | ||
@NotNull | ||
public static OperatingSystem forOsName(@Nullable final String name) { | ||
final var osName = Optional.ofNullable(name) | ||
.map(String::toLowerCase) | ||
.orElse("unknown"); | ||
return Arrays.stream(values()) | ||
.filter(os -> os.nameToken != null && osName.contains(os.nameToken)) | ||
.findFirst() | ||
.orElse(UNKNOWN); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters